Skip to content
Bots!
Bots!
  • About
    • Myself
    • আমার দোয়া
  • Bookmarks
    • Bookmarks
    • My OCI Bookmarks
    • Useful Proxmox Commands & Links
    • Learning Nano
    • Useful Sites
    • Useful Virtualbox Command
    • Useful MySQL Command
    • Useful Linux Command
    • BTT-CAS
  • Resources
    • Webinar on Cloud Adoption for Project Managers
  • Photos
  • Videos
  • Downloads
Bots!

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

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Myself…

Hi, I am Hasan T. Emdad Rumi, an IT Project Manager & Consultant, Virtualization & Cloud Savvyfrom Dhaka, Bangladesh. I have prior experience in managing numerous local and international projects in the area of Telco VAS & NMC, National Data Center & PKI Naitonal Root and CA Infrastructure. Also engaged with several Offshore Software Development Team.

Worked with Orascom Telecom-Banglalink, Network Elites as VAS partner, BTRC, BTT (Turkey) , Mango Teleservices Limited and Access to Informaiton (A2I-UNDP)

Currently working at Oracle Corporation as Principal Technology Solution and Cloud Architect.

You can reach me [h.t.emdad at gmail.com] and I will be delighted to exchange my views.

Tags

Apache Bind Cacti CentOS CentOS 6 CentOS 7 Debain Debian Debian 10 Debian 11 Debian 12 DKIM Docker endian icinga iptables Jitsi LAMP Letsencrypt Linux Munin MySQL Nagios Nextcloud NFS nginx pfsense php Postfix powerdns Proxmox RDP squid SSH SSL Ubuntu Ubuntu 16 Ubuntu 18 Ubuntu 20 Varnish virtualbox vpn Webmin XCP-NG zimbra

Topics

Recent Posts

  • Install Jitsi on Ubuntu 22.04 / 22.10 April 30, 2025
  • Key Lessons in life April 26, 2025
  • Create Proxmox Backup Server (PBS) on Debian 12 April 19, 2025
  • Add Physical Drive in Proxmox VM Guest April 19, 2025
  • Mount a drive permanently with fstab in Linux April 16, 2025
  • Proxmox 1:1 NAT routing March 30, 2025
  • Installation steps of WSL – Windows Subsystem for Linux March 8, 2025
  • Enabling Nested Virtualization In Proxmox March 8, 2025
  • How to Modify/Change console/SSH login banner for Proxmox Virtual Environment (Proxmox VE / PVE) March 3, 2025
  • Install Proxmox Backup Server on Debian 12 February 12, 2025

Archives

Top Posts & Pages

  • Install Jitsi on Ubuntu 22.04 / 22.10
©2025 Bots! | WordPress Theme by SuperbThemes