How to Install Apache, MySQL, PHP, and phpMyAdmin on Ubuntu 24.04
🚀 How to Install Apache, MySQL, PHP, and phpMyAdmin on Ubuntu 24.04
If you’re setting up a web server on Ubuntu 24.04, the classic stack of Apache, MySQL, PHP, and phpMyAdmin is still one of the most reliable choices. This combination (often called a LAMP stack) gives you everything you need to host dynamic websites and manage your databases through a user-friendly interface.
In this guide, I’ll walk you through the exact steps I used to install and configure it successfully.
🔹 Step 1: Update Your System
Before installing any packages, make sure your system is up to date:
sudo apt update && sudo apt upgrade -y
🔹 Step 2: Install Apache
Apache is the web server that will serve your websites:
sudo apt install apache2 -y
Enable Apache on boot:
sudo systemctl enable apache2
sudo systemctl start apache2
Test it by visiting your server’s IP in a browser:
http://your-server-ip
You should see the default Apache welcome page.
🔹 Step 3: Install MySQL
Next, install MySQL, the database system:
sudo apt install mysql-server -y
Secure MySQL and set a root password:
sudo mysql
Inside the MySQL shell, run:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPasswordHere';
FLUSH PRIVILEGES;
EXIT;
🔹 Step 4: Install PHP
Now install PHP along with common extensions:
sudo apt install php libapache2-mod-php php-mysql php-cli php-mbstring php-zip php-gd php-json php-curl -y
Check version:
php -v
🔹 Step 5: Install phpMyAdmin
Ubuntu 24.04 doesn’t automatically configure phpMyAdmin in Apache, so we’ll handle that manually:
sudo apt install phpmyadmin -y
Create a new Apache config file:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Add the following:
Alias /phpmyadmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
<Directory /usr/share/phpmyadmin/setup>
Require local
</Directory>
Enable and reload Apache:
sudo a2enconf phpmyadmin
sudo systemctl reload apache2
🔹 Step 6: Access phpMyAdmin
Now you can log in:
http://your-server-ip/phpmyadmin
Use:
- Username:
root - Password: the one you set in MySQL
🎯 Final Thought
You now have a fully working LAMP stack with phpMyAdmin on Ubuntu 24.04.
This setup is perfect for hosting WordPress, Drupal, Joomla, or any PHP-based application.
For better security, I recommend:
- Creating a dedicated MySQL user instead of using
root - Setting up a firewall with UFW
- Installing Let’s Encrypt SSL for secure HTTPS access
With this stack ready, you’re only a few clicks away from deploying your first web app! 🚀