MySQL Is Not Starting in XAMPP on Ubuntu: Root Causes and Fixes
When you attempt to start XAMPP for Linux using sudo /opt/lampp/lampp start, seeing the message "XAMPP: Couldn't start MySQL!" is a common friction point. The fact that Apache starts successfully while MySQL fails usually points to one of three specific issues: port conflicts, resource contention, or permission errors during the initialization phase. Since you already have a standalone instance of PHP and MySQL running on your system, the most likely culprit is a direct conflict between the system services and the XAMPP stack.
The default configuration for Apache listens on port 80, while standard MySQL installations default to port 3306. If your existing system MySQL service is active, it occupies port 3306. When XAMPP tries to launch its own MariaDB/MySQL instance (which XAMPP Linux bundles), it cannot bind to the socket or port already in use by the system daemon. The lampp script often suppresses verbose error details regarding why the start failed, simply reporting "Couldn't start MySQL!" before moving on to ProFTPD.
To resolve this, you must ensure that no other process is listening on the ports XAMPP intends to use. Start by checking if the system MySQL service is active:
sudo systemctl status mysql
# or
sudo service mysql status
If the output shows active (running), you have two options depending on your infrastructure goals. If you intend to use the bundled MySQL for development and do not need the system instance, stop it completely:
sudo systemctl stop mysql
sudo systemctl disable mysql
However, if you require both PHP versions or specific system databases to remain active, XAMPP must be configured to listen on a different port. This is a frequent requirement in shared hosting environments or dual-stack setups. You can edit the MySQL configuration file located at /opt/lampp/etc/my.cnf. Locate the line defining the port (usually port=3306) and change it to an unused value, such as 3307:
[mysqld]
port=3307
socket=/tmp/mysql.sock
After modifying this file, restart your system MySQL service to ensure it remains on port 3306 while XAMPP initializes its own instance on 3307. Note that you must also update the connection string in your application's configuration files (e.g., .env files in Laravel projects) to reflect the new socket path or port if connecting directly to the XAMPP instance.
Another frequent pitfall involves file permissions. XAMPP for Linux often installs into /opt/lampp, and the bundled database requires write access to its data directory, typically /opt/lampp/var/mysql. If your user does not own this directory correctly, the init script will fail silently or with permission denials that are masked by the generic error message.
Run the following command to ensure the correct ownership:
sudo chown -R www-data:www-data /opt/lampp/var/mysql
Additionally, verify that the mysql user within the XAMPP instance exists and has proper privileges. Sometimes, the bundled installation expects a specific user setup that differs from your system's MySQL user.
If you are developing with Laravel or similar frameworks, managing multiple database instances can get messy quickly. In such scenarios, it is often cleaner to stick with one robust MySQL installation and configure Apache to serve both PHP-FPM setups rather than running two full database stacks side-by-side. This reduces memory overhead and simplifies backup strategies.
Finally, check the XAMPP error log for specific hints. The logs are usually located at /opt/lampp/logs/error.log. Look for lines mentioning bind errors or Access denied. These messages will confirm whether a port conflict is the sole issue or if a deeper permission problem exists. By addressing these specific layersâservice status, port allocation, and directory permissionsâyou can successfully run XAMPP alongside your existing PHP environment without conflicts.
