Install Apache, MariaDB, PHP on Ubuntu 24.04

This is for Ubuntu 24.04 which we walked you through setting up earlier in the tutorial.

Ubuntu is the operating system. It’s the “L” in LAMP. LAMP stands for Linux, Apache, MariaDB (or MySQL), and PHP.

In this section, we’re installing the rest of the LAMP stack: Apache, MariaDB, and PHP. Apache is the web server, MariaDB is the database, and PHP is the server-side scripting language. These are the components needed to run WordPress.

Install Apache

This picks up at the end of the previous tutorial, so you should already be logged in to your server. Run the following commands either in Git Bash or your terminal.

sudo apt update
sudo apt install apache2 apache2-utils

Check that it’s running:

sudo systemctl status apache2

Make sure it starts after reboot:

sudo systemctl enable apache2

Go to your server’s ip address in the browser, you should see a “Apache2 Default Page”.

Install MariaDB

sudo apt install mariadb-server

Check that it’s running:

sudo systemctl status mariadb

Make sure it starts after reboot:

sudo systemctl enable mariadb

Install PHP 8.1 on Ubuntu 24.04 LTS

  1. Update your package lists:

    sudo apt update
    
  2. Ensure you have software-properties-common installed:

    sudo apt install software-properties-common
    
  3. Add the ondrej/php PPA (Personal Package Archive) which contains the latest PHP versions:

    sudo add-apt-repository ppa:ondrej/php
    
    sudo apt update
    
  4. Install the PHP modules

    sudo apt install php8.1-{fpm,gd,mbstring,mysql,xml,xmlrpc,opcache,cli,zip,soap,intl,bcmath,curl,imagick,ssh2}
    

Make sure it’s active and running:

sudo systemctl status php8.1-fpm

Enable restart after reboot:

sudo systemctl enable php8.1-fpm

Run this:

sudo a2enmod proxy_fcgi setenvif

Ignore the “systemctl restart apache2” for now.

sudo a2enconf php8.1-fpm
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event

This time, restart instead of reload:

sudo systemctl restart apache2

Check that it’s active and running:

sudo systemctl status apache2

Coming up next

In the next tutorial, we’ll harden and secure Apache, MariaDB, and PHP. Then we’ll install WordPress.

See more: ,

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]