Reader Stacks

Installing PHP, Apache, MySQL, and phpMyAdmin on Ubuntu

A working LAMP stack setup for Ubuntu — apt package installation, the Apache/MySQL services, and the one phpMyAdmin config step people usually miss.

Installing PHP, Apache, MySQL, and phpMyAdmin on Ubuntu

A LAMP stack (Linux, Apache, MySQL, PHP) is still a common baseline for running PHP applications on a self-managed Ubuntu server — here's a working setup, current as of recent Ubuntu LTS releases.

1. Update package lists

sudo apt update && sudo apt upgrade -y

2. Install Apache

sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2

3. Install MySQL

sudo apt install mysql-server -y
sudo mysql_secure_installation

mysql_secure_installation walks through setting a root password, removing anonymous users, and disabling remote root login — don't skip this step on anything beyond a throwaway local environment.

4. Install PHP and common extensions

sudo apt install php libapache2-mod-php php-mysql php-mbstring php-xml php-curl -y

The specific extension list depends on what the application needs — a Laravel project typically also needs php-zip, php-bcmath, and php-gd or php-imagick for image handling.

5. Restart Apache to load PHP

sudo systemctl restart apache2

6. Install phpMyAdmin

sudo apt install phpmyadmin -y

During installation, select apache2 when prompted for the web server to configure automatically, and choose whether to let the installer configure the database for phpMyAdmin itself.

The step people miss: enabling the Apache config

If phpMyAdmin was installed separately from Apache, or the automatic prompt was skipped, the Apache config for it needs to be included manually:

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin
sudo systemctl reload apache2

Without this, /phpmyadmin returns a 404 even though the package installed successfully — a common point of confusion.

Security note for a real server

Exposing phpMyAdmin on a public-facing production server is a common attack target — for anything beyond local development, restrict access by IP, put it behind a VPN, or move it to a non-default, non-guessable URL path at minimum.

Topics: Deployment & Hosting