Installing PHPMyAdmin on LigHTTPD on Debian 9 the bugless way

From K1VZX Wiki
Jump to: navigation, search


For this guide, we'll use mariadb. You can use mysql if you want, but mariadb has largely taken over for a variety of reasons which I will not go into here. There is no reason to choose mysql over mariadb as it is 100% compatible with mysql.

Step 1: Install mariadb

apt-get install mariadb-server mariadb-client

*NOTE: Root was not asked for password!

Step 2: Install lighttpd

First, we'll disable apache, since it will interfere. It seems to be installed by default, even if you don't select the "web server" option during Debian 9 install.

systemctl disable apache2
apt-get install lighttpd

The service will likely automatically start (at least it did for me on my first try). By default, it binds to all available interfaces and listens on port 80. So simply fire up a browser and you should see a placeholder page. If you're not sure of your IP, try pointing your browser to "http://localhost:80/". You may see the apache2 placeholder page. To fix this, do the following:

cd /var/www/html
mv index.html index.apache.html
mv index.lighttpd.html index.html

Now refresh your browser page and you should see the lighttpd placeholder page and the relevant information it contains for the install.

Step 3: Install PHP

Installing Packages

apt-get install php-fpm php

Note that you will get warnings about the install scripts not being able to start apache. This is normal! Ignore them.


Next we need to configure lighttpd to use php's fastcgi plugin to execute php code:

nano /etc/php/7.0/fpm/php.ini
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts

Restart php:

systemctl restart php7.0-fpm

We need to make a backup of the existing PHP support configuration file since it uses a different module. Execute the commands:

cd /etc/lighttpd/conf-available/
cp 15-fastcgi-php.conf 15-fastcgi-php-spawnfcgi.conf
nano 15-fastcgi-php.conf
# -*- depends: fastcgi -*-
# /usr/share/doc/lighttpd/fastcgi.txt.gz

## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
               "socket" => "/var/run/php/php7.0-fpm.sock",
               "broken-scriptfilename" => "enable"

Now, enable the fastcgi configuration:

lighttpd-enable-mod fastcgi
lighttpd-enable-mod fastcgi-php

Now you can restart lighttpd:

systemctl restart lighttpd

Testing PHP

Finally, we can test that php is working with a test file:

nano /var/www/html/info.php

Now go to your browser and enter "http://localhost:80/info.php" and you should see an information screen containing details about your php setup. If you do not, there is an issue with your server configuration.

Adding PHP Modules

Now we can add modules, such as mysql support. For mysql, I recommend the php-mysqlnd package. To install, simply execute the command:

apt-get install php-mysqlnd

Other modules are available by searching through the repositories. Some recommended modules are taken from the guide:

apt-get install php-curl php-gd php-intl php-pear php-imagick php-imap php-mcrypt php-memcache php-pspell php-recode php-tidy php-xmlrpc php-xsl

It is a good idea to install a memory cache for your server to speed up execution times of PHP software since PHP code is precompiled like C, and must be executed on the server at time of request which can cause delays for the user. XCache is a good accelerator, I have used it in the past, and it is recommended in the link I reference at the end of this guide, but it is not available in the Debian 9 packages.

Be sure to reboot lighttpd after adding or removing any php modules!

systemctl restart lighttpd

Step 4: Install PHPMyAdmin

Install the packages

Last, we can finally install PHPMyAdmin. First, install the package:

apt-get install phpmyadmin

Select lighttpd as your server at the screen that appears. Next, select yes, when you are prompted to configure phpmyadmin and a database. At the next screen, enter a password that is strong, but that you will remember. Note: Your username is 'phpmyadmin'. You will see some errors after the installer completes, various things about dpkg and apache. Just ignore those, nothing will happen.

Fixing some issues

Now, there are some issues we need to deal with. The directory that the phpmyadmin package installs its software into is /usr/share/phpmyadmin, but lighttpd runs inside a chroot jail under /var/www. So do the following:

mv /usr/share/phpmyadmin /var/www/html

Whambulance! Of course, this kind of defeats the point of the virtual alias. Note that there will not be an entry in your server log about the failed attempt to reach the location on your server outside the chroot jail (like there would be with apache). Just in case, do the following:

nano /etc/phpmyadmin/lighttpd.conf

And correct the alias to the following:

# Alias for phpMyAdmin directory
alias.url += (
        "/phpmyadmin" => "/var/www/html/phpmyadmin",

I suppose the correct thing to do would be to remove the virtual alias entirely, but I have no troubles with it running this way on my system.

Step 5: Sit back, relax, enjoy!

Remember: Your login to phpmyadmin will be 'phpmyadmin' (without the hyphens).


This guide was based on instructions from the following link: Installing Lighttpd with PHP5 (PHP-FPM) and MySQL on Debian 8 (Jessie)