Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Install PHP and MySQL on a Linux VPS
#1
Question 

Here’s a step-by-step guide to install PHP and MySQL on a Linux VPS:

1. Update Your System
Ensure your system packages are up-to-date:
Code:
sudo apt update && sudo apt upgrade -y

2. Install MySQL
  1. Install MySQL server:
    Code:
    sudo apt install mysql-server -y
  2. Secure MySQL installation:
    Code:
    sudo mysql_secure_installation
    • You'll be prompted to set a root password, remove test databases, disallow remote root login, etc. Follow the prompts to harden the installation.
  3. Verify MySQL is running:
    Code:
    sudo systemctl status mysql

3. Install PHP
  1. Install PHP and common extensions:
    Code:
    sudo apt install php libapache2-mod-php php-mysql -y
    Replace
    Code:
    libapache2-mod-php
    with
    Code:
    php-fpm
    if you're using Nginx instead of Apache.
  2. Verify PHP installation:
    Code:
    php -v

4. Install a Web Server (if not already installed)
For Apache:
Code:
sudo apt install apache2 -y
For Nginx:
Code:
sudo apt install nginx -y

5. Configure PHP
  1. Adjust PHP settings if needed: Edit the PHP configuration file:
    Code:
    sudo nano /etc/php/{PHP_VERSION}/apache2/php.ini
    Replace
    Code:
    {PHP_VERSION}
    with your installed PHP version (e.g.,
    Code:
    8.2
    ).
    • Common settings to modify:
      • Code:
        upload_max_filesize
      • Code:
        post_max_size
      • Code:
        memory_limit
  2. Restart the web server to apply changes:
    Code:
    sudo systemctl restart apache2  # For Apache
    sudo systemctl restart nginx    # For Nginx

6. Test PHP
  1. Create a PHP info file:
    Code:
    echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
  2. Access it in your browser at
    Code:
    http://YOUR_SERVER_IP/info.php
    .

7. Enable MySQL in PHP
Ensure PHP's MySQL extension is enabled (usually done automatically). Test it using your PHP scripts or by connecting to MySQL with PHP.

8. Optional: Install PHPMyAdmin
If you'd like a web interface to manage MySQL:
Code:
sudo apt install phpmyadmin -y
Follow the prompts to configure it.

9. Security Best Practices
  • Disable the PHP info file after testing:
    Code:
    sudo rm /var/www/html/info.php
  • Secure MySQL and PHP configurations according to your use case.

Feel free to add more below...

I’m not yelling, I'm Irish.
 Level 99 at procrastination, working on unlocking my "actually productive" skill tree. 
Slow and steady wins the race... unless there’s pizza involved. Then I’m Usain Bolt.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)