complete one-by-one command flow** for starting MySQL and Apache, then creating and running a PHP file step-by-step:
sudo systemctl start mysql
Check if it's running:
sudo systemctl status mysql
sudo systemctl start apache2
Check if it's running:
sudo systemctl status apache2
cd /var/www/html
(If this folder does not exist, create it:
sudo mkdir -p /var/www/html sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html)
Create a test file:
sudo nano test.php
Paste this simple PHP code:
<?php
echo "✅ PHP is working!";
?>
- Save:
Ctrl + O
+ Enter - Exit:
Ctrl + X
Use your server IP to open it:
http://your-server-ip/test.php
📌 Replace your-server-ip
with your VPS/public IP.
php test.php
Then create another file:
sudo nano db_test.php
Paste this code (change password/db name):
<?php
echo "▶ Starting DB connection test...<br>";
$conn = new mysqli("localhost", "root", "your_password", "your_db");
if ($conn->connect_error) {
die("❌ Connection failed: " . $conn->connect_error);
}
echo "✅ Connected to MySQL!";
?>
Save and then open in browser:
http://your-server-ip/db_test.php
Let me know if you want this to insert or fetch data from table, I’ll give that code too.