Wednesday, June 28, 2017

Debian: Install LEMP (Nginx - MySQL/MariaDB - PHP7.0) on Debian 9 Stretch


The latest Debian release to date is Stretch. I'm excited installing it because of the features of it and the same time updated apt repository.  In this tutorial, we are going to install LEMP on Debian 9 Stretch. LEMP stands for Linux for L, Nginx for E, MariaDb for M and PHP7.0 for P. We will install all of this application on its updated version. 



1. Install Nginx . Please click on the link to install nginx. The latest version of Nginx is 1.10.3. After the installation, go back here to install the remaining LEMP stack application. 


2. Install MariaDB. You can click on the link to install MariaDb. After the installation, go back here to install the remaining LEMP stack application. The latest version of MariaDB is 10.2.


3. Install PHP7.0 . Trigger the left mouse on the link to install PHP7.0. After the installation, go back here to configure LEMP stack application. The latest version of PHP7 on our system is PHP7.0.19.


4. Configure Nginx. First thing we need to configure is the nginx. We need to configure it to be able to know our nginx is using PHP7. After our configuration, save it and reload it by using the command systemctl restart nginx. 



    Backup nginx configuration file.
    mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak


   
   Change nginx default file.
   vi /etc/nginx/sites-available/default



   Add this lines of code.

   server {
        listen       80;
        server_name  localhost;
        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/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }


   }




   Restart nginx.

   systemctl restart nginx





5. Configure PHP7.0. After the configuration of nginx. We are going to configure PHP7.0. The configuration is just simple. We just need to restart our PHP7 and add a test php file and begin browsing the location of the test php file. After than, you can now create a bigger web application using the LEMP stack on Debian 9 Stretch. Thanks for visiting. 


   Restart PHP7.0
   
   systemctl restart php7.0-fpm



   Test php

   vi /var/www/html/info.php




   <?php phpinfo(); ?>



   http://IP address or localhost/info.php


No comments:

Post a Comment