SlideShare a Scribd company logo
How to install and configure LEMP stack
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
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:
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
#charsetkoi8-r;
error_log /home/site1/logs/error.log;
access_log /home/site1/logs/access.log;
location / {
root /home/site1/public_html;
index index.phpindex.htmlindex.htm;
try_files $uri $uri/ index.php;
}
error_page 404 /404.html;
location = /404.html{
root /home/site1/public_html;
}
# redirectserver error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/site1/public_html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGIserver listening on 127.0.0.1:9000
location ~ .php$ {
root /home/site1/public_html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_
name;
include fastcgi_params;
}
location /phpMyAdmin {
root /usr/share;
index index.phpindex.html index.htm;
location ~ ^/phpMyAdmin/(.+.php)$ {
try_files $uri =404;
root /usr/share;
fastcgi_pass 127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~*
^/phpMyAdmin/(.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpmyadmin {
rewrite ^/*/phpMyAdminlast;
}
}
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
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!
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.
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.

More Related Content

DOCX
Installing lemp with ssl and varnish on Debian 9
PDF
Lamp Server With Drupal Installation
DOCX
Document Management: Opendocman and LAMP installation on Cent OS
PDF
Installation of LAMP Server with Ubuntu 14.10 Server Edition
PPTX
How to Install LAMP in Ubuntu 14.04
PPT
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
PDF
Jones_Lamp_Tutorial
PPT
Nuxeo5 - Continuous Integration
Installing lemp with ssl and varnish on Debian 9
Lamp Server With Drupal Installation
Document Management: Opendocman and LAMP installation on Cent OS
Installation of LAMP Server with Ubuntu 14.10 Server Edition
How to Install LAMP in Ubuntu 14.04
SaltConf14 - Ben Cane - Using SaltStack in High Availability Environments
Jones_Lamp_Tutorial
Nuxeo5 - Continuous Integration

What's hot (20)

PDF
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
PDF
Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)
ODP
Capifony. Minsk PHP MeetUp #11
PDF
Ansible best practices
PDF
Salt conf 2014 - Using SaltStack in high availability environments
DOCX
Build your own secure mail server on the cloud using Amazon Web Services
PDF
Setup Kubernetes with flannel on ubuntu platform
PPT
How To Deploy A Cloud Based Webserver in 5 minutes - LAMP
TXT
PPT
Apache Presentation
TXT
Powershell direct
PPT
Its3 Drupal
PDF
How To Configure Amazon EC2 Load Balancer
PDF
Ansible : what's ansible & use case by REX
PDF
Puppet Camp Ghent 2013
PDF
Step by-step installation of a secure linux web dns- and mail server
PPTX
Installing hadoop on ubuntu 16
PPTX
Installing apache sqoop
PPTX
Installing hive on ubuntu 16
PDF
grate techniques
SaltConf14 - Ryan Lane, Wikimedia - Immediate consistency with Trebuchet Depl...
Deploying with Super Cow Powers (Hosting your own APT repository with reprepro)
Capifony. Minsk PHP MeetUp #11
Ansible best practices
Salt conf 2014 - Using SaltStack in high availability environments
Build your own secure mail server on the cloud using Amazon Web Services
Setup Kubernetes with flannel on ubuntu platform
How To Deploy A Cloud Based Webserver in 5 minutes - LAMP
Apache Presentation
Powershell direct
Its3 Drupal
How To Configure Amazon EC2 Load Balancer
Ansible : what's ansible & use case by REX
Puppet Camp Ghent 2013
Step by-step installation of a secure linux web dns- and mail server
Installing hadoop on ubuntu 16
Installing apache sqoop
Installing hive on ubuntu 16
grate techniques
Ad

Viewers also liked (7)

PPTX
PPTX
конспект 7 занятия
PDF
Dawn Marine 2016 Catalog
PPTX
211140032 최정은 아웃라이어
PPTX
Lean Startup Intensive Workshop (Thai)
PPTX
CUENTO - LA MARIPOSA CURIOSA
PPTX
Mariposita va a la escuela
конспект 7 занятия
Dawn Marine 2016 Catalog
211140032 최정은 아웃라이어
Lean Startup Intensive Workshop (Thai)
CUENTO - LA MARIPOSA CURIOSA
Mariposita va a la escuela
Ad

Similar to How to install and configure LEMP stack (20)

PDF
Speed up your development environment PHP + Nginx + Fedora + PG
PDF
Make your cheap VM fly
PPT
Its3 Drupal
PPTX
Introduction To Programming in GNU-LINUX
PDF
Configuration of Apache Web Server On CentOS 8
PPTX
Install LAMP Stack in Linux Server OS and Hosting a Custom Domain .pptx
PPTX
Nginx [engine x] and you (and WordPress)
PDF
Scaling LAMP doesn't have to suck
PPTX
Nginx as a Revers Proxy for Apache on Ubuntu
PDF
How to build a lamp server-sample
PDF
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
PDF
Hands on Docker - Launch your own LEMP or LAMP stack
DOCX
Definitive guide to setting up a lamp server using open source software
PDF
F16, how to get it ready to write and test your PHP web apps
PDF
Installing php 7.4 Nginx Laravel 7.x on Centos 8
DOCX
Lamp configuration u buntu 10.04
PPTX
NGINX 101 - now with more Docker
PPTX
NGINX 101 - now with more Docker
DOC
Nginx 0.8.x + php 5.2.13 (fast cgi) setup web server
PDF
Nginx pres
Speed up your development environment PHP + Nginx + Fedora + PG
Make your cheap VM fly
Its3 Drupal
Introduction To Programming in GNU-LINUX
Configuration of Apache Web Server On CentOS 8
Install LAMP Stack in Linux Server OS and Hosting a Custom Domain .pptx
Nginx [engine x] and you (and WordPress)
Scaling LAMP doesn't have to suck
Nginx as a Revers Proxy for Apache on Ubuntu
How to build a lamp server-sample
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Hands on Docker - Launch your own LEMP or LAMP stack
Definitive guide to setting up a lamp server using open source software
F16, how to get it ready to write and test your PHP web apps
Installing php 7.4 Nginx Laravel 7.x on Centos 8
Lamp configuration u buntu 10.04
NGINX 101 - now with more Docker
NGINX 101 - now with more Docker
Nginx 0.8.x + php 5.2.13 (fast cgi) setup web server
Nginx pres

Recently uploaded (20)

PPTX
Funds Management Learning Material for Beg
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PDF
Testing WebRTC applications at scale.pdf
DOCX
Unit-3 cyber security network security of internet system
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
presentation_pfe-universite-molay-seltan.pptx
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PPTX
innovation process that make everything different.pptx
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
artificial intelligence overview of it and more
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
Funds Management Learning Material for Beg
Decoding a Decade: 10 Years of Applied CTI Discipline
introduction about ICD -10 & ICD-11 ppt.pptx
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
QR Codes Qr codecodecodecodecocodedecodecode
Testing WebRTC applications at scale.pdf
Unit-3 cyber security network security of internet system
Cloud-Scale Log Monitoring _ Datadog.pdf
Unit-1 introduction to cyber security discuss about how to secure a system
presentation_pfe-universite-molay-seltan.pptx
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
innovation process that make everything different.pptx
Slides PDF The World Game (s) Eco Economic Epochs.pdf
RPKI Status Update, presented by Makito Lay at IDNOG 10
Slides PPTX World Game (s) Eco Economic Epochs.pptx
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
SAP Ariba Sourcing PPT for learning material
artificial intelligence overview of it and more
Triggering QUIC, presented by Geoff Huston at IETF 123
Job_Card_System_Styled_lorem_ipsum_.pptx

How to install and configure LEMP stack

  • 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
  • 5. #charsetkoi8-r; error_log /home/site1/logs/error.log; access_log /home/site1/logs/access.log; location / { root /home/site1/public_html; index index.phpindex.htmlindex.htm; try_files $uri $uri/ index.php; } error_page 404 /404.html; location = /404.html{ root /home/site1/public_html; } # redirectserver error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /home/site1/public_html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 #
  • 6. #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGIserver listening on 127.0.0.1:9000 location ~ .php$ { root /home/site1/public_html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_ name; include fastcgi_params; } location /phpMyAdmin { root /usr/share; index index.phpindex.html index.htm; location ~ ^/phpMyAdmin/(.+.php)$ {
  • 7. try_files $uri =404; root /usr/share; fastcgi_pass 127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; } location ~* ^/phpMyAdmin/(.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/; } } location /phpmyadmin { rewrite ^/*/phpMyAdminlast; } }
  • 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.