First, we will install the MariaDB database server by running the following command:<\/p>\n
apt-get install mariadb-server mariadb-client<\/pre>\nOnce the installation has been completed, start the MariaDB service and enable it to start after system reboot:<\/p>\n
systemctl start mariadb\r\nsystemctl enable mariadb<\/pre>\nNext, log in to MariaDB shell with the following command:<\/p>\n
mysql<\/pre>\nIf everything is fine, you should see the following output:<\/p>\n
Welcome to the MariaDB monitor. Commands end with ; or \\g.\r\nYour MariaDB connection id is 4\r\nServer version: 10.1.38-MariaDB-0+deb9u1 Debian 9.8\r\n\r\nCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.\r\n\r\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.<\/pre>\nMariaDB [(none)]><\/pre>\nNext, secure your MariaDB installation by using the mysql_secure_installation<\/code> script. This script will remove anonymous users, disallow root login remotely, and remove the test database.<\/p>\nmysql_secure_installation<\/pre>\nAnswer all the questions as shown below:<\/p>\n
Enter current password for root (enter for none): press [Enter]\r\nSet root password? [Y\/n]: N\r\nRemove anonymous users? [Y\/n]: Y\r\nDisallow root login remotely? [Y\/n]: Y\r\nRemove test database and access to it? [Y\/n]: Y\r\nReload privilege tables now? [Y\/n]: Y<\/pre>\nOnce MariaDB is secured, you can proceed to the next step.<\/p>\n
<\/span>Step 3: Install Lighttpd<\/span><\/h2>\nBy default, the latest version of Lighttpd is available in the Debian 9 default repository. You can install it by just running the following command:<\/p>\n
apt-get install lighttpd<\/pre>\nOnce installed, start the Lighttpd service and enable it to start after system reboot using the following command:<\/p>\n
systemctl start lighttpd\r\nsystemctl enable lighttpd<\/pre>\nYou can verify the Lighttpd status with the following command:<\/p>\n
systemctl status lighttpd<\/pre>\nIf everything is fine you should get the following output:<\/p>\n
\u25cf lighttpd.service - Lighttpd Daemon\r\nLoaded: loaded (\/lib\/systemd\/system\/lighttpd.service; enabled; vendor preset: enabled)\r\nActive: active (running) since Mon 2019-08-12 14:48:35 UTC; 29s ago\r\nMain PID: 2354 (lighttpd)\r\nCGroup: \/system.slice\/lighttpd.service\r\n\u2514\u25002354 \/usr\/sbin\/lighttpd -D -f \/etc\/lighttpd\/lighttpd.conf\r\n\r\nAug 12 14:48:35 debian9 systemd[1]: Starting Lighttpd Daemon...\r\nAug 12 14:48:35 debian9 systemd[1]: Started Lighttpd Daemon.<\/pre>\nNow, open a web browser and visit the following URL http:\/\/test.example.com<\/code>. You should get the Lighttpd default page as shown below:<\/p>\n<\/p>\n
Lighttpd’s default document root is \/var\/ww\/html<\/code> on Debian 9, the main configuration file is
\n\/etc\/lighttpd\/lighttpd.conf<\/code> and other configuration files are located at \/etc\/lighttpd\/conf-available<\/code> directory.<\/p>\n<\/span>Step 4: Install PHP and PHP-FPM<\/span><\/h2>\nNext, we will install PHP and PHP-FPM, and enable them to work with Lighttpd. You can install PHP along with all of its necessary extensions with the following command:<\/p>\n
apt-get install php php-cli php-common php-fpm php-mysql<\/pre>\nOnce installed, we need to modify the php.ini file to enable PHP support for Lighttpd.<\/p>\n
nano \/etc\/php\/7.0\/fpm\/php.ini<\/pre>\nChange cgi.fix_pathinfo value to 1:<\/p>\n
cgi.fix_pathinfo=1<\/pre>\nSave and close the file.<\/p>\n
By default, PHP-FPM listens on the UNIX socket \/var\/run\/php7-fpm.sock<\/code>. So, we will need to modify the file \/etc\/php\/7.0\/fpm\/pool.d\/www.conf<\/code> and set PHP-FPM to listens on TCP socket.<\/p>\nnano \/etc\/php\/7.0\/fpm\/pool.d\/www.conf<\/pre>\nFind the line:<\/p>\n
listen = \/run\/php\/php7.0-fpm.sock<\/pre>\nReplace it with the following line:<\/p>\n
listen = 127.0.0.1:9000<\/pre>\nSave and close the file. Next, open the file 15-fastcg-php.conf<\/code> to enable FastCGI support in Lighttpd:<\/p>\nnano \/etc\/lighttpd\/conf-available\/15-fastcgi-php.conf<\/pre>\nFind the following lines:<\/p>\n
\"bin-path\" => \"\/usr\/bin\/php-cgi\",\r\n\"socket\" => \"\/var\/run\/lighttpd\/php.socket\",<\/pre>\nReplace them with the following:<\/p>\n
\"host\" => \"127.0.0.1\",\r\n\"port\" => \"9000\",<\/pre>\nSave and close the file. Then, enable FastCGI and FastCGI-PHP modules with the following command:<\/p>\n
lighty-enable-mod fastcgi\r\nlighty-enable-mod fastcgi-php<\/pre>\nFinally, restart Lighttpd and PHP-FPM service to apply all the configuration changes:<\/p>\n
systemctl restart php7.0-fpm\r\nsystemctl restart lighttpd<\/pre>\nYou can verify the PHP-FPM with the following command:<\/p>\n
systemctl status php7.0-fpm<\/pre>\nIf everything is fine you should get the following output:<\/p>\n
\u25cf php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager\r\nLoaded: loaded (\/lib\/systemd\/system\/php7.0-fpm.service; enabled; vendor preset: enabled)\r\nActive: active (running) since Mon 2019-08-12 14:55:36 UTC; 1min 56s ago\r\nDocs: man:php-fpm7.0(8)\r\nMain PID: 12288 (php-fpm7.0)\r\nStatus: \"Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req\/sec\"\r\nTasks: 3 (limit: 7372)\r\nCGroup: \/system.slice\/php7.0-fpm.service\r\n\u251c\u250012288 php-fpm: master process (\/etc\/php\/7.0\/fpm\/php-fpm.conf)\r\n\u251c\u250012289 php-fpm: pool www\r\n\u2514\u250012290 php-fpm: pool www\r\n\r\nAug 12 14:55:36 debian9 systemd[1]: Stopped The PHP 7.0 FastCGI Process Manager.\r\nAug 12 14:55:36 debian9 systemd[1]: Starting The PHP 7.0 FastCGI Process Manager...\r\nAug 12 14:55:36 debian9 systemd[1]: Started The PHP 7.0 FastCGI Process Manager.<\/pre>\n