LEMP on Centos 6 Rumi, December 10, 2017 In this guide, we’ll walk you through installing all of these components (except for Linux, which is already installed as your OS when you create the server). Install the Extra Packages for Enterprise Linux Repository (or EPEL for short):sudo yum install epel-release Run a yum update to sync your packages with the new EPEL repository: sudo yum update Install MySQL: sudo yum install mysql-server Activate MySQL: sudo service mysqld start Configure your MySQL installation: sudo /usr/bin/mysql_secure_installation Make it so that MySQL will start automatically on server reboot: sudo chkconfig mysqld on Restart MySQL to save the changes: sudo service mysqld restart Install NGINX sudo yum install nginx Start the NGINX service: sudo service nginx start Make it so that NGINX will start automatically on server reboot: sudo chkconfig nginx on Verify that NGINX is installed by going to: http://your server’s IP address Install and configure PHP sudo yum install php php-fpm php-mysql Open php.ini: sudo vim /etc/php.ini Find the cgi.fix_pathinfo directive, and set it as follows:cgi.fix_pathinfo=0 Save and close the file Open the www.conf file for editing: sudo vim /etc/php-fpm.d/www.conf Find the listen directive (it should be the first), and verify that it is set to listen for PHP traffic using a Unix socket (instead of port 9000): listen = /var/run/php-fpm/php-fpm.sock Find the Set permissions for unix socket… section, uncomment the listen.owner and listen.group sections, and edit them so that the user and group are set to nginx instead of apache: listen.owner = nginx listen.group = nginx Find the Unix user/group of processes section, and change the user and group from apache to nginx:user = nginx group = nginx Save and close the file. Restart PHP: sudo systemctl restart php-fpm This creates the needed php-fpm.sock file Modify the permissions and ownership for the php-fpm.sock file as follows: sudo chmod 666 /run/php-fpm/php-fpm.sock sudo chown nginx:nginx /run/php-fpm/php-fpm.sock Restart PHP again: sudo service php-fpm restart Configure NGINX All of your LEMP stack components are now installed. You need only to make some changes to the default NGINX so that it properly serves PHP with FastCGI. You may want to make a copy of the default.conf file before editing it: sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.safety Open the default.conf file for editing: sudo vim /etc/nginx/conf.d/default.conf Find the server context, which will look something like this (comments removed): server { listen 80 default_server; server_name _; include /etc/nginx/default.d/*.conf; location / { root /usr/share/nginx/html; index index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } error_page 500 502 503 504 /50x.html; ocation = /50x.html { root /usr/share/nginx/html; } } Make the following edits (which are substantial, but don’t worry – there’s a template to show you how everything should work below).Remove default_server so that the listen statement looks like: listen 80; Change the server_name statement to use your server’s IP address or the domain you want to use: server_name your domain name or IP; Edit the index statement to include index.php:index index.php index.html index.htm; Add a try_files statement to the location / {} block:try_files $uri $uri/ /index.html; Add a new location ~ \.php$ {} block to tell NGINX how to properly use PHP with FastCGI: location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } Your new default server block should look like this, with comments removed (changes are highlighted in blue): server { listen 80; server_name your domain name or IP; include /etc/nginx/default.d/*.conf; location / { root /usr/share/nginx/html; index index.php index.html index.htm; try_files $uri $uri/ /index.html; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } Save and close the file, Restart PHP: sudo service php-fpm restart Restart NGINX: sudo service nginx restart Note: If NGINX fails to restart, check your edits. Make sure that all of your braces ({}) are closed and that each directive ends with a semi-colon (;). Verify that PHP is running, Create a php test file, info.php: sudo vim /usr/share/nginx/html/info.php Insert the following contents: <?php phpinfo(); ?> Go to: http://your server's IP address/info.php A page full of statistics with a PHP logo in the upper right-hand corner will be displayed. For permission on directories referring to the following URL: https://sg.godaddy.com/help/configure-nginx-server-blocks-centos-20131 https://www.digitalocean.com/community/questions/permission-problems-running-wordpress-on-nginx Ref: https://sg.godaddy.com/help/build-a-lemp-stack-linux-nginx-mysql-php-centos-6-19186 Administrations Collected Articles Configurations (Linux) CentOSCentOS6LEMP