LAMP is an acronym for Linux, Apache, MySQL (or MariaDB), and PHP. It is a popular open-source web server stack used for developing and deploying dynamic websites and applications. This article will guide you through the process of installing the LAMP stack on an Ubuntu server.
1. Prerequisites
Before you begin, ensure you have the following:
- A server running Ubuntu (18.04 or later).
- Sudo privileges on the server.
- A terminal or SSH access to your server.
2. Update Your System
Start by updating your package index to ensure you have the latest information on available packages:
sudo apt update sudo apt upgrade -y
3. Install Apache
Step 1: Install Apache
To install the Apache web server, run the following command:
sudo apt install apache2 -y
Step 2: Start and Enable Apache
After installation, start the Apache service and enable it to run on boot:
sudo systemctl start apache2
sudo systemctl enable apache2
Step 3: Verify Apache Installation
To verify that Apache is running, open your web browser and navigate to your server’s IP address:
You should see the default Apache welcome page.
4. Install MySQL
Step 1: Install MySQL
To install MySQL, run the following command:
sudo apt install mysql-server -y
Step 2: Secure MySQL Installation
After installation, run the security script to improve MySQL security:
sudo mysql_secure_installation
Follow the prompts to set a root password and configure other security options.
Step 3: Verify MySQL Installation
Log in to MySQL to verify the installation:
sudo mysql -u root -p
Enter the root password you set during the secure installation process.
5. Install PHP
Step 1: Install PHP and Required Extensions
To install PHP and some common extensions, run the following command:
sudo apt install php libapache2-mod-php php-mysql -y
Step 2: Restart Apache
After installing PHP, restart the Apache server to enable the PHP module:
sudo systemctl restart apache2
Step 3: Verify PHP Installation
To verify that PHP is installed and working, create a PHP info file:
- Create a new file in the web root directory:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
- Open your web browser and navigate to:
You should see a page displaying PHP information.
6. Clean Up
After verifying the installation, it’s a good idea to remove the PHP info file for security reasons:
sudo rm /var/www/html/info.php
7. Conclusion
You have successfully installed the LAMP stack on your Ubuntu server. With Linux, Apache, MySQL, and PHP set up, you can now develop and deploy dynamic web applications. Regularly update your software stack to ensure optimal performance and security.