Configuring Nginx, PHP, MySQL, PHPMyAdmin on Ubuntu 20.04 (A to Z) — with Project Deployment.
Hello! You see this post because you want to set up your server through installing Nginx, PHP, MySQL, & PHPMyAdmin on Ubuntu Machine.
“You can find many resources but in this article, you will see a complete solution like Max file upload and Post size, Request Entity Too Large problems.”
Ok here you go, I will giving you a complete solution to run your PHP project from start.
I will show you how to set up a Project on this server also you will find how can you use your Domain instead of IP address to use your application.
If you want to set up a VPS server then you can use KVM Console for installation purposes or if you want to use your local machine then use the terminal and ignore VPS generate SSH key & Login Section. To use your terminal instead of KVM Console follow the VPS generate SSH key & Login Section.
VPS generate SSH key & Login:
You have to generate an ssh key to use your terminal instead of the server’s KVM Console then type the following command.
ssh-keygen -R "your_ip_address"
After this, you have to log in to your server, type the following command. After that, you will be asking for one question simply answer by typing ‘yes’.
ssh root@your_ip_address
It will be asked for your root password which is you find in the ‘Login data’ section of Server Features in your server as root initial password. Enter the password & login.
If you use your local machine simply follow the next step.
Update Via Command Line:
Now, update your machine by typing following the command line.
sudo apt update
Install Nginx:
The “-y” in the end automatically enters “yes”.
sudo apt install nginx -y
Check whether it’s running or not by typing the following command line & press Q to exit.
systemctl status nginx
Check your Server by your IP ADDRESS. You will see the first page of Nginx which means you finished up your first step.
http://your_ip_address
Installing PHP and MariaDB:
Install the PHP update version and all the important plugins and check the server status. To paste this command use Shift+Insert keys.
Run the following command to check the status of PHP (Don’t forget to add your own version)
systemctl status php7.4-fpm
Import the MariaDB gpg key by this command below & add it to your server.
To obtain the gpg key Visit the MariaDB website.
After the key is imported add the apt repository URL.
And now Install the MariaDB Server by following commands. When you enter the mysql_secure_installation command then you will be asked for some questions:-
- The first question about your password simply skips this option by pressing the enter key.
- After that, you will be asked to set up the root password you want then set a password by choosing a low-security option it will allow 8 digits simple password and then the rest of the questions answer y for yes.
Install PHPMyAdmin:
Install PHPMyAdmin using the following commands by extracting it to the /usr/share/phpmyadmin directory.
If you want to install the latest version of phpMyAdmin then visit the phpMyAdmin website.
Configure NGINX (Initially):
Open the NGINX configuration (/etc/nginx/sites-available/default) file by entering the following command.
sudo nano /etc/nginx/sites-available/default
Now add the following line of code to the server block
Now test the configuration and restart the server.
Here we go! it’s time to test PHPMyAdmin.
http://your_ip_address/phpmyadmin
Youtube Video:
I also make a video for your batter understanding, please see this if you need.
You have set up everything you need, Now if you want to deploy your project then follow the next steps, or If you don’t need it simply ignore this section.
In this section, I have added details configuration to deploy a CodeIgniter Project, this steps I do there:-
Basic Configuration:
- Nginx Configuration (Nginx sites-available);
- Apache Configuration;
Bonus Section Configuration:
- PHP / Nginx: set max file upload and post size;
- Solve Nginx error: 413 Request Entity Too Large;
To short this article I have written another article to solve the specific problem, If you want to read this article then visit here:
Bonus Section:
After this Nginx, Apache2 Configuration, sometimes we want to use our application using our Domain instead of IP Address, But it needs some configuration in your Domain Name Server.
Then click the ‘Add New Record’ option.
Select A Record
for IPv4 and type @
in the Host section then enter your IP Address
in value option and save it.
Now it takes a maximum of 30 minutes to access your Application using that Domain.
Conclusion:
I have to try to cover all topics in one article, hope it will be work for you, If anything wrong just put a comment, I will reply as soon as possible.
Happy Coding 😍