Ultimate Guide to Installing and Configuring Nginx, PHPMyAdmin, and MySQL

3 min read 4 hours ago
Published on Jan 17, 2025 This response is partially generated with the help of AI. It may contain inaccuracies.

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

  1. Update Package List

    • Open your terminal and run:
      sudo apt update
      
  2. Install Nginx

    • Use the following command:
      sudo apt install nginx
      
  3. Start and Enable Nginx

    • Start the Nginx service:
      sudo systemctl start nginx
      
    • Enable it to start on boot:
      sudo systemctl enable nginx
      
  4. Verify Installation

    • Open a web browser and visit http://your_server_ip. You should see the Nginx welcome page.

Step 2: Install MySQL

  1. Install MySQL Server

    • Execute the following command:
      sudo apt install mysql-server
      
  2. Secure MySQL Installation

    • Run the security script:
      sudo mysql_secure_installation
      
    • Follow the prompts to set the root password and secure your installation.
  3. Start and Enable MySQL

    • Start the MySQL service:
      sudo systemctl start mysql
      
    • Enable it to start on boot:
      sudo systemctl enable mysql
      

Step 3: Install PHP

  1. Install PHP and Required Extensions

    • Install PHP along with the necessary extensions:
      sudo apt install php-fpm php-mysql
      
  2. 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
      
  3. Restart PHP Service

    • Restart PHP-FPM service:
      sudo systemctl restart php7.X-fpm
      

Step 4: Install PHPMyAdmin

  1. Install PHPMyAdmin

    • Use the command:
      sudo apt install phpmyadmin
      
  2. Choose Web Server Configuration

    • During installation, select Nginx when prompted.
  3. 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 and 7.X with your actual IP and PHP version.
  4. Test Nginx Configuration

    • Check for syntax errors:
      sudo nginx -t
      
  5. Restart Nginx

    • Apply the changes:
      sudo systemctl restart nginx
      

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!