Installing the LAMP Stack on Ubuntu VPS

Installing the LAMP Stack on Ubuntu VPS

Installing the LAMP Stack on Ubuntu VPS

Installing the LAMP Stack on Ubuntu VPS
Prerequisites:
Ubuntu installed on a Virtual Private Server. Version 18.04 and above.
SSH access to your server.

Step 1: Log in to Your VPS
Open your terminal and log in to your VPS:

ssh username@your_server_ip

Instead of username, use your username, while for your_server_ip, use that of your VPS.

Step 2: Upgrade Your System
First of all, you need to upgrade your package index:

sudo apt update && sudo apt upgrade -y

Step 3: Install Apache – Installing the LAMP Stack on Ubuntu VPS
You can install Apache using the next command in your terminal:

sudo apt install apache2 -y

After installation, enable and start the Apache service:

sudo systemctl enable apache2
sudo systemctl start apache2

Apache is now running. You can verify this by opening http://your_server_ip in your web browser. You will find there the Apache2 Ubuntu Default Page .

Step 4: Install MySQL
Next, you can install MySQL:

sudo apt install mysql-server -y

Then, execute the following command to secure your MySQL installation:

sudo mysql_secure_installation

You will be asked to set a password for the root user, followed by securing your database. Reply appropriately to each prompt.

Step 5: Install PHP
Install PHP and its modules:

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

Step 6: Test PHP Processing
Ensure now that PHP works fine with Apache. Create a test PHP file:

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

Add the following:

<?php
phpinfo();
?>

Save and exit.
Now, open http://your_server_ip/info.php in your web browser. You will see a PHP info page.

Step 7: Install Additional PHP Modules (Optional)
You can install other PHP modules depending on your needs. Here is an example to install the gd library to handle images:

sudo apt install php-gd -y

Step 8: Restart Apache
Now, restart Apache to apply all the changes:

sudo systemctl restart apache2

Step 9: Remove the Test Page

Do not forget for security reasons to remove the PHP info page:

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

Conclusion
Congratulations! You just installed a LAMP stack on your Ubuntu VPS.
Now you can serve dynamic web applications that would run PHP and databases administered by MySQL. You might want to use a framework like WordPress or Laravel for more complicated apps if you wish. Enjoy!

Internal Link