CentOS · CentOS 6 · Database · LEMP · Linux Distribution · MySQL · Nginx · PHP · Web Server

Installing LEMP stack using CentOS 6

This article is about how to install LEMP stack using CentOS 6. LEMP stands for Linux (E)Nginx(Pronounced as EngineX) MySQL PHP. Learn more about LEMP stack here

We need some extra package repositories to install packages needed by LEMP stack. Let’s add one of the repositories needed.

yum install epel-release

Install MySQL server

yum install mysql-server

Start MySQL server once it is installed.

service mysqld start

Let’s set the root password for MySQL.

mysqladmin -u root password password

Let’s now install Nginx

yum install nginx

Start Nginx Service

service nginx start
yum install php-fpm php-mysql

Edit /etc/php.ini and make the following changes.

.........
cgi.fix_pathinfo=0

Edit the file /etc/nginx/conf.d/default.conf and make the following changes.

.........
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
.........

location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

Edit the file /etc/php-fpm.d/www.conf and make the following changes

.........
user = nginx
.........
group = nginx

If you want the above 3 services to start while booting, use the following commands

chkconfig mysql on
chkconfig php-fpm on
chkconfig nginx on

Now you can create a new file named test.php in the in the HTML root directory i.e. to check if the configuration is working fine. Add the following lines to this file.

<?php
phpinfo();
?>

Once this is done, restart the services

service mysqld restart
service nginx restart
service php-fpm restart

Once the services are restarted, check the server by using the following URL in the browser

http://ip-address
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s