A Beginner’s Guide to Installing LAMP on Ubuntu
Published on: Feb 25, 2023
2 min read.
Every developer has their preferred stack. For me, the front end can change based on the client’s needs, but if no matter what I make, I always need LAMP on a Ubuntu server. LAMP, an acronym for Linux, Apache, MySQL, and PHP, is a popular open-source software stack for developing and hosting web applications. In this guide, I’ll show you how to install the LAMP stack on an Ubuntu system.
The LAMP stack is widely used due to its ease of use, flexibility, and the large community contributing to its updates and security. By the end of this tutorial, you will have a fully functional LAMP stack installed and ready for your next web project. I use it for nearly all web projects because it is fast, flexible, and widely documented.
Let’s get started!
Step 1: Update Your System
Before we start, it’s always a good idea to update the package lists for upgrades and new installations. Open your terminal and run:
sudo apt update
Step 2: Install Apache
Now, let’s install Apache, a widely used open-source web server.
sudo apt install apache2
After the installation, you can verify Apache’s installation by accessing it from your browser. Type in
http://localhost/` orhttp://your_server_ip/` in your browser.
Step 3: Install MySQL
Next, we install MySQL, which will manage and organize your website’s data.
sudo apt install mysql-server
During the installation process, you will be prompted to create a root password. Make sure you choose a strong, secure password.
Step 4: Secure MySQL Installation
This is an optional but highly recommended step. Running the security script can remove some insecure default settings and disable access to your database system.
Step 5: Install PHP
Finally, we’ll install PHP, which is responsible for processing code to display dynamic content. For this, we will be installing the latest, stable version of PHP. Version 8.1. Note: new versions of PHP are constantly being worked on and released by the community, so this will change in the future.
sudo apt -y install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt install php8.1 php8.1-common php8.1-cli php8.1-mbstring php8.1-bz2 php8.1-readline php8.1-intl php8.1-bcmath php8.1-bz2 php8.1-curl php8.1-mysql php8.1-readline php8.1-xml php8.1-zip libapache2-mod-php8.1
After these commands, PHP will be installed, along with some additional modules. Now that PHP is installed, we need to enable PHP with Apache.
sudo a2enmod php8.1
Step 6: Verify PHP Installation
You can verify PHP’s installation by creating a basic PHP info page in your web document root.
echo "<!--?php phpinfo(); ?-->" | sudo tee /var/www/html/info.php
Now navigate to
http://localhost/info.php` orhttp://your_server_ip/info.php` in your web browser. You should see a PHP information page.
And there you have it!
Congratulations, you have successfully installed a LAMP stack on your Ubuntu system. This provides a solid foundation for you to start deploying and running your web applications. With the stack at your fingertips, you can focus on building and optimizing your projects.
Remember, keep your system updated regularly to ensure the smooth running of the server and to protect against any potential vulnerabilities. Happy coding!