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 server, MariaDB/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;
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: Starting The Apache HTTP Server... Apr 30 17:59:47 jellyfish apachectl: 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: 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.
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 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.
If you want to install other PHP versions on Ubuntu 22.04, follow the link below;
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 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
[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
systemctl restart apache2
Next, navigate to the browser and enter the address, http://<server-IP>/info.php
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 on Ubuntu 22.04.