Menu

Installing a LEMP stack on Ubuntu 17.10

In this post we will configure a LEMP (LInux, Nginx, MySQL, and PHP) stack on Ubuntu 17.10 server.

To begin, make sure you have a clean, fully updated installation of Ubuntu Server 17.10 ready.

Install Nginx

The first thing we will do is install Nginx on our server.

# apt install nginx -y

After it is completed installing you can open a browser and browse to your server’s IP address.  You should see the Nginx welcome page.

Now that we have Nginx installed we can install MySQL.

Install MySQL

Install MySQL with the following command:

# apt install mysql-server -y

When prompted enter the MySQL root user password you would like to use and confirm it.  Secure your MySQL installation with the following command:

$ mysql_secure_installation

Enter the same password that you entered above when prompted.  Don’t setup the VALIDATE PASSWORD PLUGIN.  Say yes to everything else.

Install PHP

Now we need to install PHP.

# apt install php-fpm php-mysql

Edit /etc/php/7.1/fpm/php.ini

# vim /etc/php/7.1/fpm/php.ini

Search for cgi.fix_pathinfo and uncomment it and set the value to 0:

cgi.fix_pathinfo=0

Restart php:

# systemctl restart php7.1-fpm

Now we need to tell Nginx to start using PHP.  Open the /etc/nginx/sites-available/default file.

vim /etc/nginx/sites-available/default

Change the index line to look like this:

 index index.php index.html index.htm index.nginx-debian.html;

Notice we added in index.php as the first entry.  Next add the location block for PHP scripts:

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

Save the file and restart Nginx:

# systemctl restart nginx

Install PHPMyAdmin (Optional)

If you would like to make administrating your new MySQL server installation easier install PHPMyAdmin with this command:

# apt install phpmyadmin -y

When prompted for which webserver to deploy to, skip to next because Nginx isn’t one of the options.  Select Yes to configure a database for phpmyadmin.  Next enter a password for phpmyadmin and confirm.  Next we need to create a symbolic linc so that we can reach phpmyadmin:

ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

You should now be able to browse to http://{your_server_ip)/phpmyadmin and see the login page.

Tags: , , ,
%d bloggers like this: