How to Install a LAMP Stack on Ubuntu 20.04 (With SSH Access)

By Virgil on April 23, 2025 | howtos


โœ… Step 1: Connect to Your Server via SSH

To begin, you’ll need to SSH into your Ubuntu 20.04 server. From your local terminal:

 
ssh username@your_server_ip

Replace username with your actual username (often root on fresh VPS setups) and your_server_ip with your server's IP address. You can find this information in portal.cloudnium.net under your VPS services section.

Example:

ssh root@192.168.1.100 

If it’s your first time connecting, you’ll be prompted to confirm the authenticity of the server. Type yes and hit Enter.


๐Ÿ”ฅ Step 2: Update Your System

Before we install anything, make sure your system is up-to-date:

 
sudo apt update && sudo apt upgrade -y

This ensures you're installing the latest versions and security patches.


๐ŸŒ Step 3: Install Apache

Apache is the web server that will serve your site to users.

 
sudo apt install apache2 -y

Once installed, enable it to start at boot and then start it:

 
sudo systemctl enable apache2 sudo systemctl start apache2

Test it! Go to your browser and visit:

 
http://your_server_ip

You should see the Apache default page — success!


๐Ÿ’พ Step 4: Install MySQL

Next up: the database. Install MySQL with:

 
sudo apt install mysql-server -y

Secure the installation:

 
sudo mysql_secure_installation

During the setup:

  • You can set a root password.

  • Remove anonymous users.

  • Disallow root remote login.

  • Remove test databases.

  • Reload privileges.

For extra security, consider logging into MySQL to create a dedicated database and user later.


๐Ÿง  Step 5: Install PHP

Now for the dynamic part — PHP! Install PHP along with the Apache module and MySQL support:

 
sudo apt install php libapache2-mod-php php-mysql -y

You can test PHP is working by creating a test file:

 
sudo nano /var/www/html/info.php

Add the following line:

 
<?php phpinfo(); ?>

Save and exit (CTRL + O Enter Finally CTRL + X).

Now visit:

 
http://your_server_ip/info.php

You should see the PHP info page! ๐ŸŽ‰


โš™๏ธ Optional: Install Additional PHP Modules

Depending on your app, you might need more PHP modules:

 
sudo apt install php-cli php-curl php-zip php-gd php-mbstring php-xml php-bcmath -y

๐Ÿงน Step 6: Cleanup and Secure

Once everything is working:

  • Remove the test PHP file for security:

 
sudo rm /var/www/html/info.php
  • Restart Apache:

 
sudo systemctl restart apache2

๐Ÿ“ฆ Bonus: Create a MySQL Database and User

To create a new database and user:

 
sudo mysql -u root -p

Inside the MySQL shell:

 
CREATE DATABASE myapp; CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword'; GRANT ALL PRIVILEGES ON myapp.* TO 'myuser'@'localhost'; FLUSH PRIVILEGES; EXIT;

๐Ÿ You Did It!

You now have a fully functional LAMP stack running on Ubuntu 20.04! Your server is ready to host WordPress, Laravel, or any PHP-based site or application.


Share this article: Twitter Facebook LinkedIn