‍In this article, we will guide you through the process of installing a LAMP stack with MariaDB on Ubuntu 23.10. A LAMP stack is a collection of open-source software that is commonly used to host dynamic websites and web applications. It consists of the Linux operating system, the Apache web server, the MySQL or MariaDB database, and the PHP programming language.

Prerequisites

Before we begin, make sure you have the following:

  • An Ubuntu 23.10 server
  • SSH access to the server with root privileges

Step 1: Update the System

First, let’s update the system to ensure that we have the latest software packages. Open a terminal and run the following commands:

apt update
apt upgrade -y

This will update the package lists and upgrade any installed packages on your system.

Step 2: Install Apache

Apache is a widely-used web server that will allow us to serve our web content. To install Apache, run the following command:

apt install -y apache2 apache2-utils

Once the installation is complete, you can check the status of Apache by running the following command:

systemctl status apache2

You should see output similar to the following:

● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running) since Fri 2023-10-20 07:00:24 UTC; 49s ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 2734 (apache2)
Tasks: 55 (limit: 2226)
Memory: 4.9M
CPU: 88ms
CGroup: /system.slice/apache2.service
├─2734 /usr/sbin/apache2 -k start
├─2736 /usr/sbin/apache2 -k start
└─2737 /usr/sbin/apache2 -k start

If Apache is not active, you can start it with the following command:

systemctl start apache2

To enable Apache to start automatically at boot time, run the following command:

systemctl enable apache2

You can verify the Apache version by running the following command:

apache2 -v

This will display the Apache version installed on your system.

Step 3: Configure Firewall

Next, we need to configure the firewall to allow incoming HTTP and HTTPS traffic to our server. Run the following commands to allow these ports:

ufw allow http
ufw allow https

To verify if the firewall is working correctly, open your browser and enter your server’s IP address. You should see the Apache default page.

Step 4: Install MariaDB

MariaDB is a relational database management system that will store our site’s data. To install MariaDB, run the following command:

apt install mariadb-server mariadb-client

Once the installation is complete, you can check the status of MariaDB by running the following command:

systemctl status mariadb

If MariaDB is not active, you can start it with the following command:

systemctl start mariadb

To enable MariaDB to start automatically at boot time, run the following command:

systemctl enable mariadb

Next, we need to secure our MariaDB installation. Run the following command and follow the prompts:

mysql_secure_installation

This script will guide you through the process of securing your MariaDB installation by setting a root password and removing some insecure default settings. Follow the prompts and answer the questions accordingly.

Step 5: Install PHP

PHP is a popular programming language that will allow us to process dynamic content on our website. To install PHP along with some required extensions, run the following 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

Once the installation is complete, restart the Apache web server for the changes to take effect:

systemctl restart apache2

To check the PHP version installed on your system, run the following command:

php --version

This will display the PHP version installed on your system.

Step 6: Test PHP

To test if PHP is working correctly, we will create a simple PHP file and access it through our web browser. Open a text editor and create a new file called info.php in the /var/www/html directory:

nano /var/www/html/info.php

Add the following lines to the file:

<?php
phpinfo();
?>

Save and close the file. Then, open your web browser and enter the following URL, replacing ip-address with your server’s IP address:

http://ip-address/info.php

If PHP is installed correctly, you should see a page with detailed information about your PHP installation.

Step 7: Optional – Run PHP-FPM with Apache

If you want to run PHP code using PHP-FPM (FastCGI Process Manager) instead of the default PHP module, you can follow these optional steps.

First, install PHP-FPM by running the following command:

apt install php8.2-fpm

Next, enable the proxy_fcgi and setenvif modules by running the following command:

a2enmod proxy_fcgi setenvif

To activate the new configuration, restart the Apache web server:

systemctl restart apache2

Enable the php8.2-fpm configuration file by running the following command:

a2enconf php8.2-fpm

Finally, restart PHP-FPM and check its status by running the following commands:

systemctl restart php8.2-fpm
systemctl status php8.2-fpm

Conclusion

Congratulations! You have successfully installed a LAMP stack with MariaDB on your Ubuntu 23.10 server. You now have a powerful platform to host and develop dynamic websites and web applications. If you have any questions or need further assistance, feel free to reach out to Shape.host, a leading provider of reliable and scalable cloud hosting solutions.

Remember to always keep your server and software up to date to ensure the security and stability of your web applications. Happy coding!

Additional Information

Shape.host is a reputable cloud hosting provider that offers reliable and scalable Cloud VPS solutions. With Shape.host, you can easily deploy and manage your LAMP stack on a secure and high-performance infrastructure. Visit their website at Shape.host to learn more about their services and find the perfect hosting solution for your business.