The LAMP stack is a popular set of open-source software used to host web applications. It stands for Linux, Apache, MySQL, and PHP. In this tutorial, you will learn how to install the LAMP stack on Ubuntu 22.04.
What You Can Do with a LAMP Server:
- Host Websites: Serve dynamic content using Apache and PHP.
- Manage Databases: Store and retrieve information using MySQL.
- Run Web Applications: Deploy and manage web applications built with PHP.
Components of the LAMP Stack:
- Apache: Web server to handle HTTP requests.
- MySQL: Database server to manage data.
- PHP: Server-side scripting language for dynamic content.
Step 1: Create a Cloud Instance
Before installing the LAMP stack, you need to create a cloud instance to host it. Here’s how to set up your instance:
Step 1.1: Click on “Create”
- From your hosting provider’s dashboard, click on the Create button and select Instances.
Step 1.2: Choose a Location
- Select the data center closest to your target audience (e.g., New York, London, Tokyo).
Step 1.3: Choose an Instance Plan and OS
- Choose an instance plan based on your needs (e.g., Standard, CPU-Optimized).
- Select Ubuntu 22.04 as the operating system.
Step 1.4: Create the Instance
- Fill in the necessary details, such as authentication (SSH keys or password), and choose a hostname. Click Create Instance.
Step 1.5: Find Your IP Address
- 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.
Step 2: Install Apache
Install Apache, the web server software, and configure it to start at boot:
apt-get install apache2 -y
Start and enable Apache:
systemctl start apache2
systemctl enable apache2
Check Apache’s status to ensure it’s running properly:
systemctl status apache2
Verify the Apache version:
apache2ctl -version
Step 3: Check Apache Installation via Web Browser
After Apache is installed, you can verify that it’s working correctly by accessing the default Apache web page.
- Open your web browser.
- In the address bar, type
http://<your-server-ip>
, replacing<your-server-ip>
with the actual public IP address of your server. - If Apache is working correctly, you should see the default Apache welcome page that says “Apache2 Ubuntu Default Page”.
If you see this page, Apache has been successfully installed and is running properly.
Step 4: Install PHP 8.1
To enable dynamic content, you need PHP. Install PHP 8.1 and the necessary modules for Apache:
apt-get install php8.1 libapache2-mod-php8.1 php8.1-mysql php8.1-gd php8.1-curl php8.1-xml -y
Check the PHP version to ensure the installation was successful:
php --version
Step 5: Install MySQL
Install MySQL, the database management system:
apt-get install mysql-server -y
Start and enable MySQL:
systemctl start mysql
systemctl enable mysql
Check the status of MySQL to ensure it’s running:
systemctl status mysql
Verify the MySQL version:
mysql --version
Step 6: Secure MySQL
To secure your MySQL installation and set the root password, run the following command:
mysql_secure_installation
Follow the on-screen prompts to complete the MySQL secure installation process.
Step 7: Test PHP with Apache
To test if PHP is working correctly with Apache, create a simple info.php
file in the /var/www/html/
directory:
nano /var/www/html/info.php
Add the following code to the file:
<?php
phpinfo();
?>
Save the file and exit the editor.
Step 8: Verify LAMP Installation
Open a web browser and navigate to http://<your-server-ip>/info.php
. You should see a page displaying PHP information, confirming that Apache, PHP, and MySQL are working together correctly.
You have successfully installed the LAMP stack on Ubuntu 22.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.
By utilizing Shape.Host’s Linux SSD VPS, you can take full advantage of the LAMP stack’s potential with enhanced performance and scalability. Explore Shape.Host’s VPS offerings to find the perfect solution for your project.