phpservermon and Debian 9 (Stretch)

23 Jan

Let’s assume Proxmox:
[bash]apt-get install qemu-guest-agent openssh-server[/bash]

Let’s prepare to install a newer version of PHP:
[bash]apt -y install lsb-release apt-transport-https ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list[/bash]

Update the sources:
[bash]apt-get update[/bash]

Now we can install:
[bash]apt-get install apache2 mysql-server libapache2-mod-php7.4 php7.4-common php7.4-curl php7.4-dev php7.4-gd php7.4-mbstring php7.4-xml php7.4-zip php7.4-mysql postfix[/bash]

Let’s secure the database server:
[bash]mysql_secure_installation[/bash]

Let’s create a database:

[bash]mysql -u root -p[/bash]
[text]CREATE USER ‘phpmyadmin’@’%’ IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON *.* TO ‘phpmyadmin’@’%’ WITH GRANT OPTION;
quit;[/text]

I prefer to have the site which runs phpMyAdmin is only accessible on another port:
[bash]nano /etc/apache2/ports.conf[/bash]
[text]Listen 8080[/text]

Create the directory the site source code will be located:
[bash]mkdir -p /var/vhosts/phpmyadmin/www[/bash]

Download phpMyAdmin:
[bash]cd /tmp
wget https://files.phpmyadmin.net/phpMyAdmin/4.9.7/phpMyAdmin-4.9.7-english.tar.gz
tar xzf phpMyAdmin-4.9.7-english.tar.gz[/bash]

We can then move it to the created folder:
[bash]cd phpMyAdmin-4.9.7-english
cp * -R /var/vhosts/phpmyadmin/www[/bash]

Update Apache’s configuration:
[bash]nano /etc/apache2/sites-available/phpmyadmin.conf[/bash]

[text]<VirtualHost *:8080>
ServerName phpmyadmin
DocumentRoot "/var/vhosts/phpmyadmin/www"
<Directory />
Require all granted
</Directory>
</VirtualHost>[/text]

Assign proper permissions:
[bash]chown -R www-data:www-data /var/vhosts[/bash]

Enable the site and restart the service:
[bash]a2ensite phpmyadmin
service apache2 restart[/bash]

Create a user and database for phpservermon using phpMyAdmin.
[text]http://ip-address:8080[/text]

Let’s create folders, download + extract, and move the source files for phpservermon:

[bash]mkdir -p /var/vhosts/website_name/www
mkdir -p /var/vhosts/website_name/ssl
cd /tmp
wget https://github.com/phpservermon/phpservermon/releases/download/v3.5.2/phpservermon-3.5.2.tar.gz
tar xzf phpservermon-3.5.2.tar.gz
cd phpservermon-3.5.2
cp * -R /var/vhosts/website_name/www[/bash]

Update Apache’s server config:
[bash]nano /etc/apache2/sites-available/website_name.conf[/bash]

[text]<VirtualHost *:80>
ServerName website_name
Redirect / https://website_name/
</VirtualHost>
<VirtualHost *:443>
ServerName website_name
SSLEngine on
SSLCertificateFile /var/vhosts/website_name/ssl/certificate.crt
SSLCertificateKeyFile /var/vhosts/website_name/ssl/key.key
SSLCertificateChainFile /var/vhosts/website_name/ssl/ca-certificate.crt
DocumentRoot "/var/vhosts/website_name/www"
<Directory />
AllowOverride All
Require all granted
</Directory>
</VirtualHost>[/text]

Create your certificate assets:
[bash]nano /var/vhosts/website_name/ssl/key.key
nano /var/vhosts/website_name/ssl/certificate.crt
nano /var/vhosts/website_name/ssl/ca-certificate.crt[/bash]

Enable the new site and the required SSL module:
[bash]a2ensite website_name
a2enmod ssl[/bash]

Assign the proper owner and restart the service:
[bash]chown -R www-data:www-data /var/vhosts
service apache2 restart[/bash]