Install Ubuntu 18.4, Apache2, PHP 7.3 and Percona 5.7

Update system repositories

sudo apt update

Install Apache 2

Install Apache 2 with the apt command

sudo apt install apache2

Allow Apache on UFW and verify its status

sudo ufw allow 'Apache'

Install PHP 7.3

Update system repositories

sudo apt update
sudo apt upgrade

Add PPA for PHP 7.3

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Install PHP 7.3 for Apache

sudo apt install php7.3

Install PHP 7.3 Extensions

Install extensions through:

sudo apt install php7.3-extension_name

sudo apt install php7.3-common php7.3-mysql php7.3-xml php7.3-xmlrpc php7.3-curl php7.3-gd php7.3-imagick php7.3-cli php7.3-dev php7.3-imap php7.3-mbstring php7.3-opcache php7.3-soap php7.3-zip php7.3-intl

Adjust php.ini file

sudo nano /etc/php/7.3/apache2/php.ini

upload_max_filesize = 100M
post_max_size = 48M
memory_limit = 512M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000

Restart Apache2 and PHP services

sudo systemctl restart apache2.service

Test PHP7.3 and Apache2 install

sudo nano /var/www/html/phpinfo.php

Add the following line and save

<?php phpinfo( ); ?>

Load web browser with localhost/phpinfo.php

The following is ONLY for dev environment

Add current user to group that owns /var/www/html folder

sudo usermod -a -G GROUPNAME USERNAME

Reboot system

Change group permissions to rwx

sudo chmod -R g+rwx /var/ww/html

Install Persona 5.7

Source: https://www.percona.com/doc/percona-server/5.7/installation/apt_repo.html

Update max_allowed_packet in mysqld.cnf to 32M to prevent Mysql went away message when doing large imports like: “ERROR 2006 (HY000) at line XXXX: MySQL server has gone away”

sudo nano /etc/mysql/percona-server.conf.d/mysqld.cnf

[mysqld]
max_allowed_packet=32M

sudo service mysql restart

Install PHPMyAdmin

sudo apt update && sudo apt install phpmyadmin

For WordPress installation /

Enable mod_rewrite

sudo a2enmod rewrite

sudo systemctl restart apache2

By default, Apache prohibits using an .htacess file to apply rewrite rules.

sudo nano /etc/apache2/sites-available/000-default.conf

Add the following code between <VirtualHost *:80>

<Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

sudo systemctl restart apache2

Create a .htaccess file in the web root folder

sudo nano /var/www/html/.htaccess

Add default WordPress .htaccess file contents:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Source: https://vitux.com/how-to-install-and-configure-apache-web-server-on-ubuntu/

Source: https://www.cloudbooklet.com/how-to-install-php-7-3-on-ubuntu-18-04/

Source: https://websiteforstudents.com/install-php-7-3-php-7-3-fpm-with-apache2-nginx-on-ubuntu-16-04-18-04-18-10/

Setup Remote Desktop XRDP on Debian 9

Install XRDP

sudo apt install xrdp

Configuring the firewall

sudo ufw allow 3389

Modify the Xwrapper.config file when you get a blank screen when removing in.

sudo nano /etc/X11/Xwrapper.config

Change:

allowed_users = console

to

allowed_users = anybody

Restart XRDP.

sudo systemctl restart xrdp

Actually, reboot the entire server

When logging in and you receive the message: Authentication Required – Authentication is required to create a color managed device click cancel and it’s all working.

PowerShell – Running scripts is disabled on this system.

There are four different execution policies in PowerShell

  • Restricted – No scripts can be run.
  • AllSigned – Only scripts signed by a trusted publisher can be run.
  • RemoteSigned – Downloaded scripts must be signed by a trusted publisher.
  • Unrestricted – All Windows PowerShell scripts can be run.

You can change the PowerShell execution policies with Set-ExecutionPolicy like

Set-ExecutionPolicy Unrestricted

You can get the current policy in PowerShell

get-executionpolicy

Windows PowerShell Remove previous Hyper-V backup folders older than….

This is based on code from Mike Galvin. When you copy the dirs to a network drive or so, this allows you to delete older backups.

Create a file called “Remove-old-Backups.ps1” and enter the following code:

##Remove previous backup folders older than the configured number of days.
$Backup = "\\NETWORKDRIVE\FOLDER\"
$History = 4
## Location of the VM names file
$VmList = "c:\scripts\vms.txt"
##If a VM list file is configured, get the content of the file.
If ($VmList)
{
$Vms = Get-Content $VmList
echo $Vms
}
ForEach ($Vm in $Vms)
{
Get-ChildItem -Path $Backup -Filter "$Vm
-*-*-*-*-*-*" -Directory | Where-Object CreationTime –lt (Get-Date).AddDays(-$History) | Remove-Item -Recurse -Force
echo $Backup
}

Source: https://gal.vin/2017/09/18/vm-backup-for-hyper-v/

Windows PowerShell copy local directory to network drive where items created TODAY

The following script will copy a local directory with items created TODAY to a network share.

Copy and paste below code to a file ending with .ps1 and run from Powershell as Admin

$path = "C:\LOCALPATHTOFOLDER\"
$Destination = "\\NETWORKSHARE\FOLDER"
Get-ChildItem -Path $path | Where-Object {$_.CreationTime.Date -eq (Get-Date).Date} | Copy-Item -Destination $Destination -Recurse -Force
Write-Host "I've just copied the file to $Destination"

Importing Hyper-V backup

From the right pane in Hyper-V Manager Console, select the ‘Import Virtual Machine’ option.

Browse to the folder of your backed up VM and ‘Select Folder’

Choose the type of import to perform.

Complete the import

I’ve been noticing that in some cases when you added a new virtual switch manager other than the default ones in Hyper-V, the VM would fail to start with “Hyper-V Manager: failed to change state.”.

My workaround was doing another import but during the connection selection, selecting a connection for each VM.

Creating Hyper-V backups in Windows 10

Download and run the script from Mike Galvin.

Create folder c:\scripts

Create folder c:\scripts\logs

Create folder c:\scripts\vms

Save code from: https://github.com/Digressive/HyperV-Backup-Utility/blob/master/Hyper-V-Backup.ps1 to file Hyper-V-Backup.ps1 in the folder c:\scripts

Create a text file called c:\scripts\vms.txt and on a separate line list each Hyper-V VM name you would like to backup.

Right click on powershell and run as administrator

Run: C:\scripts\Hyper-V-Backup.ps1 -BackupTo C:\scripts\vms C:\scripts\vms.txt -Keep 4 -L C:\scripts\logs

More options available such as compress and email.

Source: https://gal.vin/2017/09/18/vm-backup-for-hyper-v/

Schedule the task with Task scheduler

Open task scheduler by typing in taskschd.msc

Action > Create Task

Enter in a name like “Backup VMs”

Select “Run whether user is logged on or not”

Configure for: “Windows 10”

Tab Triggers

Daily, select start date / time

Stop task if it runs longer than: 4 hours (or whatever works for you)

Tab Actions

Enter “powershell” in program / script

Enter for “Add arguments (optional):” C:\scripts\Hyper-V-Backup.ps1 -BackupTo C:\scripts\vms C:\scripts\vms.txt -Keep 4 -L C:\scripts\logs

Tab Settings

Check the following:

“Allow task to be run on demand”
“Run task as soon as possible after a scheduled start is missed”
“Stop the task if it runs longer than: 4 hours (or whatever works for you)
“If the running task does not end when requested, force it to stop”

Install Debian 10 with PHP 7 and MySQL 8 + phpMyAdmin

sudo: command not found

After installation of Debian 10 and you try to install a package you might get the message: bash: sudo: command not found

To install sudo, run the following:

su

apt-get install sudo

Give the user the right to run sudo

usermod -aG sudo username

Log out the user to refresh the group permissions of the user

Reference: https://chewett.co.uk/blog/477/sudo-command-not-found-debian-fixed/

Install the firewall ufw on Debian

Run the package installer:

sudo apt-get install ufw

Enable the firewall

sudo ufw enable

Reference: https://www.tecmint.com/how-to-install-and-configure-ufw-firewall/

Install the Apache Web Server

Update the local package index to reflect the latest upstream changes:

sudo apt update

Install the apache2 package

sudo apt install apache2

Configure the firewall for port 80

sudo ufw allow in 'WWW Full'

On your local computer you can check ‘localhost’ in the browser to see if Apache is running.

To test the install from another computer find the IP address of the server with:

ip addr show

Reference: https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-debian-9

Install MYSQL 8.0

MySQL 8.0 packages are available on the official MySQL Dev apt repository

sudo apt -y install wget
wget https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb

sudo apt update
sudo apt -y install mysql-server

Reference: https://computingforgeeks.com/how-to-install-mysql-8-0-on-debian/

Install PHP7

sudo apt update 
sudo apt upgrade

sudo apt install php libapache2-mod-php php-gd php-mysqlnd

Create a PHP Info page to see if it is all working.

sudo nano /var/www/html/info.php

Type in:

<?php phpinfo(); ?>

Enter ctrl+x, y and enter

In your browser go to your https://webserver/info.php

Install phpMyAdmin

Log in to MySQL

mysql -u root -p

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PASSWORD';

Update server’s package index

sudo apt update

sudo apt install php-mbstring php-zip php-gd

wget https://files.phpmyadmin.net/phpMyAdmin/4.9.0.1/phpMyAdmin-4.9.0.1-all-languages.tar.gz

tar xvf phpMyAdmin-4.9.0.1-all-languages.tar.gz

sudo mv phpMyAdmin-4.9.0.1-all-languages/ /usr/share/phpmyadmin

sudo mkdir -p /var/lib/phpmyadmin/tmp

sudo chown -R www-data:www-data /var/lib/phpmyadmin

sudo cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php

sudo nano /usr/share/phpmyadmin/config.inc.php

Add a 32 character blowfish_secret

$cfg['blowfish_secret'] = 'RANDOMSTRINGHERE'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

At the bottom of the file add

$cfg['TempDir'] = '/var/lib/phpmyadmin/tmp';

Configuring Apache to Serve phpMyAdmin

Create new file

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Add the following code:

# phpMyAdmin default Apache configuration

Alias /phpmyadmin /usr/share/phpmyadmin

<Directory /usr/share/phpmyadmin>
    Options SymLinksIfOwnerMatch
    DirectoryIndex index.php

    <IfModule mod_php5.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        </IfModule>
        <FilesMatch ".+\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>

        php_value include_path .
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
        php_admin_value mbstring.func_overload 0
    </IfModule>
    <IfModule mod_php.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        </IfModule>
        <FilesMatch ".+\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>

        php_value include_path .
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
        php_admin_value mbstring.func_overload 0
    </IfModule>

</Directory>

# Authorize for setup
<Directory /usr/share/phpmyadmin/setup>
    <IfModule mod_authz_core.c>
        <IfModule mod_authn_file.c>
            AuthType Basic
            AuthName "phpMyAdmin Setup"
            AuthUserFile /etc/phpmyadmin/htpasswd.setup
        </IfModule>
        Require valid-user
    </IfModule>
</Directory>

# Disallow web access to directories that don't need it
<Directory /usr/share/phpmyadmin/templates>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/setup/lib>
    Require all denied
</Directory>

sudo a2enconf phpmyadmin.conf

sudo systemctl reload apache2

Log into phpMyAdmin: https://localhost/phpmyadmin

Create database phpmyadmin

Click operations tab – follow links to create tables for phpmyadmin database

Source: https://www.digitalocean.com/community/tutorials/how-to-install-phpmyadmin-from-source-debian-10

Install VSTFTPD

sudo apt update
sudo apt install vsftpd

sudo nano /etc/vsftpd.conf

Set the following in the vsftpd.conf file:

anonymous_enable=NO
local_enable=YES
local umask=022
userlist_enable=YES
userlist_file=/etc/vsftpd.user_list
userlist_deny=NO

Add ufw exceptions

sudo ufw allow 20:21/tcp
sudo ufw allow 30000:31000/tcp
sudo systemctl restart vsftpd

Add the users that are allowed to access vsftpd to the vsftpd.userlist (one per line)

sudo nano /etc/vsftpd.user_list

The following is ONLY for dev environment

Add current user to group that owns /var/www/html folder

sudo usermod -a -G GROUPNAME USERNAME

Reboot system

Change group permissions to rwx

sudo chmod -R g+rwx /var/ww/html

A stop job is running for …

When you are getting message such as:

“A stop job is running for Session”

“A stop job is running for User manager for UID”

I found that a quick workaround would be to logout the user first and then shutting down or in terminal enter:

sudo shutdown now