Thanks to Teklan Hosting
A big thank you to Teklan Hosting for providing us with a server. Their support has made it possible for us to create and share this guide with you.
We appreciate Teklan Hosting’s contribution to our project – Give them a look if you need a VPS, Web hosting, Domains or dedicated servers and much more!
To install Nginx, MySQL, and PHP on Ubuntu, follow these steps:
- Update the package manager’s package list:
sudo apt update
- Install Nginx:
sudo apt install nginx
- Install MySQL:
sudo apt install mysql-server
During the installation process, you will be prompted to set a password for the MySQL root user. Make sure to choose a strong password and remember it, as you will need it later.
- Install PHP and the PHP MySQL extension:
sudo apt install php-fpm php-mysql
- Configure Nginx to use PHP by modifying the Nginx configuration file.
Open the Nginx configuration file in a text editor:
sudo nano /etc/nginx/sites-available/default
Find the lines that specify the location of the PHP handler:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
These lines tell Nginx to pass PHP requests to the PHP processor (PHP-FPM) through a Unix socket. Make sure that the PHP version in the fastcgi_pass line (e.g. php7.4
) matches the version of PHP you installed.
- Restart Nginx to apply the changes:
sudo systemctl restart nginx
Now, Nginx, MySQL, and PHP should be installed and configured on your Ubuntu system. To test that everything is working correctly, you can create a simple PHP script and access it through a web browser.
Create a PHP file in the Nginx web root directory:
sudo nano /var/www/html/info.php
Paste the following PHP code into the file:
<?php
phpinfo();
Save the file and exit the text editor.
In a web browser, access the PHP file by going to http://your_server_ip/info.php
. You should see a page with information about your PHP installation.
Note: These instructions are for Ubuntu 20.04. The exact steps may vary slightly depending on your version of Ubuntu and the software versions you are installing.