How to Install LAMP Apache, PHP, MySQL on Ubuntu 22.04


If you want to set up LAMP Stack Means Linux Apache 2 PHP MySQL and PHPMyAdmin on your Ubuntu system then this tutorial will show you how to install and configure Lamp (Linux, Apache, MySQL, PHP, PHPMyAdmin) on the Ubuntu 22.04 server.

How to Install LAMP Stack Apache, MySQL, PHP, and PHPMyAdmin on Ubuntu 22.04

Here are some steps to install and configure LAMP Linux Apache 2 php MySQL and phpmyadmin on Ubuntu 22.04:

Step 1 – Update System Packages

Whenever some packages have to be set up in Ubuntu, it is necessary to update the Ubuntu first, for this, you can use:

sudo apt-get update
sudo apt-get upgrade

Once we have updated the setup we can start the setup.


Step 2 – Install Apache 2

Install Apache 2 on the Ubuntu 22.04 system, so execute the following command on the command prompt to install Apache on the Ubuntu 22.04 system:

sudo apt-get install apache2

Step 3 – Setup Firewall

Once the Apache installation has been finished, we need to set up Uncomplicated Firewall (UFW) with Apache to allow public access on default web ports for HTTP and HTTPS


sudo ufw app list

We will see all listed applications.

Available applications:
Apache Full
Apache Secure

  • Apache: This profile opens port 80 (normal, unencrypted web traffic)
  • Apache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
  • Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic)
  • OpenSSH: This profile opens port 22 for SSH access.

If we are not going to use SSL we need to enable only the Apache profile.

Then enable Apache full by using the following command; is as follows:

sudo ufw allow 'Apache Full'

With this command, we can view the status of UFW.

sudo ufw status

We will see the output as follows.


Status: active
To Action From
-- ------ ----
Apache Full ALLOW Anywhere
OpenSSH ALLOW Anywhere
Apache Full (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)

Step – 4 Check Apache Installation

Once Apache is installed and the firewall configuration has been finished, we can check the Apache version using the following command: is as follows:

sudo apachectl -v

Server version: Apache/2.4.52 (Ubuntu)
Server built:   2022-03-25T00:35:40

Every process in Apache is managed with the systemctl command. Check the status of Apache with the following command.

sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-29 00:34:49 UTC; 2min 52s ago
   Main PID: 12782 (apache2)
      Tasks: 55 (limit: 1151)
     Memory: 5.1M
        CPU: 52ms
     CGroup: /system.slice/apache2.service
             ├─12782 /usr/sbin/apache2 -k start
             ├─12784 /usr/sbin/apache2 -k start
             └─12785 /usr/sbin/apache2 -k start

Step 5 – Install MySQL

Install and configure MySQL on Ubuntu 22.04 by using the following commands: is as follows:


sudo apt-get install mysql-server

Once the installation is completed. We can verify that the MySQL server status is running, type:

sudo service mysql status

The output should show that the service is enabled and running:

● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-29 00:38:45 UTC; 11s ago
    Process: 13836 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, statu>
   Main PID: 13844 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 1151)
     Memory: 351.4M
        CPU: 1.043s
     CGroup: /system.slice/mysql.service
             └─13844 /usr/sbin/mysqld

To check MySQL version using the following command:


sudo mysql -V
mysql  Ver 8.0.28-0ubuntu4 for Linux on x86_64 ((Ubuntu))

Step 6 – Secure MySQL

MySQL installation comes with a script name mysql_secure_installation that allows us to easily improve the MySQL server security.

sudo mysql_secure_installation

Will be asked to configure the VALIDATE PASSWORD PLUGIN which is used to test the strength of the MySQL users passwords and improve the security.

Press y if we want to set up the validate password plugin or any other key to move to the next step.


There are three levels of password validation policy, low, medium, and strong. Enter 2 for strong password validation.

On the next prompt, will be asked to set a password for the MySQL root user.

If we set up the validate password plugin, the script will show us the strength of we new password. Type y to confirm the password.

Next, will be asked to remove the anonymous user, restrict root user access to the local machine, remove the test database, and reload privilege tables. we should answer y to all questions.

Step 7 – Install PHP

Install PHP using the following command; is as follow:

sudo apt-get install php8.1-fpm php8.1 libapache2-mod-php8.1 php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-intl php8.1-bcmath unzip -y

Once the PHP installed has been completed, we can use the following command to check the version of the installed PHP:

php -v
PHP 8.1.5 (cli) (built: Apr  7 2022 17:46:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies

Step 8 – Configure PHP

To configure PHP by changing some values in php.ini file.


So, open the php.ini file by executing the following command on command prompt:

sudo nano /etc/php/8.1/apache2/php.ini

Hit F6 for search inside the editor and update the following values for better performance.

upload_max_filesize = 32M 
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000

Once we have modified PHP settings, we need to restart Apache for the changes to take effect.

Step 9 – Configure Apache

Disable default Apache configuration.

sudo a2dissite 000-default

Create website directories.


sudo mkdir -p /var/www/html/domainname/public

Set up correct permissions.

sudo chmod -R 755 /var/www/html/domainname
sudo chown -R www-data:www-data /var/www/html/domainname

Create a new virtual host configuration.

sudo nano /etc/apache2/sites-available/domainname.conf

Paste the following configurations in the new file:

<VirtualHost *:80>
     ServerAdmin [email protected]

     DocumentRoot /var/www/html/domainname/public

     <Directory /var/www/html/domainname/public>
         Options Indexes FollowSymLinks
         AllowOverride All
         Require all granted

     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 

Enable the new configuration.

sudo a2ensite domainname.conf

Step 10 – Install PhpMyAdmin

Use the following command to Install PHPMyAdmin:

sudo apt-get install phpmyadmin

Configuration phpmyadmin for Apache.

sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf

Enable the configuration.

sudo a2enconf phpmyadmin.conf

Then execute the following command on the command prompt to restart Apache web server:

sudo service apache2 restart

Now we have installed PHPMyAdmin, this can be accessible with this route

Here is the video tutorial for install apache php mysql ubuntu 22.04:


Through this tutorial, we have learned how to install LAMP stack Ubuntu 22.04. Also learned to install and configure PhpMyAdmin and secure installation.


Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.


Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00