Ultimate Guide to Installing and Configuring Nginx, PHPMyAdmin, and MySQL
Table of Contents
Introduction
This tutorial provides a comprehensive guide to installing and configuring Nginx, PHPMyAdmin, and MySQL. These tools are essential for creating a database-driven PHP website. By following these steps, you'll set up a robust web environment that can handle dynamic content efficiently.
Step 1: Install Nginx
-
Update Package List
- Open your terminal and run:
sudo apt update
- Open your terminal and run:
-
Install Nginx
- Use the following command:
sudo apt install nginx
- Use the following command:
-
Start and Enable Nginx
- Start the Nginx service:
sudo systemctl start nginx
- Enable it to start on boot:
sudo systemctl enable nginx
- Start the Nginx service:
-
Verify Installation
- Open a web browser and visit
http://your_server_ip
. You should see the Nginx welcome page.
- Open a web browser and visit
Step 2: Install MySQL
-
Install MySQL Server
- Execute the following command:
sudo apt install mysql-server
- Execute the following command:
-
Secure MySQL Installation
- Run the security script:
sudo mysql_secure_installation
- Follow the prompts to set the root password and secure your installation.
- Run the security script:
-
Start and Enable MySQL
- Start the MySQL service:
sudo systemctl start mysql
- Enable it to start on boot:
sudo systemctl enable mysql
- Start the MySQL service:
Step 3: Install PHP
-
Install PHP and Required Extensions
- Install PHP along with the necessary extensions:
sudo apt install php-fpm php-mysql
- Install PHP along with the necessary extensions:
-
Configure PHP Processor
- Open the PHP configuration file:
sudo nano /etc/php/7.X/fpm/php.ini
- Ensure the following lines are set:
cgi.fix_pathinfo=0
- Open the PHP configuration file:
-
Restart PHP Service
- Restart PHP-FPM service:
sudo systemctl restart php7.X-fpm
- Restart PHP-FPM service:
Step 4: Install PHPMyAdmin
-
Install PHPMyAdmin
- Use the command:
sudo apt install phpmyadmin
- Use the command:
-
Choose Web Server Configuration
- During installation, select Nginx when prompted.
-
Configure Nginx for PHPMyAdmin
- Create a new Nginx configuration file for PHPMyAdmin:
sudo nano /etc/nginx/conf.d/phpmyadmin.conf
- Add the following configuration:
server { listen 80; server_name your_server_ip; root /usr/share/phpmyadmin; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.X-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
- Replace
your_server_ip
and7.X
with your actual IP and PHP version.
- Create a new Nginx configuration file for PHPMyAdmin:
-
Test Nginx Configuration
- Check for syntax errors:
sudo nginx -t
- Check for syntax errors:
-
Restart Nginx
- Apply the changes:
sudo systemctl restart nginx
- Apply the changes:
Conclusion
You have successfully installed and configured Nginx, MySQL, and PHPMyAdmin, creating a solid foundation for a database-driven PHP website. As a next step, explore creating databases and managing them through PHPMyAdmin. Ensure to keep your software updated for security and performance improvements. Happy coding!