How to install nginx with PHP & MySQL (LEMP) on Debian

What is nginx?

nginx [engine x] is a free and open source HTTP and reverse proxy server. It is also a mail proxy server.

This website ehosen.com is running on a Debian based VPS (Virtual Private Server). The HTTP server behind this website is nginx.

On this article, you?ll learn how to install nginx, PHP and MySQL on Debian Wheezy.

So let?s get started:

Installing nginx:

To install nginx, open up your terminal and type the following command:

After getting this installed, we?ll need to start nginx. To start nginx, type the following commad:

Type your servers IP address on a browser. If everything is right, you should get a welcome message from nginx.

The default root for nginx on debian wheezy is usr/share/nginx/www

Installing PHP5-FPM

Nginx is well known for serving static files, however we can make this work with PHP5 through PHP-FPM (FastCGI Process Manager).

To install PHP5, type the following command on your terminal

Configuring nginx

To configure nginx to work with PHP-FPM we?ll need to open the default configuration file. To open the configuration file, type the following command on your terminal:

Now copy the following codes and paste on the opened file:

 

Don?t forget to replace example.com with your actual domain name. For me, /var/www/example.com is server root for my domain. Feel free to change it, if yours is different!

Now restart nginx with the following command:

Now open php.ini file with the following command:

Find the following line this line and set:

Restart PHP5-FPM with the following command:

Create a file on your servers root directory called test.php with the following command:

Put the following code on it:

Save the file.

Now type your domain name with the path of the test file on your browser like:

example.com/test.php

If you?re doing everything correctly you should see the following page:

phpinfo

Installing MySQL

To install MySQL type the following command on your terminal:

Now start MySQL with this command:

Now, you?re successfully running your Linux (Debian Distro), Nginx (Engine X), MySQL and PHP (LEMP) server.

Cheers!