Introduction
Ready to power up your web projects? This guide offers a comprehensive, step-by-step walkthrough to install the essential LAMP stack on your Ubuntu 24.04 Server or Desktop. We’ll meticulously cover the deployment of Apache, PHP 8.3, and MariaDB 11, transforming your Linux system into a robust web application development environment. Whether you’re setting up a Content Management System like WordPress or building custom dynamic websites, this tutorial provides all you need to get your server running efficiently and securely. Dive in to unlock the full potential of your Ubuntu machine!
Setting Up Your Development Environment: LAMP on Ubuntu 24.04
The LAMP (Linux, Apache, MariaDB/MySQL, PHP) stack remains a cornerstone for deploying dynamic websites and a vast array of web applications. This powerful open-source combination provides everything needed for a robust web platform: a reliable web server, an efficient database management system, and a versatile server-side scripting language. Ideal for content management systems like WordPress, Joomla, and Drupal, a well-configured LAMP stack on your Ubuntu Server is the foundation for countless online ventures.
Prerequisites for Your LAMP Stack Installation
To embark on this tutorial, you’ll need an active Ubuntu 24.04 server instance. If you don’t already have one, consider provisioning a Virtual Private Server (VPS) from a reputable cloud provider:
- DigitalOcean – Starting at $4/month, new users receive $200 in credits for 60 days.
- Linode (Akamai) – Starting at $5/month, new users receive $100 in credits for 60 days.
Affiliate Disclosure: The links above are affiliate links. If you sign up through them, we may earn a small commission at no extra cost to you. This helps support our content creation.
Step-by-Step LAMP Stack Installation on Ubuntu 24.04
1. Deploying Apache: Your Ubuntu Web Server
The journey begins with installing Apache, the world’s most popular web server. We’ll fetch it from Ubuntu’s official repositories.
bash
sudo apt update
sudo apt install apache2
Verifying Apache Status and Ports
Once installed, confirm Apache is running and listening on its default port (80 for HTTP).
bash
sudo systemctl status apache2
sudo ss -tlpn | grep apache2
Configuring UFW Firewall
If UFW (Uncomplicated Firewall) is active on your Ubuntu 24.04 system, you must allow HTTP and HTTPS traffic.
bash
sudo ufw allow ‘Apache Full’
sudo ufw status
Browser Verification
Open your web browser and navigate to your server’s IP address. You should see the default Apache welcome page, confirming its successful operation.
Enabling HTTPS Support (SSL/TLS)
For secure web pages, activate Apache’s SSL module and enable the default SSL configuration.
bash
sudo a2enmod ssl
sudo a2ensite default-ssl.conf
sudo systemctl restart apache2
sudo ss -tlpn | grep apache2
Now, try accessing your server via https://YOUR_SERVER_IP. You’ll encounter a certificate warning because Apache is configured with a self-signed certificate by default. Accept the warning to proceed and view the secure page.
Enabling Apache at Boot
Ensure Apache starts automatically whenever your server reboots.
bash
sudo systemctl enable apache2
2. Integrating PHP 8.3 for Dynamic Content
Next, we install PHP 8.3, along with essential modules required for dynamic web content and database interaction.
Searching for PHP 8.3 Modules
Before installation, you might want to explore the available PHP 8.3 packages:
bash
apt search php8.3
Installing Core PHP 8.3 Modules
Install the fundamental PHP 8.3 modules necessary for most web application development tasks.
bash
sudo apt install php8.3 libapache2-mod-php8.3 php8.3-mysql php8.3-xml php8.3-gd php8.3-curl php8.3-mbstring php8.3-zip
Checking PHP Version
Verify the installed PHP version.
bash
php -v
Testing PHP Configuration with info.php
Create a small info.php file in Apache’s webroot (/var/www/html/) to inspect PHP’s configuration.
bash
sudo nano /var/www/html/info.php
Add the following content:
php
<?php
phpinfo();
?>
Restart Apache to apply the changes:
bash
sudo systemctl restart apache2
Now, open your web browser and navigate to http://YOUR_SERVER_IP/info.php. You should see a detailed PHP information page.
Unique Tip: After verifying, it’s highly recommended to delete or restrict access to info.php in a production environment as it exposes sensitive server configurations. For performance, ensure PHP’s opcache is enabled (it usually is by default with modern PHP installs); it significantly speeds up script execution by caching compiled bytecode.
Installing Additional PHP Modules
To discover and install more PHP 8.3 modules, use apt and bash autocompletion:
bash
sudo apt install php8.3-[TAB]
For instance, to add modules for image manipulation and internationalization:
bash
sudo apt install php8.3-imagick php8.3-intl php8.3-bcmath
Always restart Apache after installing new PHP modules:
bash
sudo systemctl restart apache2
3. Installing MariaDB 11: The Robust Database Backend
Now, let’s install MariaDB 11, a powerful open-source relational database, along with the PHP module needed for database interaction.
bash
sudo apt install mariadb-server mariadb-client php8.3-mysql
Securing Your MariaDB Installation
Immediately after installation, run the security script to harden your MariaDB database server. This script prompts you to set a root password, remove anonymous users, disable remote root login, and eliminate the test database.
bash
sudo mysql_secure_installation
Follow the prompts:
- Press Enter for the current password (none by default).
- Type
Yto switch tounix_socketauthentication (recommended for local root access). - Type
Yto set a root password and enter a strong password. - Type
Yto remove anonymous users. - Type
Yto disallow root login remotely. - Type
Yto remove the test database. - Type
Yto reload privilege tables.
Granting MariaDB Access for System Users
If you need to access MariaDB as a system user without sudo, log in as root and modify the user’s authentication method.
bash
sudo mysql
use mysql;
ALTER USER ‘root’@’localhost’ IDENTIFIED VIA mysql_native_password USING PASSWORD(‘your_strong_password’);
FLUSH PRIVILEGES;
EXIT;
Restarting MariaDB and Logging In
Restart the MariaDB service and test your root login with the new password.
bash
sudo systemctl restart mariadb
mysql -u root -p
4. Optional: Streamlining Database Management with phpMyAdmin
For web-based database administration, consider installing phpMyAdmin.
bash
sudo apt install phpmyadmin
During installation, you’ll be prompted for several configurations:
- Select
apache2as your web server (press Space, then Enter). - Choose
Yesto configure phpMyAdmin withdbconfig-common. - Enter your MariaDB root password.
- Set a strong password for the phpMyAdmin application itself.
Enabling PHP Extensions and Restarting Apache
After phpMyAdmin installs, enable the mbstring PHP extension and restart Apache.
bash
sudo phpenmod mbstring
sudo systemctl restart apache2
You can now access phpMyAdmin by visiting http://YOUR_SERVER_IP/phpmyadmin in your web browser.
Securing phpMyAdmin
It’s crucial to secure your phpMyAdmin installation to prevent unauthorized access. Consider implementing additional measures such as HTTP authentication or restricting access by IP address. For more details, refer to resources on securing phpMyAdmin.
FAQ
Question 1: What is the primary advantage of choosing LAMP for web application development on Ubuntu?
Answer 1: The LAMP stack (Linux, Apache, MariaDB/MySQL, PHP) offers a stable, mature, and widely supported environment for web application development. Its open-source nature means cost-effectiveness, extensive community support, and flexibility. On an Ubuntu Server, it benefits from Ubuntu’s robust package management and security updates, making it a reliable and secure platform for anything from small blogs to complex enterprise applications.
Question 2: How can I ensure my LAMP stack is secure after installation?
Answer 2: Security is paramount for any Linux server. Key steps include: 1) Regular Updates: Keep Ubuntu, Apache, PHP, and MariaDB updated. 2) Firewall: Configure UFW to only allow necessary ports (80, 443, 22). 3) MariaDB Security: Always run mysql_secure_installation and use strong, unique passwords. 4) PHP Security: Disable display_errors in production, remove info.php, and restrict file upload sizes. 5) Apache Security: Use HTTPS with Let’s Encrypt for free SSL certificates, implement proper file permissions, and consider using Web Application Firewalls (WAFs).
Question 3: Can I host multiple websites with this LAMP setup?
Answer 3: Absolutely! Hosting multiple websites on a single LAMP stack is achieved through Apache’s Virtual Host feature. Each virtual host allows you to specify a unique document root, server name, log files, and other configurations for different domains or subdomains. This enables efficient resource utilization on your Ubuntu Server while maintaining separate environments for each website. You’d typically create a new .conf file in /etc/apache2/sites-available/ for each site and then enable it using a2ensite.

![How to Install LAMP Stack on Ubuntu 24.04 [Complete Guide] How to Install LAMP Stack on Ubuntu 24.04 [Complete Guide]](https://i3.wp.com/www.tecmint.com/wp-content/uploads/2016/10/Install-LAMP-Stack-on-Ubuntu-24.04.webp?w=1024&resize=1024,1024&ssl=1)