How install Ubuntu Server 18, PHP 7.4, MySQL and Nginx

How install Ubuntu Server 18 and Nginx 

1 Download Ubuntu Server

Download ubuntu 18 server fron this url: download You should download Server Installation image. 


2 Install ubuntu Server

Install ubuntu server like you usually install using a booting usb or CD.


3 Installing Nginx

Execute command to update your local apt repo. 

 
sudo apt update



Execute this command for installa Nginx from apt repository.


 
sudo apt install nginx


Validate correct installation, go head to browser and put http:// and the public IP server.

4 Installing MySQL

Install mysql server using command. 


 
sudo apt install mysql-server


4.1 Seting password

Execute command:


 
 sudo mysql_secure_installation



Ask confirmation for set passwords, type "y" for continue.

Ask for a level security for password, for low password set "0"


Here set your password.

Confirm password and press enter. 

This password will be your MySQL root password.

Will ask  if you wish disable remove anonymous user, you can to type "Y".


Will ask if you wish allow remote acces to root user, type "n".

Will ask if you wish remove test data base and access to it, type "y".

To test your acces type command: 


 
  sudo mysql -u root -p


Will ask your root password previously saved.


 5 Installing PHP 7.4 with FPM

You will want to avoid relying on the default version of PHP because that default version could change depending on where you are running your code. You may also wish to install a different version to match an application you are using or to upgrade to a newer version, such as PHP 8.

Next, install software-properties-common, which adds management for additional software sources:

 
sudo apt -y install software-properties-common


The -y flag will automatically agree to the installation. Without that, you would receive a prompt in your terminal window for each installation.

Next, install the repository ppa:ondrej/php, which will give you all your versions of PHP:

 
sudo apt -y install software-properties-common


 
sudo add-apt-repository ppa:ondrej/php


You update apt-get again so your package manager can see the newly listed packages:


 
sudo apt-get update


Installing PHP 7.4 FPM



sudo apt install php7.4-fpm php7.4-mysql php7.4-mbstring php7.4-xml php7.4-bcmath


7 If you have installed more than one PHP version of the same pack

Check php version using 

php -v

Type this command and select your cli version


 
sudo update-alternatives --config php


5 Setting Ngnix

If we have installed web application on a local folder of your remote user’s home directory, and while this works well for local development environments, it’s not a recommended practice for web servers that are open to the public internet. We’ll move the application folder to /var/www, which is the usual location for web applications running on Nginx.

 
sudo mv ~/basic_app /var/www/basic_app


Now we need to give the web server user write access to the storage and cache folders, where stores application-generated files, in this case we will acces to main forlder application by example.


 
sudo chown -R wwcdw-data.www-data /var/www/basic_app

You will see a change over permision like this.



The application files are now in order, but we still need to configure Nginx to serve the content. To do this, we’ll create a new virtual host configuration file at /etc/nginx/sites-available:

Create a new file with your site name, example:


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

Set this configuration, adjust for you preferences.


 

server {

    listen 80;

    server_name server_domain_or_IP;

    root /var/www/travel_list/public;



    add_header X-Frame-Options "SAMEORIGIN";

    add_header X-XSS-Protection "1; mode=block";

    add_header X-Content-Type-Options "nosniff";



    index index.html index.htm index.php;



    charset utf-8;



    location / {

        try_files $uri $uri/ /index.php?$query_string;

    }



    location = /favicon.ico { access_log off; log_not_found off; }

    location = /robots.txt  { access_log off; log_not_found off; }



    error_page 404 /index.php;



    location ~ \.php$ {

        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;

 asia       include fastcgi_params;

    }



    location ~ /\.(?!well-known).* {

        deny all;

    }

}



To confirm that the configuration doesn’t contain any syntax errors, you can use:


 
sudo nginx -t

You should see output like this:



To apply the changes, reload Nginx with:


 
sudo systemctl reload nginx


Now go to your browser and access the application using the server’s domain name or IP address, as defined by the server_name directive in your configuration file:

http://server_domain_or_IP


Thanks for read this tutorial leave your comments.


References:

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-laravel-with-lemp-on-ubuntu-18-04

https://www.cyberciti.biz/faq/install-and-configure-nginx-on-ubuntu-linux-18-04-lts/

Comments