The LAMP stack is a popular combination of open-source software used for web development. LAMP stands for Linux, Apache, MySQL, and PHP. In this tutorial, we will install and set up the LAMP server stack on Ubuntu 24.04.

Step 1: Create an Instance

  • Access the Dashboard: Log in to your Shape.Host account and navigate to your Dashboard.
  • Click Create: Click on the “Create” button located in the top-right corner.
  • Select Instances: From the dropdown menu, choose “Instances” to begin creating a new cloud server.
Shape.host Resources dashboard with Create > Instance highlighted.
  • Select Location: Choose a data center location for your instance closest to your target audience for optimal performance.
Shape.host instance form with the data center location selector highlighted.
  • Choose a Plan: Scroll through the available pricing plans. Select a plan based on your project requirements, such as Standard, CPU-Optimized, or Memory-Optimized.
  • Choose an Image: Select Ubuntu 24.04 as the operating system for your instance.
Shape.host instance form with the operating system image selector highlighted.
  • Authentication and Finalize: Choose your authentication method, either via SSH keys or password. Once done, click Create Instance to launch your server.
Shape.host instance form with the Create Instance button highlighted.

Once the instance is created, go to the Resources section to find the public IP address of your instance. You’ll need this to connect to the instance remotely.

Shape.host Resources dashboard with the server IP address highlighted.

Step 2: Update and Upgrade System Packages

Start by updating the package list and upgrading the existing packages to the latest versions:

apt update && apt upgrade -y
Terminal showing apt update and apt upgrade commands.

Step 3: Install Apache Web Server

Apache is the web server that serves web pages to users. Install Apache using the following command:

apt-get install apache2 -y
Terminal showing APT package management commands and output.

After the installation, start the Apache service and enable it to start automatically on system boot:

systemctl start apache2
systemctl enable apache2
Terminal showing systemd service management commands or output.

Verify the status of Apache to ensure it’s running:

systemctl status apache2
Terminal showing systemd service management commands or output.

Check the installed version of Apache:

apache2ctl -version
Terminal displaying the Apache server version.

Step 4: Install MySQL Database Server

Next, install MySQL, which is used to store and manage databases:

apt install mysql-server -y
Terminal showing APT package management commands and output.

Secure the MySQL installation by running the following command:

mysql_secure_installation

This command will prompt you to set a root password, remove anonymous users, disallow root login remotely, and remove the test database.

Terminal showing MariaDB/MySQL database security configuration prompts.
Terminal showing mysql commands or output during Install MySQL Database Server.

Step 5: Add PHP Repository and Install PHP

To get the latest version of PHP, add the Ondrej PHP repository:

add-apt-repository ppa:ondrej/php
Terminal showing APT package management commands and output.

Update the package list again:

apt update

Now install PHP 8.3 along with commonly used extensions:

apt install php8.3 libapache2-mod-php8.3 php8.3-mysql php8.3-gd php8.3-curl php8.3-xml -y
Terminal showing APT package management commands and output.

Restart Apache to apply the changes:

systemctl restart apache2

Check the installed version of PHP:

php --version
Terminal showing systemd service management commands or output.

Step 6: Start and Enable MySQL Service

Make sure the MySQL service is started and enabled to start automatically on boot:

systemctl start mysql
systemctl enable mysql
Terminal showing systemd service management commands or output.

Step 7: Verify PHP Installation

To verify that PHP is working correctly with Apache, create a test PHP file in the web root directory:

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Now, open your web browser and navigate to http://your-server-ip/info.php. You should see the PHP information page, which confirms that PHP is correctly installed and configured.

Note: For security purposes, it’s recommended to remove the info.php file after verification:

rm /var/www/html/info.php
PHP information page displaying runtime and module configuration.

You have successfully installed the LAMP stack on Ubuntu 24.04. Your server is now ready to host PHP applications, connect to a MySQL database, and serve web pages using Apache.

To host websites and applications efficiently, Shape.Host offers Linux SSD VPS services. Shape.Host’s SSD-powered VPS ensures fast and reliable performance, perfect for hosting LAMP-based applications.