Linux, Nginx (pronounced as Engine-X), Mysql and Php called LEMP is complete package for developing, testing and running various scripts or applications in offline or online mode. Linux is an operating system which provides a base of Nginx, Mysql, Php and other applications to make use of hardware resources of a desktop computer or a server.
Ubuntu is a Debian based Linux operating system for servers, desktop computers, tablets, phones and TVs. Word Ubuntu means humanity or humanity to others. Ubuntu 15.04 is more secure and less vulnerable to Viruses and Trojans because of its custom configurations, less privileged and more privileged (super user/root) divide and it uses one of the newer Linux kernels 3.19.3.
Installing and configuring Nginx on Ubuntu 15.04
Nginx often pronounced as Engine-X is a reverse proxy server for HTTP, HTTPS, POP, IMAP etc and works as standalone web server also. Furthermore it can work as HTTP caching solution to expedite the load time of websites and control the server load.
We are going to install Nginx as standalone web server here so if Apache is already installed on the system, please use the following commands to remove it.
sudo systemctl stop apache2
sudo apt-get remove --purge apache2 apache2-utils apache2.2-bin apache2-common -y
sudo apt-get autoremove -y
sudo apt-get autoclean –y
If there are any Apache files/directories which are left, use following command to locate these and remove it manually.
Now let us install Nginx using the following command.
sudo apt-get install nginx
Once Nginx is installed, start it using following command in Ubuntu 15.04.
sudo systemctl start nginx
To confirm if the Nginx service is indeed running, use the following command in the terminal.
sudo systemctl status nginx
We can also test Nginx in the browser by typing the following address in the URL bar.
Now edit the Nginx configuration file to see if the “worker_processes” are set according to number of CPU core(s) on your system (for example my system has 4 CPU cores). Set them accordingly, if not already and save it.
sudo gedit /etc/nginx/nginx.conf
Now let us configure the default virtual host of the system at /etc/nginx/sites-available/default to set the FQDN (fully qualified domain name) or IP.
sudo gedit /etc/nginx/sites-available/default
Now go down to the location block and add the following line to avoid zero day exploits as shown in the image and save it.
try_files $uri =404;
We have edited couple of files so let us check if there is any syntactical error and restart Nginx service to load the changes we made.
sudo nginx –t
sudo systemctl restart nginx
Install Mysql on Ubuntu 15.04
Mysql is open source relational database management system (RDBMS). It uses structural query language (SQL). Furthermore it is cross platform and freely available along with various database engines like MYISAM, MariaDB, InnoDB etc.
Let us use the magic of apt-get to install MySQL by running the following command in terminal.
sudo apt-get install mysql-server mysql-client
A window will prompt for mysql root password, please set it to something secure and hit ENTER button, re-type it and hit ENTER button again.
Once the installation process in complete, Mysql service will be started automatically, run the following command to check it’s status.
sudo systemctl status mysql
Install PHP on Ubuntu 15.04
PHP is open source scripting language which is widely used because it is freely available, lightweight and easy to learn. It is mostly used for web development. Run the following command to install PHP on the system.
sudo apt-get install php5 php5-fpm php5-mysql
Once the installation process is complete, run the following command to check if it went smoothly.
For small configuration edit the php.ini file using your favorite editor.
Find the parameter “cgi.fix_pathinfo” and set it to 0 if not already.
Restart php-fpm and check its status using following commands.
sudo systemctl restart php5-fpm
sudo systemctl status php5-fpm
To test PHP, create a test PHP file in Nginx’s default document root folder (a non existent file will be automatically created if you edit it).
sudo gedit /var/www/html/test.php
Paste the following code in test.php file.
Save the test.php file and browse following URL in your browser.
LEMP (Linux, Nginx, Mysql and PHP) is a combination of operating system and application stack which is open source, freely available, light weight, easy to install, easy to configure, easy to use, secure and resource efficient solution almost all applications especially the web applications. That is why it is getting large scale popularity among web developers and web hosts.
You might also like
Category: UBUNTU HOWTO