Disclaimer: We may earn a commission when you purchase products linked throughout our site.

DigitalOcean โ€” Cloud hosting for developers
XAMPP on Ubuntu 24.04: Install, Security Hardening, and Port Conflicts

XAMPP on Ubuntu 24.04: Install, Security Hardening, and Port Conflicts

Install XAMPP on Ubuntu 24.04 for local PHP development, secure the default configuration, and resolve Apache/MySQL port conflicts with system services.

XAMPP remains the quickest way to get a local Apache-MySQL-PHP stack running for WordPress development, legacy PHP projects, and learning web development - but installing it on Ubuntu 24.04 comes with complications that the official documentation glosses over. Ubuntu ships its own Apache2, MySQL (via the mysql-server package), and PHP, and these conflict directly with XAMPP’s bundled versions. Port 80 is already in use, port 3306 is claimed by the system MySQL, and XAMPP’s default installation is wildly insecure for anything beyond isolated local testing. This guide covers the correct installation process, resolving every common port conflict, securing the installation against network exposure, and knowing when Docker is a better choice. We have maintained XAMPP setups alongside system LAMP stacks for years and can detail exactly where the friction points are.

Why XAMPP in 2026?

A fair question. Docker, Laravel Herd, and DDEV all provide better isolated development environments. But XAMPP still has a role:

  • Simplicity: One installer, one start button, working PHP/MySQL. No containerisation knowledge required.
  • Legacy compatibility: Some older PHP projects expect the exact XAMPP directory structure (/opt/lampp/htdocs/).
  • Learning: If you are new to web development, XAMPP lets you focus on PHP and MySQL without the overhead of understanding containers.

For professional PHP development in 2026, we recommend Docker or DDEV instead. But if you want XAMPP, here is how to make it work.

Ready to go beyond localhost? When your project outgrows local development and you need a live server, Digital Ocean makes it easy to spin up an Ubuntu 24.04 server with Apache, MySQL, and PHP pre-configured - a natural next step from XAMPP.

Installation

Download

Get the latest XAMPP for Linux from the Apache Friends website. The file is a self-extracting installer:

chmod +x xampp-linux-x64-*-installer.run
sudo ./xampp-linux-x64-*-installer.run

Follow the graphical installer. XAMPP installs to /opt/lampp/ by default. Do not change this path - many XAMPP tools hardcode it.

Headless Installation (No GUI)

For server or SSH-only installations:

sudo ./xampp-linux-x64-*-installer.run --mode unattended

Resolving Port Conflicts

Apache: Port 80 Conflict

Ubuntu’s Apache2 (if installed) claims port 80. If XAMPP’s Apache fails to start:

sudo systemctl status apache2

If Ubuntu’s Apache is running:

Option A: Disable Ubuntu’s Apache

sudo systemctl stop apache2
sudo systemctl disable apache2

Option B: Change XAMPP’s Port

Edit /opt/lampp/etc/httpd.conf:

Listen 8080

And update ServerName:

ServerName localhost:8080

Access your sites at http://localhost:8080 instead of http://localhost.

MySQL: Port 3306 Conflict

Similarly, if Ubuntu’s MySQL or MariaDB is installed:

sudo systemctl status mysql

Option A: Disable Ubuntu’s MySQL

sudo systemctl stop mysql
sudo systemctl disable mysql

Option B: Change XAMPP’s MySQL Port

Edit /opt/lampp/etc/my.cnf:

[mysqld]
port = 3307

Update your application configs to connect to port 3307.

Check for Port Usage

Before starting XAMPP, verify what is using your ports:

sudo ss -tlnp | grep -E ':80|:443|:3306'

This shows the process ID and name of anything listening on the relevant ports.

Starting and Stopping XAMPP

Command Line

sudo /opt/lampp/lampp start    # Start all services
sudo /opt/lampp/lampp stop     # Stop all services
sudo /opt/lampp/lampp restart  # Restart all services

Individual Services

sudo /opt/lampp/lampp startapache    # Start only Apache
sudo /opt/lampp/lampp startmysql     # Start only MySQL

XAMPP Manager (GUI)

sudo /opt/lampp/manager-linux-x64.run

This opens a graphical panel for starting/stopping services. However, it requires a desktop environment and root privileges.

Auto-Start on Boot

If you want XAMPP to start automatically:

sudo tee /etc/systemd/system/xampp.service << 'EOF'
[Unit]
Description=XAMPP
After=network.target

[Service]
Type=forking
ExecStart=/opt/lampp/lampp start
ExecStop=/opt/lampp/lampp stop

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable xampp

Security Hardening

XAMPP ships with intentionally insecure defaults - no MySQL root password, phpMyAdmin accessible without authentication, and the web server listening on all interfaces. This is a convenience for local development but a disaster if exposed to a network.

Step 1: Run the Security Script

sudo /opt/lampp/lampp security

This interactive script lets you:

  • Set a MySQL root password
  • Set a phpMyAdmin password
  • Restrict XAMPP directory access
  • Set a ProFTPD password (or disable FTP)

Do this immediately after installation.

Step 2: Bind to Localhost Only

Edit /opt/lampp/etc/httpd.conf:

Listen 127.0.0.1:80

This prevents XAMPP from being accessible from other machines on your network.

For MySQL, edit /opt/lampp/etc/my.cnf:

[mysqld]
bind-address = 127.0.0.1

Step 3: Disable Unnecessary Modules

Edit /opt/lampp/etc/httpd.conf and comment out modules you do not need:

# LoadModule dav_module modules/mod_dav.so
# LoadModule dav_fs_module modules/mod_dav_fs.so
# LoadModule status_module modules/mod_status.so

The status module in particular should be disabled - it exposes server internals.

Step 4: Firewall Rule

Even with localhost binding, add a firewall rule as defence in depth:

sudo ufw deny from any to any port 80
sudo ufw deny from any to any port 3306

Adjust if you changed the default ports.

Working with htdocs

XAMPP serves files from /opt/lampp/htdocs/. The default owner is root, which means you cannot create files without sudo. Fix this:

sudo chown -R $USER:$USER /opt/lampp/htdocs

Now you can create and edit files normally:

echo '<?php phpinfo();' > /opt/lampp/htdocs/info.php

Access at http://localhost/info.php. Delete this file after verifying - phpinfo exposes sensitive server details.

PHP Version Management

XAMPP bundles its own PHP (typically PHP 8.x in 2026 versions). This PHP is separate from any system PHP installed via apt. XAMPP’s PHP binary is at:

/opt/lampp/bin/php --version

If your project requires a different PHP version, you have two options:

  1. Download a different XAMPP version that bundles the PHP version you need
  2. Replace XAMPP’s PHP with a system PHP by updating php.ini and symlinking - this is fragile and not recommended

For multi-version PHP development, Docker is genuinely the better tool.

Uninstalling XAMPP

sudo /opt/lampp/lampp stop
sudo rm -rf /opt/lampp
sudo rm /etc/systemd/system/xampp.service 2>/dev/null
sudo systemctl daemon-reload