Notes on setting up LAMP

Submitted by Rork on Sat, 11/06/2021 - 09:16

Setting up Apache2, Mysql and PHP on my Kubuntu / Ubuntu server installation, the main goal is to put up a dev version of Drupal.

Start with installing all the packages:

sudo apt-get install apache2 mysql-server php phpmyadmin

Configure Apache2 home directories
In Apache it's possible to allow users to host a site from their own home directory, the default is ~/public_html. For this enable the userdir mod, make the directory, set the directory access rights, enable php (follow the directions in the config file) and restart apache:

sudo a2enmod userdir
mkdir ~/public_html
chmod 755 /home/user
chmod 755 ~/public_html
sudo nano /etc/apache2/mods-enabled/php7.4.conf
sudo systemctl restart apache2

Next I want to have clean URL's, because I will install drupal. I use mod_rewrite for that and add the configuration directly to apache2.conf:

sudo a2enmod rewrite
sudo nano /etc/apache2/apache2.conf
# add directory configuration below to apache2.conf
sudo systemctl restart apache2

The configuration will rewrite everything in my public_html directory as arguments to ~user/index.php unless it's a file or directory itself.

<Directory /home/user/public_html>
  RewriteEngine On
  RewriteBase /~user/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Somehow the Drupal .htaccess results in the error ".htaccess: Options not allowed here"

Setting up phpmyadmin
While installing phpmyadmin there is a question to choose a webserver to configure. Apache2 is highlighted but should be selected (space) and there should be an asterisk. When this was forgotten it can be reinstalled. However, to trigger the configuration of the database, all the config files should also be removed.

sudo apt-get purge phpmyadmin
sudo apt-get install phpmyadmin
sudo systemctl restart apache2

By default mysql has no password for root and phpmyadmin doesn't allow logging in without a password. So a password for mysql has to be set:

sudo mysql
mysql> ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 'password'
mysql> exit

phpMyAdmin can now be reached by http://localhost/phpmyadmin with username root and the new password.

Setting up akonadi to the new sql database
Akonadi is a personal information management software which uses a mysql database. On my system after installing mysqld, akonadi stopt working. It is possible to reconfigure akonadi so it uses the new mysqld.

In ~/.config/akonadi/akonadiserverrc set:


Then add the required user and database to mysql:

sudo mysql -p
mysql> CREATE USER USER@localhost IDENTIFIED WITH auth_socket;
mysql> CREATE DATABASE akonadi;
mysql> GRANT ALL PRIVILEGES ON akonadi.* TO USER@localhost;
mysql> exit
akonadictl restart