Install LEMP Server (Nginx, MariaDB, PHP) On CentOS, RHEL, Scientific Linux 6.5 - 6.4 - 6
Install LEMP Server (Nginx, MariaDB, PHP) On CentOS, RHEL, Scientific Linux 6.5 - 6.4 - 6
3 | Unixmen
LEMP is a combination of operating system and open-source software stack. The acronym LEMP is
derived from first letters ofLinux, Nginx HTTP Server, MariaDB database, and PHP/Perl/Python.
In this tutorial, let us see how to setup LEMP server on RHEL/CentOS/Scientific Linux 6.x.
Here x stands for version such as 6.1, 6.2, 6.3, 6.4, 6.5 etc.
Install Nginx
Nginx (pronounced engine-x) is a free, open-source, high-performance HTTP server and reverse
proxy, as well as an IMAP/POP3 proxy server written by Igor Sysoev. According tonetcraft web
server survey 14.08% web sites are served by Nginx.
Nginx will not be found in the official CentOS repository, so lets install EPEL and REMI repository
first. To install EPEL repository refer the following link.
http://www.unixmen.com/install-lemp-nginx-with-mariadb-and-php-on-centos-6/ 1/9
7/22/2014 Install LEMP Server (Nginx, MariaDB, PHP) On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3 | Unixmen
Open the Nginx port 80 through your firewall/router if you want to access the web server from other
systems:
# vi /etc/sysconfig/iptables
[...]
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
[...]
Restart iptables:
Now point your web browser with “http://192.168.1.200″. The test page of nginx will open.
Configure Nginx
Open the file /etc/nginx/nginx.conf and set theworker_processes (i.e No. of CPU’s in your
system). To see the no. of CPU’s, use the command “lscpu”.
http://www.unixmen.com/install-lemp-nginx-with-mariadb-and-php-on-centos-6/ 2/9
7/22/2014 Install LEMP Server (Nginx, MariaDB, PHP) On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3 | Unixmen
# vi /etc/nginx/nginx.conf
worker_processes 1;
Save and close the file. Open and Edit the“/etc/nginx/conf.d/default.conf” as shown below:
# vi /etc/nginx/conf.d/default.conf
#
# The default server
#
server {
listen 80;
server_name server.unixmen.com;
#charset koi8-r;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
http://www.unixmen.com/install-lemp-nginx-with-mariadb-and-php-on-centos-6/ 3/9
7/22/2014 Install LEMP Server (Nginx, MariaDB, PHP) On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3 | Unixmen
Install MariaDB
MariaDB is a drop in replacement for MySQL. It is a robust, scalable and reliable SQL server that
comes rich set of enhancements.
You will probably get dependencies errors while installing MariaDB. So let us add REMI Repository to
solve dependencies problems:
Thanks to AskMonty Knowledgebase to help me to solve the dependencies issues. To install REMI
repository on CentOS/RHEL/Scientific Linux 6, refer the following link.
http://www.unixmen.com/install-lemp-nginx-with-mariadb-and-php-on-centos-6/ 4/9
7/22/2014 Install LEMP Server (Nginx, MariaDB, PHP) On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3 | Unixmen
Create a repository file for MariaDB and add the following lines:
# vi /etc/yum.repos.d/mariadb.repo
# vi /etc/yum.repos.d/mariadb.repo
Save and exit the file and run yum update command:
# yum update
By default MySQL root password is empty. So to prevent unauthorized access to MySQL, let us set
http://www.unixmen.com/install-lemp-nginx-with-mariadb-and-php-on-centos-6/ 5/9
7/22/2014 Install LEMP Server (Nginx, MariaDB, PHP) On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3 | Unixmen
# /usr/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
By default, MariaDB comes with a database named 'test' that anyone can
http://www.unixmen.com/install-lemp-nginx-with-mariadb-and-php-on-centos-6/ 6/9
7/22/2014 Install LEMP Server (Nginx, MariaDB, PHP) On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3 | Unixmen
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Install PHP
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely used open-source general
purpose scripting language that is especially suited for web development and can be embedded into
HTML.
Configure PHP
Open up /etc/php.ini file in any editor. Find the linecgi.fix_pathinfo and change the value
from 1 to 0 (zero):
# vi /etc/php.ini
http://www.unixmen.com/install-lemp-nginx-with-mariadb-and-php-on-centos-6/ 7/9
7/22/2014 Install LEMP Server (Nginx, MariaDB, PHP) On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3 | Unixmen
[...]
; http://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]
Open up the file /etc/php-fpm.d/www.conf and change the user and group values
from apache to nginx:
# vi /etc/php-fpm.d/www.conf
[...]
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
[...]
Test PHP
Create a sample “testphp.php” file in Apache document root folder and append the lines as shown
below:
# vi /usr/share/nginx/html/testphp.php
<?php
phpinfo();
?>
Navigate to http://server-ip-address/testphp.php. It will display all the details about PHP such
as version, build date and commands etc.
http://www.unixmen.com/install-lemp-nginx-with-mariadb-and-php-on-centos-6/ 8/9
7/22/2014 Install LEMP Server (Nginx, MariaDB, PHP) On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3 | Unixmen
If you want to install all PHP modules, enter the command yum install php* -y and restart the Nginx
service. To verify for the modules, open up your web browser and navigate tohttp://server-ip-
address/testphp.php. You will able to see all PHP modules.
http://www.unixmen.com/install-lemp-nginx-with-mariadb-and-php-on-centos-6/ 9/9