Skip to content

Tutorials Servers Intermediate1 min read

How to Install a LAMP Stack (Linux, Apache, MySQL, PHP) on Ubuntu

Install Apache, MySQL (or MariaDB) and PHP on Ubuntu 24.04, open the firewall, secure the database and test PHP — the classic base for PHP websites.

By ZSOLNET Editorial Team Updated

Key takeaways

  • LAMP runs most PHP applications, including WordPress.
  • Secure MySQL right after installing it.
  • Remove test files like info.php when finished.

These steps assume Ubuntu 24.04 and a user with sudo rights.

1. Apache

sudo apt update
sudo apt install apache2
sudo ufw allow 'Apache Full'

Visit http://your-server-ip — you should see the Apache default page.

2. MySQL

sudo apt install mysql-server
sudo mysql_secure_installation

Answer yes to removing anonymous users, disallowing remote root login and removing the test database.

Create a database and user for your application:

sudo mysql
CREATE DATABASE app;
CREATE USER 'app'@'localhost' IDENTIFIED BY 'a-strong-password';
GRANT ALL PRIVILEGES ON app.* TO 'app'@'localhost';
FLUSH PRIVILEGES;
EXIT;

3. PHP

sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-zip
sudo systemctl restart apache2

4. Test PHP

echo '<?php phpinfo();' | sudo tee /var/www/html/info.php

Open http://your-server-ip/info.php, confirm it shows the PHP version, then delete it: sudo rm /var/www/html/info.php.

Next steps

Create a virtual host for your domain, point DNS at the server, and add a free certificate with Certbot.

Frequently asked questions

Should I choose LAMP or LEMP?

Both work well. Apache supports .htaccess files, which many PHP apps rely on. Nginx (LEMP) uses less memory under heavy load. Pick what your application documents.

MySQL or MariaDB?

Either is fine for most sites. MariaDB is a drop-in replacement for MySQL and is the default on many distributions.

Share X LinkedIn Facebook

Log in to your account

Manage your domains, hosting and invoices in one place.

Secure connection straight to the ZSOLNET client area.

Open the ZSOLNET dashboard

No account yet?