How to Install LAMP Stack with MariaDB on Ubuntu 24.10
A LAMP stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MySQL or MariaDB database, and dynamic content is processed by PHP.
Update the System
First, check for any pending system upgrades.
apt update
apt upgrade
Install Apache
Command to install Apache along with its utilities.
apt install -y apache2 apache2-utils
Next, check the Status of Apache.
systemctl status apache2
Output:
root@servercom:~# systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running) since Mon 2024-10-28 16:29:19 UTC; 16s ago
Invocation: 0132d32c1bc642dc988b1317ac8f13a7
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 1563 (apache2)
Tasks: 55 (limit: 3995)
Memory: 5.4M (peak: 5.8M)
CPU: 55ms
CGroup: /system.slice/apache2.service
├─1563 /usr/sbin/apache2 -k start
├─1565 /usr/sbin/apache2 -k start
└─1566 /usr/sbin/apache2 -k start
Oct 28 16:29:19 servercom systemd[1]: Starting apache2.service - The Apache HTTP Server...
Oct 28 16:29:19 servercom apachectl[1562]: AH00558: apache2: Could not reliably determine the server's >
Oct 28 16:29:19 servercom systemd[1]: Started apache2.service - The Apache HTTP Server.
If Apache is not active can start using the following command.
systemctl start apache2
Use the following command to auto start Apache at boot time.
systemctl enable apache2
You can confirm the Apache2 version with the below command,
apache2 -v
Output:
root@servercom:~# apache2 -v
Server version: Apache/2.4.62 (Ubuntu)
Server built: 2024-08-15T07:32:14
Enable Firewall
We will open the HTTP, HTTPS ports in the firewall, so we can access the page served by the Apache web server.
Allow the HTTP,HTTPS ports by running the below command,
ufw allow http
ufw allow https
Output:
root@servercom:~# ufw allow http
Rules updated
Rules updated (v6)
root@servercom:~# ufw allow https
Rules updated
Rules updated (v6)
And to verify if it's working, open the server's IP address in your browser. You should be able to view the Apache default page.
http://ip-address
NOTE: Replace with your Server IP address.
Install MariaDB Server
Install MariaDB server, run the below command:
apt install mariadb-server mariadb-client mariadb-client-compat -y
Once the installation complete, check the status of MariaDB.
systemctl status mariadb
Output:
root@servercom:~# systemctl status mariadb
● mariadb.service - MariaDB 11.4.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: enabled)
Active: active (running) since Mon 2024-10-28 16:32:33 UTC; 13s ago
Invocation: 1f36786ec5f54260b76555434fe57704
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 2694 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 14 (limit: 26370)
Memory: 84.5M (peak: 88.6M)
CPU: 1.875s
CGroup: /system.slice/mariadb.service
└─2694 /usr/sbin/mariadbd
Start MariaDB if it is not active using below command,
systemctl start mariadb
Use the following command to auto start MariaDB at boot time.
systemctl enable mariadb
Next, MariaDB database security.
NOTE: In this step, you will be prompted with several questions.
mysql_secure_installation
Output:
root@servercom:~# mysql_secure_installation
/usr/bin/mysql_secure_installation: Deprecated program name. It will be removed in a future release, use 'mariadb-secure-installation' instead
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]
y ... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Login to the MariaDB using below command,
mariadb -u root -p
To exit from MariaDB.
exit
Check MariaDB Version,
mariadb --version
Output:
root@servercom:~# mariadb --version
mariadb from 11.4.3-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper
Install PHP
PHP 8.3 is the default version of PHP that would be installed on Ubuntu 24.10.
Install PHP and Required Extensions using below command,
apt install php libapache2-mod-php php-mysql php-common php-cli php-common php-json php-opcache php-readline php-mbstring php-gd php-dom php-zip php-curl
Enable the Apache PHP module and restart the Apache Web server.
a2enmod php8.3
Output:
root@servercom:~# a2enmod php8.3
Considering dependency mpm_prefork for php8.3:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php8.3:
Module php8.3 already enabled
systemctl restart apache2
To check PHP Version.
php --version
Output:
root@servercom:~# php --version
PHP 8.3.11 (cli) (built: Sep 30 2024 12:07:44) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.11, Copyright (c) Zend Technologies
with Zend OPcache v8.3.11, Copyright (c), by Zend Technologies
Test PHP scripts we need to add the info.php
file in the document.
nano /var/www/html/info.php
Add the following to the file.
<?php phpinfo(); ?>
To verify enter the following link in a web browser.
NOTE: Replace with your server IP address below.
http://ip-address/info.php
Once it's verified, remove the file so it will not be of any security risk,
rm /var/www/html/info.php
Run PHP-FPM with Apache [Optional]
FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for heavy-loaded sites.
NOTE: This is an optional step, PHP 8.3 is used to run the PHP code but if you want to run PHP code with PHP-FPM follow the below steps.
Next, Install PHP-FPM.
apt install php8.3-fpm
Enable proxy_fcgi and setenvif module.
a2enmod proxy_fcgi setenvif
Output:
root@servercom:~# a2enmod proxy_fcgi setenvif
Considering dependency proxy for proxy_fcgi:
Enabling module proxy.
Enabling module proxy_fcgi.
Module setenvif already enabled
To activate the new configuration, you need to run:
systemctl restart apache2
Now enable the Apache php8.3-fpm file.
a2enconf php8.3-fpm
Output:
root@servercom:~# a2enconf php8.3-fpm
Enabling conf php8.3-fpm.
To activate the new configuration, you need to run:
systemctl reload apache2
Restart the Apache.
systemctl restart apache2
Enable php-fpm.
systemctl enable php8.3-fpm
Follow below command to start php-fpm.
systemctl start php8.3-fpm
To check the status of php-fpm.
systemctl status php8.3-fpm
Output:
root@servercom:~# systemctl status php8.3-fpm
● php8.3-fpm.service - The PHP 8.3 FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php8.3-fpm.service; enabled; preset: enabled)
Active: active (running) since Mon 2024-10-28 16:53:30 UTC; 1min 58s ago
Invocation: e4a69fc8e27b447ba680917969e0b001
Docs: man:php-fpm8.3(8)
Main PID: 15872 (php-fpm8.3)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0.00req/sec"
Tasks: 3 (limit: 3995)
Memory: 10.2M (peak: 12M)
CPU: 84ms
CGroup: /system.slice/php8.3-fpm.service
├─15872 "php-fpm: master process (/etc/php/8.3/fpm/php-fpm.conf)"
├─15873 "php-fpm: pool www"
└─15874 "php-fpm: pool www"
Now you have successfully installed the LAMP stack (Apache, MariaDB, and PHP8.3) on 24.10.
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS