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:
2. Install MySQL
3. Install PHP
4. Install a Web Server (if not already installed)
For Apache:
For Nginx:
5. Configure PHP
6. Test 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:
Follow the prompts to configure it.
9. Security Best Practices
Feel free to add more below...
1. Update Your System
Ensure your system packages are up-to-date:
Code:
sudo apt update && sudo apt upgrade -y
2. Install MySQL
- Install MySQL server:
Code:sudo apt install mysql-server -y
- 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.
- You'll be prompted to set a root password, remove test databases, disallow remote root login, etc. Follow the prompts to harden the installation.
- Verify MySQL is running:
Code:sudo systemctl status mysql
3. Install PHP
- Install PHP and common extensions:
ReplaceCode:sudo apt install php libapache2-mod-php php-mysql -y
withCode:libapache2-mod-php
if you're using Nginx instead of Apache.Code:php-fpm
- Verify PHP installation:
Code:php -v
4. Install a Web Server (if not already installed)
For Apache:
Code:
sudo apt install apache2 -y
Code:
sudo apt install nginx -y
5. Configure PHP
- Adjust PHP settings if needed: Edit the PHP configuration file:
ReplaceCode:sudo nano /etc/php/{PHP_VERSION}/apache2/php.ini
with your installed PHP version (e.g.,Code:{PHP_VERSION}
).Code:8.2
- Common settings to modify:
- Code:
upload_max_filesize
- Code:
post_max_size
- Code:
memory_limit
- Common settings to modify:
- Restart the web server to apply changes:
Code:sudo systemctl restart apache2 # For Apache
sudo systemctl restart nginx # For Nginx
6. Test PHP
- Create a PHP info file:
Code:echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
- 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
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.