The LAMP Stack (Linux, Apache, MySQL/MariaDB, and PHP) is a collection of open-source software used to create websites and web applications. Each component of the LAMP Stack is freely available, making it suitable for both development and production contexts.
This guide will provide you with detailed instructions on how to install the LAMP Stack on Ubuntu 24.04 “Noble Numbat” server. You’ll also learn how to secure MariaDB and set up a virtual host using an Apache web server.
Prerequisites
Before proceeding, ensure that you have an Ubuntu 24.04 “Noble Numbat” server with either the root user or a non-root user with administrative privileges.
Installing Apache Web Server
Apache is widely recognized as one of the most reliable web server solutions. Many high-traffic websites like Wikipedia, Slack, and LinkedIn rely on Apache. Its modular nature means you can extend its capabilities through add-ons.
Here’s how to install Apache on Ubuntu 24.04:
Start by updating your package list:
sudo apt update
Install Apache with the following command, confirming with Y when prompted:
sudo apt install apache2
After installation, Apache should start automatically:
sudo systemctl is-enabled apache2 sudo systemctl status apache2
If UFW is active, allow traffic for Apache:
sudo ufw allow 'Apache Full'
Verify UFW rules:
sudo ufw status
Finally, access your server’s IP (e.g., http://192.168.5.30/) to see Apache’s default page:
Installing MariaDB Database Server
MariaDB is an enhanced, open-source fork of MySQL, renowned for its speed and features. Here’s how you can install and secure it on Ubuntu 24.04:
Install MariaDB:
sudo apt install mariadb-server
Check MariaDB’s status:
sudo systemctl is-enabled mariadb sudo systemctl status mariadb
Run MariaDB’s secure installation tool:
sudo mariadb-secure-installation
Follow on-screen prompts to strengthen MariaDB’s security by setting a root password, disabling remote root login, and removing test databases.
Installing PHP
PHP is a key language for web development, powering popular CMS platforms like WordPress. Install it with essential extensions:
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-json php-intl php-bcmath php-opcache php-apcu php-mbstring php-fileinfo php-xml php-soap php-tokenizer php-zip
Edit PHP configuration:
sudo nano /etc/php/8.3/apache2/php.ini
Adjust the following settings:
date.timezone = Europe/Paris memory_limit = 256M upload_max_file_size = 64M max_execution_time = 300
Restart Apache to apply changes:
sudo systemctl restart apache2
Apache and PHP Integration
Create a PHPINFO file for verification:
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
Access http://192.168.5.30/info.php in your browser:
Creating a Virtual Host in Apache
To host multiple sites, configure a virtual host:
Create the document root:
mkdir -p /var/www/mysite/public_html echo "Welcome to mysite.com" > /var/www/mysite/public_html/index.html
Set ownership:
sudo chown -R www-data:www-data /var/www/mysite
Configure the virtual host file:
sudo nano /etc/apache2/sites-available/mysite.conf
Insert the following:
<VirtualHost *:80> ServerAdmin admin@mysite.com ServerName mysite.com ServerAlias www.mysite.com DocumentRoot /var/www/mysite/public_html ErrorLog ${APACHE_LOG_DIR}/mysite-error.log CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined </VirtualHost>
Enable the site and test configuration:
sudo a2ensite mysite.conf sudo apachectl configtest
Restart Apache:
sudo systemctl restart apache2
Testing Your Apache Virtual Host
Update your local hosts file with your domain and server IP. For Windows, edit C:\Windows\System32\drivers\etc\hosts. For Linux/MacOS, edit /etc/hosts with:
192.168.5.30 mysite.com
Visit http://mysite.com/ to confirm the setup:
FAQ
What is LAMP Stack?
LAMP Stack is an acronym for Linux, Apache, MySQL/MariaDB, and PHP. It is a popular open-source web development platform.
Why use MariaDB instead of MySQL?
MariaDB is a fork of MySQL with additional features and optimizations, often preferred for its enhanced performance and scalability.
How do I access the virtual host?
To access a virtual host, you need to map your server’s IP to the domain in your local hosts file. Then, visit the domain in your web browser.
What if Apache does not start after configuration?
Check the Apache logs for error messages and verify that your configuration files are syntax error-free using apachectl configtest
.