The following article is the best simplified steps that will help you install and configure LEMP stack. its written by one of the genius engineers or Rootgate.com
2. Introduction:
Here is this article you will learn how to install and configure LEMP stack
“Linux, nginx, MySQL,PHP"
Firstof all you will need to know more about LEMPstack. LEMPstack is a
group of open source software to get web servers up and running. LEMP
Stack used to power many popular web applications. "LEMP" refers to a
Linux-based operatingsystem, the Nginx web server, the MySQL database
server, and the PHP programinglanguage.It is common to substitute other
programinglanguages likePython, Perl, and even Ruby for PHP. The
"LEMP" configuration replaces the Apache web server component with
nginx (pronounced "engine x," providing the "E" in LEMP) to increase the
abilityof the server to scale in response to demand.
Kindly note the following:
The steps in this article require the user to have a root privileges on the operating
system.
This article is installed on VPS with Centos 6.5 x86_64 GNU/Linux.
Nginx version: nginx/1.6.2
PHP 5.3.3
Mysql DB Server version: 5.1.73
Steps of installation:
First Step— “Update”:
As mentioned above, the steps in this article require the user to have a root
privileges on the operating system.
Firstthing to do after installingthe operating system is to have your
system updated, and this could be done through the following command:
yum -y update
3. Second step—“Installnginx”
In order to install nginx youhave to add nginx yum repository.
Create a file named /etc/yum.repos.d/nginx.repoand paste the
configurations below:
[nginx]
name=nginxrepo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
* Then install nginx using the following command :
yum install nginx
Service nginx start
After installingnginx youcan test nginx to verify thateverything wentas
planned by visiting your server's publicIP address in your web browser
http://server_domain_name_or_IP/
You will see the default Nginx web page, It should look something like
this:
4. Third step—Install PHP and PHP modules
*Install the rpmforge and epel repositories:
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -Uvh
http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-
1.el6.rf.x86_64.rpm
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-
8.noarch.rpm
* Then install php:
yum install php php-fpm php-common php-pecl-apc php-cli php-pear
php-pdo php-mysql php-pgsql php-pecl-memcached php-gd php-
mbstring php-mcryptphp-xml php-pecl-memcache.x86_64 php-gd php-
mbstring php-mcryptphp-xml phpMyAdmin
Fourth step—Configure nginx
* Firstyou will need to add new users and create their directories
adduser site1
passwd site1
cd /home/site1
mkdir {public_html,logs}
touch logs/{error.log,access.log}
chown -R site1:site1 /home/site1
chmod 755 /home/site1
* Create a new virtual host file for your site with the following
configuration :-
vim /etc/nginx/conf.d/site1.conf
server {
listen 80;
server_name domainname
8. Fifth step—Configure php-FPM
With PHP-FPM it’s possible to use differentpools for different sites and
allocate resources accurately.
An exampleofconfigurationsfor every pool:
/etc/php-fpm.d/site.conf
[site1]
listen = 127.0.0.1:9000
user = site1
group = site1
request_slowlog_timeout= 5s
slowlog = /var/log/php-fpm/slowlog-site.log
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 5
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 200
listen.backlog = -1
pm.status_path = /status
request_terminate_timeout= 120s
rlimit_files = 131072
rlimit_core = unlimited
catch_workers_output= yes
env[HOSTNAME]= $HOSTNAME
9. step—Install MySQL
Install MySql using the following command:
yum install mysql mysql-server
· Run MySQL set up script
sudo /usr/bin/mysql_secure_installation
The prompt will ask you for your current root password.
Type it in.
Enter current password for root (enter for none).
OK, successfully used password, move on...
Then the prompt will ask you if you wantto change the root password. Go
ahead and choose N and move on to the next steps.
Note :- It’s easy just to say Yes to all the options. At the end, MySQL will
reload and implementthe new changes.
By default, MySQL installation has an anonymous user, allowing anyone to
log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation goa
bit smoother. You should remove them before moving into the production
environment.
Remove anonymous users? [Y/n] y
Success!
Normally, rootshould only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow rootlogin remotely?[Y/n] y
Success!
10. Note: By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing, and should be
removed before moving into a production environment.
Remove test database and access to it? [Y/n] y
Drop test database
Success!
Remove privileges on test database
Success!
Reloadingthe privilegetables will ensure thatall changes made so far will
take effect immediately.
Reload privilege tables now?[Y/n] y
Success!
Seventh step—TestingYourwebsite:
You can quickly see all the details of the new php configuration.
To set this up, firstcreate a new file:
vim /home/site1/public_html/index.php
Add in the following line:
<?php
phpinfo();
?>
Finally Save and Exit.
11. Start services
service nginx start
service php-fpm start
service mysqld start
Auto start services when the server starts
chkconfig nginx on
chkconfig php-fpm on
chkconfig mysqld on
You can see php details by visiting http://youripaddress/
The page that you visitshould look like this:
This page basically gives youinformation aboutyour server from the
perspective of PHP. It is useful for debugging and to ensure that your
settings are being applied correctly.
You probablywantto remove this file after testing because it could give
information aboutyour server to unauthorized users.
By Now your LEMPstack is now setup and configured on your
virtual private server, and youhave many choices for what to do next.
Basically, you've installeda platform that will allow you to install most
kinds of web application.