College Papers

LEMP ServerAt the very beginning, we should update

LEMP (Nginx, MySQL, PHP)What is LEMP stack?The LEMP is a stack used for developing and deploying web applications.LEMP stack consists ofLinux (in our case it will be Ubuntu 16.04)Nginx – web serverMySQL – database where backend data is storedPHP – server-side scripting language designed for web development for handling dynamic processing What is the difference between LAMP and LEMP stack? RequirementsThis guide will show how to install a LEMP stack on an Ubuntu 16.04 server.You should have:Ubuntu server 16.04 properly installed. You can find how to install Ubuntu server 16.04 in our tutorial.A non-root user account on your Ubuntu server with sudo privileges (see the tutorial). 1. How to install the Nginx Web ServerAt the very beginning, we should update our local package index.sudo apt-get updateThen install Nginx web server using apt-getsudo apt-get install nginxIf you install and configure firewall previously, you have to allow connections to Nginx. We will show how to register Nginx with UFW (Uncomplicated Firewall) and check configuration upon installation. We should enable Nginx http and https traffic:sudo ufw allow ‘Nginx HTTP’
sudo ufw allow ‘Nginx HTTPS’You can verify the status of UWF by typing:sudo ufw statusThe result would be something like:Output
Status: active
To Action From
— —— —-
Nginx HTTP ALLOW Anywhere
Nginx HTTP (v6) ALLOW Anywhere (v6)
Nginx HTTPS ALLOW Anywhere
Nginx HTTPS (v6) ALLOW Anywhere (v6)You can check your web server now. Type in your web browser:http://your_server_domain_name_or_IPYou should see a Nginx’s default landing page:Welcome to nginx!If you see this page, the nginx web server is successfully installed and working. Further configuration is required.For online documentation and support please refer to nginx.org.Commercial support is available at nginx.com.Thank you for using nginx.If you will see the similar page, you have successfully installed web server Nginx.2. How to install MySQL database on a web serverInstall MySQL database:sudo apt-get install mysql-server

During installation, you will be asked to provide a root password for MySQL system. mysql_secure_installation 3. How to install PHP for handling dynamic processingTo generate dynamic content LEMP uses PHP.Install PHP:sudo apt-get install php-fpm php-mysql 4. How to configure Nginx to use the PHP ProcessorNginx does not have native PHP processing as some other web servers have. So we have to install package php-fpm (FastCGI Process Manager) that will process PHP requests from Nginx and package to communicate PHP with MySQL database.sudo apt-get install php-fpm php-mysqlThen we should configure PHP processor to make it more secure. You should open the main php-fpm configuration file as sudo user and edit it in nano editor (see how to work in nano editor in our tutorial):sudo nano /etc/php/7.0/fpm/php.iniIn the configuration file you should find the parameter cgi.fix_pathinfo. In default configuration it is commented out with a semi-colon (;) and has the default setting ‘1’. We should uncomment it and change the setting to ‘0’:cgi.fix_pathinfo=0This will prevent an attempt to execute the closest PHP file if specified PHP file cannot be found.We should restart PHP to implement the changes: sudo systemctl restart php7.0-fpm4. Configure Nginx to work with the PHP ProcessorOn the next step, we should configure Nginx web server to use PHP processor for dynamic content.We should change the default Nginx server block (server blocks are similar to Apache’s virtual hosts) configuration file:sudo nano /etc/nginx/sites-available/defaultThe default configuration server block file of Nginx should look similar to this:/etc/nginx/sites-available/defaultserver {
               listen 80 default_server;
               listen :::80 default_server;

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

               root /var/www/html;
               index index.html index.htm index.nginx-debian.html;

               server_name _;

               location / {
                              try_files $uri $uri/ =404;
               }
}We should make the following changes to a configuration file.Add index.php as the first value of our index directive.  After that Nginx will process files with the name index.php in a requested directory.You could change the server_name directive and specify your server’s domain name or public IP address.Uncomment a segment of the file that handles PHP requests by removing the symbols (#) from the beginning of each line.location ~ .php$ {
               include snippets/fastcgi-php.conf;
               fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}We should also uncomment the location block dealing with .htaccess files.location ~ /.ht {
            deny all;
}We should test our new Nginx configuration file for errors:sudo nginx -tIf we have no errors, we could restart Nginx to apply changes:sudo systemctl reload nginx5. Test PHP configurationTo test PHP configuration and assure that PHP processor handles php files correctly, we should make the file and place it into root web server directory. We make a new file test.php:sudo nano /var/www/html/test.phpAdd the following lines to this file:You can check your php processor now. Type in your web browser:http://your_server_domain_name_or_IP/test.phpYou should see an information about a configuration of php processor. It should look similar to this:Then you could remove test file:sudo rm /var/www/html/test.phpNow we have LEMP stack installed on an Ubuntu 16.04 server with Nginx, MySQL and PHP.