Follow Us:
Linux /

Install Apache, PHP and mariaDB on Ubuntu Server

Created Date: 2nd January, 2024
Updated Date: 4th January, 2024

This comprehensive guide walks you through installing Apache2 Web Server, PHP, and MariaDB on a Ubuntu system. Each step is crucial, so follow them carefully for a successful setup.

Part 1: Install Apache2 Web Server

1- We will update package list:

sudo apt update

2- Install Apache:

sudo apt install apache2

3- Start and Enable Apache2 Service:

sudo systemctl start apache2
sudo systemctl enable apache2

4- Check Apache2 Status:

sudo systemctl status apache2

Part 2 Install PHP

First, we need to add a repository that has PHP, as it might not be available in the default Ubuntu repositories.

1- We will update package list:

sudo apt update

2- Install software-properties-common:

sudo apt install software-properties-common

3- Add the PHP repository:

sudo add-apt-repository ppa:ondrej/php
sudo apt update

4- Now we will install the PHP and its extenstion, in this post we will install 8.1 , if you want to install another version you can change the number (8.1)

sudo apt install php8.1
sudo apt install php8.1-cli
sudo apt install php8.1-fpm
sudo apt install php8.1-mbstring
sudo apt install php8.1-xml
sudo apt install php8.1-mysql
sudo apt install php8.1-curl
sudo apt install php8.1-zip
sudo apt install php8.1-gd
sudo apt install php8.1-bcmath

You may need additional extensions based on your specific needs.

Now you have successfully installed php, you can check through the command below:

php -v

Part 3 Install mariaDB:

1- Import the MariaDB repository key:

sudo apt-key adv --fetch-keys ''

2- Add the MariaDB repository:

Replace [version] with the desired version (e.g., 10.4 or 10.6).

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el][version]/ubuntu focal main'

3- Update your package list:

sudo apt update

4- Install MariaDB:

sudo apt install mariadb-server

5- Secure your MariaDB installation:

sudo mysql_secure_installation

Now you have successfully installed MariaDB, you can check through the command below:

mariadb -V

Share the post: