Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sejalkailashyadav/009e03ebefbfdee2f9665fc694a4515a to your computer and use it in GitHub Desktop.
Save sejalkailashyadav/009e03ebefbfdee2f9665fc694a4515a to your computer and use it in GitHub Desktop.

complete one-by-one command flow** for starting MySQL and Apache, then creating and running a PHP file step-by-step:


✅ STEP 1: Start MySQL

sudo systemctl start mysql

Check if it's running:

sudo systemctl status mysql

✅ STEP 2: Start Apache

sudo systemctl start apache2

Check if it's running:

sudo systemctl status apache2

✅ STEP 3: Go to Apache Web Directory

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

)


✅ STEP 4: Create a PHP File

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

✅ STEP 5: Open in Browser

Use your server IP to open it:

http://your-server-ip/test.php

📌 Replace your-server-ip with your VPS/public IP.


✅ OPTIONAL: Run PHP from Terminal (CLI)

php test.php

✅ Want to Test DB Connection?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment