Install LAMP on CentOS 6 & 7

2018-02-17|Categories: Linux|

By yum

Installation

# CentOS 6
# If you want to run php as mod_php of httpd,
# then you do NOT need to install `php-fpm`.
yum install -y httpd mysql-server php php-mysql php-fpm

# CentOS 7
yum install -y httpd mariadb-server php php-mysql php-fpm

Configuration

# FastCGI (php-fpm) for httpd
cat >> /etc/httpd/conf/httpd.conf <<- EOF
    DirectoryIndex index.php
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/\$1
EOF    

Startup

# CentOS 6
for i in httpd mysqld php-fpm; do
    service ${i} start
    chkconfig --add ${i}
    chkconfig ${i} on
done

# CentOS 7
for i in httpd mysqld php-fpm; do
    systemctl start ${i}
    systemctl enable ${i}
done

By compiling

I have written a script to do the LAMP compilation job:

Leave A Comment