Configure LAMP on Ubuntu

A very good tutorial can be found here: and another one here: – don’t try them both at the same time, rather take them one at a time.

However, if after following it, for some reason, mysql or phpmyadmin does not work, try one of the following fixes

Very useful stuff

1. If, for some reason you get the following error: Phpmyadmin. mysqli_real_connect(): (HY000/2002): Permission denied. Connection for controluser as defined in your configuration failed – try to use the following fix:

In the file /etc/phpmyadmin/config-db.php, change


Afterwards, restart Apache2


2. To delete Linux apps from the command line, use the following commands:

sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean

you can replace mysql* with any other app name such as php* or phpmyadmin* or apache*. You can also use multiple apps like so:

sudo apt-get remove --purge mysql* php* phpmyadmin* apache*

3. Reconfigure phpmyadmin post-install

sudo dpkg-reconfigure phpmyadmin

4. MySQL won’t start – error: su: warning: cannot change directory to /nonexistent: No such file or directory

mysql user is looking for a home directory, which seems to have not been assigned. To do that, you can execute:

sudo systemctl stop mysql.service
sudo usermod -d /var/lib/mysql/ mysql
sudo systemctl start mysql.service


sudo service mysql stop
sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start


5. ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

Try to remove and reinstall all the apps

5. Create Virtual Hosts

Very useful article here:

I still wasn’t able to add a virtual host outside the /var/www folder, but I should be able to do it in the future.


Leave a Reply