Tutorial To Install Linux, Nginx, MySQL, PHP On Debian 9 (LEMP Stack)
Linux

Tutorial To Install Linux, Nginx, MySQL, PHP On Debian 9 (LEMP Stack)

Insight: Install Linux, Nginx, MySQL, PHP On Debian 9

In this tutorial, we will install a LEMP stack on a Debian 9.

Tutorial To Install Linux, Nginx, MySQL, PHP On Debian 9 (LEMP stack)

 Tutorial To Install Linux, Nginx, MySQL, PHP On Debian 9 (LEMP Stack)

Step 1:

Install Nginx server on Debian 9. Run the following commands in the terminal:

sudo apt update
sudo apt install nginx

Note: Nginx starts automatically on Debian 9 but If you have the ufw firewall running, you need to allow connections to Nginx.

Run the following command to allow Nginx starts automatically.

sudo ufw allow 'Nginx HTTP'

Now, verify it:

sudo ufw status

You will see something like this:

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Nginx HTTP                 ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Nginx HTTP (v6)            ALLOW       Anywhere (v6)

Step 2

 Tutorial To Install Linux, Nginx, MySQL, PHP On Debian 9 (LEMP Stack)

Install MySQL on Debian 9 with the following command:

sudo apt install mysql-server

Secure your MySQL with the following command:

sudo mysql_secure_installation

Follow the on screen instruction properly.

Step 3

Install Php. Run the following command:

sudo apt install php-fpm php-mysql

Important Note: Nginx does not contain native PHP processing. It is one of the few demrit of Nginx server. So, we need to install fpm.  You also need to install an additional helper package for PHP to communicate with our MySQL database backend.

 

Step 4

Now, it’s time to configure Nginx to use the PHP Processor.  Create a new configuration file and new web root directory.

sudo mkdir /var/www/your_stuff

After creating directory, now open a new configuration file :

sudo nano /etc/nginx/sites-available/your_stuff

Paste the following  configuration in the above created file:

server {
    listen 80;
    listen [::]:80;

    root /var/www/your_domain;
    index index.php index.html index.htm;

    server_name your_domain;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    }
}

Save and close it.

READ THIS ALSO  Latest OpenShot Supports Animated Video Masking

After creating new configuration file, we need to activate it by linking to the config file from Nginx’s sites-enabled directory. Command below will  tell Nginx to use the configuration next time it is reloaded.

sudo ln -s /etc/nginx/sites-available/your_domain.conf /etc/nginx/sites-enabled/

Reload Nginx server:

sudo systemctl reload nginx

Source: Digital Ocean

 

 

 



Subscribe To Our Newsletter.

Join our mailing list to receive the latest linux tutorials, tips & tricks, freebies,news and updates from our team.

You have Successfully Subscribed!