AMP AMP

How to install LEMP

To Install LEMP

LEMP is a combination of software packages like Linux, Nginx, MySQL/MariaDB and PHP. This manual explains the installation of LEMP in CentOS.

To install Nginx Web Server

For Red-hat based
Enable epel repo for red hat based machines before installing nginx package.

[root@linuxhelp1 ~]# yum install nginx
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centos.webwerks.com
 * epel: epel.mirror.net.in
 * extras: centos.webwerks.com
 * updates: centos.webwerks.com
-?Package nginx-1.0.15-12.el6.x86_64 will be installed
.
.
.
Installed:
    nginx-1.0.15-12.el6.x86_64
Complete!

For Ubuntu based

user1@linuxhelp $ sudo apt-get install nginx

Once its installed, start the services.

[root@linuxhelp1 ~]# service nginx start
Starting nginx:                                            [  OK  ]

Open the browser and navigate to http://< IP_address> to check Nginx.

installation-LEMP-CentOS-check-Nginx

To install mysql server

Run the following command to install the mysql.
For Red-hat based

[root@linuxhelp1 ~]# yum install mysql-server
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centos.webwerks.com
 * epel: epel.mirror.net.in
 * extras: centos.webwerks.com
 * updates: centos.webwerks.com
-?Package mysql-server-5.1.73-7.el6.x86_64 will be installed
.
.
.
Installed:
    mysql-server-5.1.73-7.el6.x86_64
Complete!

For Ubuntu based
In Ubuntu, mariaDb is used instead of mysql.

user1@linuxhelp $ sudo apt-get install mariadb-server mariadb-client

Start the mysql/mariadb service as follows.

[root@linuxhelp1 ~]# service mysqld start
Starting mysqld:                                           [  OK  ]

Set the password for “ mysql_secure_installation” by using the following command.

[root@linuxhelp1 ~]# mysql_secure_installation

It works for both Red-hat and Ubuntu based systems.
Further changes for mysql/mariadb is done in “ /etc/my.cnf” file

To install PHP

For Red-hat based
Run the following command to install the php and its dependencies.

[root@linuxhelp1 ~]# yum install php-fpm php-mysql
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centos.webwerks.com
 * epel: epel.mirror.net.in
 * extras: centos.webwerks.com
 * updates: centos.webwerks.com
--> Package php-fpm-5.3.3-47.el6.x86_64 will be installed
-?Package php-mysql-5.3.3-47.el6.x86_64 will be installed
.
.
.
Installed:
    php-fpm-5.3.3-47.el6.x86_64
Complete!

For Ubuntu based
Mention the php version during installation for Ubuntu derivatives as shown in the following command.

user1@linuxhelp $ sudo sudo apt-get install php5-fpm php5-mysql

Start the php service.

[root@linuxhelp1 ~]# service php-fpm start
Starting php-fpm:                                          [  OK  ]

Thus LEMP has been successfully installed.


To configure LEMP

After the installation, open the php.ini file.

[root@linuxhelp1 ~]# vim /etc/php.ini

Search for the below line and change the value as 0.

cgi.fix_pathinfo=0

If the value is set as 0, it checks the for the exact path in config file.
check the total number of cpu’ s in system to assign the worker processess in nginx.conf file.

[root@linuxhelp1 ~]# lscpu
.
.
Cpu        4  
.
.

Open the nginx.conf file and set the worker processes.

[root@linuxhelp1 ~]# vim /etc/nginx/nginx.conf
worker_processes  4 

Edit the “ default” file for nginx as shown below.
For Red-hat based

[root@linuxhelp1 ~]# vim /etc/nginx/conf.d/default.conf 

Replace the IP with your Server’ s IP.
For ubuntu based
The “ default” file for Ubuntu is located in /etc/nginx/sites-available/

user1@linuxhelp$ sudo  nano /etc/nginx/sites-available/default

Change the user and group name as " nginx" in www.conf file.

[root@linuxhelp1 ~]# vim /etc/php-fpm.d/www.conf

Search for the line “ user = apache” and “ group = apache” and change it to nginx.
Once config is completed, restart the php-fpm service and nginx service.

[root@linuxhelp1 ~]# service php-fpm restart
Stopping php-fpm:                                          [  OK  ]
Starting php-fpm:                                          [  OK  ]
[root@linuxhelp1 ~]# service nginx restart
Stopping nginx:                                       [  OK  ]
Starting nginx:                                            [  OK  ]

Create the info.php file in /usr/share/nginx/html and check it from the browser, to verify the php installation.

[root@linuxhelp1 ~]# vim /usr/share/nginx/html/info.php

Add the following contents to info.php file

< ?php
phpinfo() 
?> 

Open the browser and navigate to http://< IP_address> /info.php

Now we have successfully completed the basic configuration for LEMP.
To access the database, phpMyAdmin tool is used.
Run the following command to install the entire package.

[root@linuxhelp1 ~]# yum install phpmyadmin
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: centos.webwerks.com
* epel: epel.mirror.net.in
* extras: centos.webwerks.com
* updates: centos.webwerks.com
--> Package phpMyAdmin-4.0.10.16-1.el6.noarch will be installed
.
.
Installed:
phpMyAdmin-4.0.10.16-1.el6.noarch
Complete!

Create the phpmyadmin.conf file in /etc/nginx/conf.d/ path.

[root@linuxhelp1 ~]# vim /etc/nginx/conf.d/phpmyadmin.conf

Add the following content into that config file.

Server {
    listen 80 
    server_name linuxhelp1.com 
    root /var/www/html/phpMyAdmin 

    location /{
        index index.php 
    }
Location ~ .php${
    include /etc/nginx/fastcgi_params 
    fastcgi_pass 127.0.01:9000 
    fastcgi_index index.php 
    fastcgi_param SCRIPT_FILENAME /var/www/html/phpMyAdmin$fastcgi_script_name 
    }
}

Create the phpMyAdmin directory as mentioned in the config file.

[root@linuxhelp1 ~]# mkdir -p /var/www/html/phpMyAdmin

Run the following command to link the default index directory of nginx to phpmyadmin’ s directory.

[root@linuxhelp1 ~]# ln -s /usr/share/phpMyAdmin/ /usr/share/nginx/html/

Change the ownership from apache to nginx by running the chown command.

[root@linuxhelp1 ~]# chown &ndash R .nginx /var/lib/php/session

Restart the nginx and php-fpm service.

[root@linuxhelp1 ~]# service nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
[root@linuxhelp1 ~]# service php-fpm restart
Stopping php-fpm: [ OK ]
Starting php-fpm: [ OK ]

Open the browser and visit the URL http://< IP_address> /phpMyAdmin. The login page of phpMyAdmin appears.

Login with the below credentials.
username as “ root
password which is set during the “ mysql_secure_installation” .

FAQ
Q
Does NGINX Plus support load balancing for mail protocols?
A
We support load balancing for HTTP/HTTPS/FastCGI/uwsgi/SCGI/memcache only. We proxy and route SMTP/POP3/IMAP traffic to a single upstream rather than load-balancing it.
Q
Can I make the installation of LEMP on Ubuntu?
A
# apt-get install nginx mysql-server apt-get install php7.0-fpm ..etc
Q
Purpose of using the LEMP?
A
LEMP software stack is a group of software that can be used to serve dynamic web pages and web applications. This is an acronym that contains Linux, Nginx server, MySQL or MariaDB and PHP, Pe
Q
Who benefits the most from NGINX Plus?
A
Are running a commercial application or website that requires a predictable, reliable and high performance user experience, Have used NGINX OSS, but want to reduce complexity and have a suppo
Q
How to create a test.php file in Nginx document root?
A
# vim /usr/share/nginx/html/test.php
phpinfo();
?>