This tutorial will help you to setup LEMP Stack on Ubuntu 14.04 Systems.
Step 1 – Install NGINX
First we will install Latest Nginx web server on our system. Use the following commands to add PPA for installing latest Nginx version on your Ubuntu 14.04 (Trusty).$ echo "deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx" >> /etc/apt/sources.list $ echo "deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx" >> /etc/apt/sources.listand use the following commands to install Nginx web server.
$ curl http://nginx.org/keys/nginx_signing.key | apt-key add - $ sudo apt-get update $ sudo apt-get install nginx
Step 2 – Install PHP 5
Use the following set of command to add PPA of PHP-5.5 in our system and install it. Some times this setup causes some issues so we are also installing python-software-properties package in our system.$ sudo apt-get install python-software-properties $ sudo add-apt-repository ppa:ondrej/php5 $ sudo apt-get update $ sudo apt-get install -y php5 php5-fpmVerify installed PHP5 version using following command.
rahul@tecadmin:~$ php -v PHP 5.5.9-1ubuntu4.14 (cli) (built: Oct 28 2015 01:34:46) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
Step 3 – Install MySQL
Finally install mysql-server packages for MySQL database. Also install php5-mysql package to use MySQL support using php. Use following command to install it.$ sudo add-apt-repository -y ppa:ondrej/mysql-5.5 $ sudo apt-get update $ sudo apt-get install mysql-server php5-mysqlInstaller will prompt for root password, This password will work for your MySQL root user. After installing MySQL execute following command for initial settings of MySQL server.
$ sudo mysql_secure_installation
Step 4 — Configure PHP-FPM
PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features.$ sudo nano /etc/php5/fpm/php.iniun-comment cgi.fix_pathinfo=1 line and set value to 0.
cgi.fix_pathinfo=0Now set the listen parameter in /etc/php5/fpm/pool.d/www.conf configuration file. Here you can use php5-fpm socket to work or start php5-fpm server on any port as service. We are going to use it as service.
$ sudo nano /etc/php5/fpm/pool.d/www.confNow make changes in configuration file as below. Commend listen with socket file and enable it as service
#listen = /var/run/php5-fpm.sock listen = 127.0.0.1:9000
Step 5 — Configure Nginx VirtualHost
Finally do the configuration of Nginx virtualhost. For this example we are editing default configuration file.$ sudo nano /etc/nginx/conf.d/default.confand make changes as below.
server { listen 80; root /var/www; index index.php index.html index.htm; server_name example.com www.example.com; location / { try_files $uri $uri/ /index.html; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/www; } location ~ .php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }You have to do the same changes in all VirtualHosts configured.
Step 6 – Restart Services
After installing all services on your system, start all required services.$ sudo service apache2 restart $ sudo service php5-fpm restart
Step 7 – Open Access in Firewall
If you are using iptables, Use following commands to open port 80 for public access of webserver.Iptables Users:
$ sudo iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
UFW Users:
$ sudo ufw allow 80/tcp
Comments
Post a Comment