Install LAMP Stack on Ubuntu 22.04

|
Last Updated:
|
|

Welcome to our guide on how to install LAMP Stack on Ubuntu 22.04. If you are looking at building some web application, LAMP stack is the first thing you might need. As you already know, LAMP is a group of opensource web development softwares; Linux OS, Apache http serverMariaDB/MySQL relational database management systems and PHP web scripting language.

Install LAMP Stack on Ubuntu 22.04

As per the acronym, Linux system is the first component of LAMP stack. And since you are here, Ubuntu 22.04 is our first component of LAMP stack.

Run System Update

To begin with, update and upgrade your system packages;

apt update
apt upgrade

Install Apache Web Server on Ubuntu 22.04

Apache web server can be installed by running the command below;

apt install apache2

Once the installation is done, start and enable Apache to run on system boot.

systemctl enable --now apache2

You can check the status of the service;

systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-04-30 17:59:47 EAT; 1min 31s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 18168 (apache2)
      Tasks: 55 (limit: 4579)
     Memory: 5.4M
        CPU: 73ms
     CGroup: /system.slice/apache2.service
             ├─18168 /usr/sbin/apache2 -k start
             ├─18170 /usr/sbin/apache2 -k start
             └─18171 /usr/sbin/apache2 -k start

Apr 30 17:59:47 jellyfish systemd[1]: Starting The Apache HTTP Server...
Apr 30 17:59:47 jellyfish apachectl[18167]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' >
Apr 30 17:59:47 jellyfish systemd[1]: Started The Apache HTTP Server.

If you going to be accessing Apache from your external system, then you need to allow it on firewall, that is, in case UFW is running;

ufw allow Apache

or simply run ufw allow 80/tcp to allow HTTP traffic or ufw allow 443/tcp for HTTPS traffic.

Verify external access to Apache by navigating to your browser and entering the server IP address or hostname as http://Server.IP_or_hostname. You should land on Apache HTTP server test page.

Install LAMP Stack on Ubuntu 22.04

Great. Proceed to install MySQL/MariaDB on Ubuntu 22.04.

Install MySQL Database Server on Ubuntu 22.04

In this demo, we are running LAMP stack on Ubuntu 22.04 with MySQL 8. Therefore, follow the link below to install MySQL 8 on Ubuntu 22.04;

Install MySQL 8 on Ubuntu 22.04

Install PHP on Ubuntu 22.04

PHP is the last but not least component in LAMP Stack. In this demo, we are going to use PHP 8 for our LAMP stack.

Install PHP 8 on Ubuntu 22.04

If you want to install other PHP versions on Ubuntu 22.04, follow the link below;

Install PHP 7.1/7.2/7.3/7.4 on Ubuntu 22.04

Installing PHP Modules on Ubuntu 22.04

Installation of PHP installs with itself other PHP modules such as, libapache2-mod-php, php-common, php-cli, php-common, php-json, php-opcache, php-readline

Install MySQL module for PHP and any other module you may need for your web application.

apt install php-mysql

Current installed version of PHP;

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

Loaded modules;

php -m
[PHP Modules]
calendar
Core
ctype
date
exif
FFI
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
Zend OPcache
zlib

[Zend Modules]
Zend OPcache

Testing PHP Processing on Ubuntu 22.04

You can test PHP to confirm that is working as required as well check the version and installed modules using the simple PHP info script.

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Restart Apache

systemctl restart apache2

Next, navigate to the browser and enter the address, http://<server-IP>/info.php

Install LAMP Stack on Ubuntu 22.04

If you see this page, then PHP installation is working pretty well.

That marks the end of our guide on how to Install LAMP Stack.

Install PHP 7.1/7.2/7.3/7.4 on Debian 11

Install PHP 8 on Ubuntu 22.04

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment