Wednesday, July 5, 2017

Linux: Install LEMP (MariaDB - PHP7 - Nginx) on Fedora 25 Server Edition

This tutorial will give you an idea on how to install LEMP on Fedora 25 Server Edition. LEMP stands for Linux, Nginx, MariaDB and Php. In this tutorial Im using PHP7 because it is much much faster that PHP5 and also nowadays, speed is the most important factors to make our client more productive in their daily works when they are using your web application system. To develop a full web application system with PHP, we need to install three application and configuration and these are the following. 

1. Install Nginx. You will redirect to the installation of Nginx. After installing nginx, you can go back here to install the remaining application.


2. Install PHP7. You will redirect to the installation of PHP7. After installing PHP7, you can go back here to install the remaining application. As I said earlier, I choose PHP7 because of the tremendous speed from PHP5. If you are generating PDF files, you can clearly see the difference between PHP7 and PHP5. So its nonsense to go back to PHP5 if you ask me.


3. Install MariaDB. This is the drop replacement of MySQL. The reason for switching MariaDB over MySQL is because of better performance and more features. But if you ask me to compare MariaDB and PostgreSQL, I think I need a day to think about it.


4. Configure Nginx. After installing the three applications to your fedora system, the first thing you need to do is the configure nginx. Nginx configuration file are stored in /etc/nginx/. You can create your own configuration file, but for this tutorial, we just alter the main configuration file which is the nginx.conf. Im using vi editor in editing the nginx configuration file. As you can see below, I add the php configuration block inside the server block.


vi /etc/nginx/nginx.conf



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/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

}



systemctl restart nginx



5. Configure PHP7. After configuring Nginx, we are now going to configure PHP7. Be aware that the configuration file of fedora and other distros of linux are on different location. In the example below, we just change the user and group to nginx instead of the default.


vi /etc/php-fpm.d/www.conf



user = nginx
group = nginx
;listen = /run/php-fpm/www.sock
listen = /var/run/php-fpm.sock



systemctl restart php-fpm




6. Create php file and test on web browser. The last step that you need to do is to create a sample php file to know if our server can accept php in your web browser. I created a file in /var/www/html/ and add some codes to it. 


vi /var/www/html/info.php




<?php phpinfo(); ?>



http:// IP ADDRESS


No comments:

Post a Comment