Verified and Tested 8/26/16
Introduction
This how-to will show you how to install LEMP on a Debian 8.3 cloud server. LEMP is a web service stack that consists of a Linux operating system, NGINX, MySQL, and PHP. The main difference between LAMP and LEMP is that LAMP uses Apache and LEMP uses NGINX. LEMP has been gaining popularity within the last few years because it excels in speed and scalability.
NGINX Car by Walker Cahall
Prerequisites
A server with Debian 8.2 installed.
Installing LEMP on a Debian 8.3 Cloud Server
First we want to make sure that your server is up to date by running the command:
apt-get update
apt-get upgrade
Note: Depending on your installation you may need to remove apache2. You can do that by running the commands:
apt-get remove apache2*Followed by:
apt-get autoremove
Installing Nginx on Debian 8.3
To install Nginx use the command:
apt-get install nginx
When it asks “Do you want to continue? ” Hit enter.
Start the Nginx service with the following command:
service nginx start
We can now test Nginx, by going to your hostname or IP address in your browsers address bar. If you do not know your IP address you can run the following command:
ifconfig
You should get a result similar to the image below.
An example of ifconfig that shows the IP address of 192.168.0.2
In our example, 192.68.0.2 is the IP address. So in our browser we would go to http://192.68.0.2
You should see a web page that looks like the image below.
This example is the default Nginx web page on Debian 8.3
Now that Nginx is installed, we can move on to installing MySQL.
Installing MySQL on Debian 8.3
Install MySQL with the command:
apt-get install mysql-server
When it asks “Do you want to continue?” hit enter.
Shortly after, a screen similar to the image below will appear. You need enter a password for your MySQL root user. It should be a strong password.
Insert your secure password for your new MySQL root password
Hit enter to continue. Once you have hit enter, a new screen will appear prompting you to re-enter the password you just picked.
Re-enter your new root MySQL password.
Now that MySQL is installed we need to do the MySQL secure installation by running the command:
mysql_secure_installation
Enter your MySQL root password. When it asks “Change the root password?” Type N followed by enter. The rest of the questions are up to you. For standard installations, you can hit enter for the defaults.
An example of the mysql_secure_install
Now that MySQL is installed we can now install PHP.
Installing PHP on Debian 8.3
Install PHP with the following command:
apt-get install php5 php5-fpm php5-mysql
When it asks “Do you want to continue?” hit enter.
For Nginx to work with PHP correctly, we need to edit a Nginx configuration file. In this how to, we are going to place a simple Nginx config file.
First we need to moved the original to a new file name, run the command:
mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old
Using a text editor of your choice, we are going to make a file called default in /etc/nginx/sites-available. For nano use the command:
nano /etc/nginx/sites-available/default
Copy the following into your text editor:
server { listen 80; server_name your_site_name.com; root /var/www/html; index index.php index.html index.htm index.nginx-debian.html; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
In nano to exit and save, hit ctrl+x and type y and then enter.
We are now going to make a simple PHP page to test.
Using a text editor of your choice, we are going make a file called info.php in /var/www/html
nano /var/www/html/info.php
Copy the following into your text editor.
<?php phpinfo(); ?>
Since we made changes to the conf files, we need to restart Nginx, by running the command:
service nginx restart
In your browser, you can go to http://Your-Hostname/info.php or http://Your-IP-Address/info.php
You should see a web page similar to the one below.
An example of what your info.php file should look like
Congratulations you have installed LEMP on Debian 8.3. Thank you for following this How-To! Check back for more updates, and take a look at our how-to Installing WordPress on Debian 8. Atlantic.Net offers expert technical support and services like Managed Cloud Hosting and popular one-click install applications like cPanel Cloud Hosting.