The following guide describes how to install a LEMP stack on Centos 6.5 combining PHP 5.4 and MySQL 5.6
Step 1 – Install Required Repositories
The following steps install and configure the required repositories.
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
Disable the repositories to ensure correct depency management
sed -i s'/enabled=1/enabled=0/' /etc/yum.repos.d/epel.repo sed -i s'/enabled=1/enabled=0/' /etc/yum.repos.d/remi.repo sed -i s'/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo sed -i s'/enabled=1/enabled=0/' /etc/yum.repos.d/nginx.repo
Step 2 – Install Software packages
The following steps install the required MySQL 5.6, PHP 5.4 and Nginx.
yum -y --enablerepo=mysql56-community,remi install php-fpm yum -y --enablerepo=mysql56-community,remi install php-mysqlnd yum -y --enablerepo=mysql56-community,remi install mysql-server yum -y --enablerepo=nginx install nginx
Step 3 – Configure Software packages
Set the user and group for php-fpm
sed -i s'/user = apache/user = nginx/' /etc/php-fpm.d/www.conf sed -i s'/group = apache/group = nginx/' /etc/php-fpm.d/www.conf
Edit the nginx config file to set site defaults
vi /etc/nginx/conf.d/default.conf
server { listen 80; # listen port server_name localhost; # Server name (www.servermule.com) location / { root /usr/share/nginx/html; # Document root index index.php index.html index.htm; } location ~ \.php$ { root /usr/share/nginx/html; # Document root fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
Step 4 – Start up the servers
To Start up MySQL, Nginx and PHP-FPM
service mysqld start service php-fpm start service nginx start
To set MySQL, PHP-FPM and Nginx to restart in case of a server reboot
chkconfig mysqld on chkconfig php-fpm on chkconfig nginx on
Step 5 – Test that it’s all working together
Create a phpinfo page
echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/phpinfo.php
Navigate to the site in your browser and check that the php information is returned</>
http://ip address/phpinfo.php
Create a mysql access page
vi /usr/share/nginx/html/mysql.php
enter the following php code
<?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Unable to connect to the server: ' . mysql_error()); } echo "Success - PHP has Connected to MySQL...!"; ?>Navigate to the site in your browser and check that "Success - PHP has Connected to MySQL...!" is returned</>
http://ip address/mysql.php
Step 6 - Secure MySQL
Optionally to set the root password and secure the installation run the secure script as follows.
mysql_secure_installation