Install LAMP Stack on Ubuntu 22.04
Contents
A strong foundation is necessary to build a dynamic web environment, and developers all around the world often choose the install LAMP stack for this reason. This stack, which consists of Linux, Apache, MySQL, and PHP, gives you all you need to host and create dynamic web applications. We’ll walk you through installing and install LAMP stack on Ubuntu 22.04 in this step-by-step tutorial, making sure you have a strong setup for your web development activities.
Prerequisites to Install LAMP
For install LAMP stack you will need an Ubuntu 22.04 server to install LAMP with a non-root sudo enabled user account and a basic firewall in order to finish this guide.
Step 1 — Installing Apache and Updating the Firewall
One of the most widely used web servers worldwide is Apache. It is an excellent option for hosting a website since it is widely used, has a strong user community, and has been there for a significant portion of the internet’s existence.
Begin by updating the package index and installing the Apache web server:
sudo apt update
sudo apt install apache2
After the installation is complete, you must modify your firewall configuration to permit HTTP traffic. Uncomplicated Firewall (UFW) is the name of Ubuntu’s default firewall setting tool. You can use it with various application profiles. Use this command to get a list of every UFW application profile that is currently available:
sudo ufw app list
Here is result you will get once, you write command in terminal:
Each of these profiles means what follows:
Apache: Only port 80 (regular, unencrypted web traffic) is open with this profile.
Apache Full: This profile opens port 443 (TLS/SSL encrypted traffic) in addition to port 80 (standard, unencrypted web traffic).
Apache Secure: Only port 443 (TLS/SSL encrypted traffic) is open with this profile.
Since this is a fresh installation of Apache and you do not yet have a TLS/SSL certificate installed to enable for HTTPS traffic on your server, it is advisable to accept only connections on port 80 for the time being.
sudo ufw allow in "Apache"
Verifying changes
sudo ufw status
If your ufw
(Uncomplicated Firewall) status is inactive, it means that the firewall is not actively filtering or blocking any incoming or outgoing connections. This can be fine depending on your security requirements and network setup, but it’s generally recommended to have a firewall configured to protect your system from unauthorized access.
If you want to enable ufw
and configure it to allow traffic for services like Apache, MySQL, or SSH, you can follow these steps:
Enable UFW:
sudo ufw enable
Allow SSH (if you need remote access to your server):
sudo ufw allow ssh
Allow Apache Full (allow HTTP and HTTPS traffic for Apache):
sudo ufw allow in "Apache Full"
Open your browser and type URL in http://127.0.0.1/
Install MySQL:
After your web server is operational, you must install the database system in order to store and manage content for your website. A well-liked database management solution for PHP environments is MySQL.
sudo apt install mysql-server
Secure MySQL Installation:
Run the MySQL security script to improve the security of your MySQL installation.
sudo mysql_secure_installation
Install PHP:
PHP is the programming language that will process dynamic content.
sudo apt install php libapache2-mod-php php-mysql
Test PHP:
Create a test PHP file in Apache’s document root to ensure PHP is working correctly.
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Adjust File Permissions:
Adjust permissions to ensure the web server can access the PHP file.
sudo chown -R www-data:www-data /var/www/html/ sudo chmod -R 755 /var/www/html/
Restart Apache:
After making changes, restart Apache server using systemctl for the changes to take effect.
sudo systemctl restart apache2
To follow above steps we can successfully install LAMP stack. Using Apache as your web server and MySQL as your database system, you have constructed a versatile framework for providing your users with PHP webpages and applications through this approach.