• 07464 367512
  • wblug@elvis-online.co.uk

WBLUG
MAN Pages

1 - How to Setup Ubuntu 18.04 Server with LAMP, PHP, MariaDB, Cubecart and Plex PDF File.
Open the attached PDF file and follow the instructions. The commands highlighted in YELLOW need to be copied / pasted into a terminal. If you follow these instructions then you will have a fully working server with the above programs.

Download and Install Ubuntu 18.04 Server
Download the iso for Ubuntu 18.04 from here
Burn the iso to disc and then go through the steps to install on your machine. Once rebooted update your repo list via terminal as root sudo apt-get update Then install any updates by sudo apt-get upgrade

Setup a static ip address for the server through the setup screen. This will save aggravation later and save a lot of stress. If you dont want to setup a static IP now, allow it to setup as DHCP and see the appendix below.



Install ssh Server
( https://linuxconfig.org/how-to-install-ssh-server-on-ubuntu-18-04-bionic-beaver-linux )
Log into your server and type the following commands, pressing <Enter> after each one.

$ sudo apt-get -y install resolvconf
$ sudo apt install tasksel

Next, use tasksel to install the openssh-servertask:

$ sudo tasksel install openssh-server

Do the above as you need to be able to access your server via ftp and putty, and you need ssl installed and to open the required ports
Reboot the machine
( See Appendix A for extra ssh commands, start, stop etc. )
Log back in and type the following command.

$ sudo systemctl enable ssh

Open incoming TCP ports 20, 21, 22 and 80 from any source, such as when running FTP server:

$ sudo ufw allow from any to any port 20,21,22,80 proto tcp

The above command will allow you to run putty from another machine remotely, this is beneficial as its easier to copy / paste commands from a browser into putty, rather than having to type long commands / weird symbols and make mistakes.

$ sudo service ssh restart

At this stage I would install “Putty” on my laptop and connect to my Ubuntu server via Putty. This is due to being able to copy/paste the following commands. I find it easier to copy/paste rather than typing in long commands which may include funny symbols. This leads to mistakes. If you are happy to type the following commands without putty, then no problem.
For everyone else, install Putty on your laptop. Run Putty. Type in the IP address of your server, port 22 and connection type ssh, and click “Open”. Type in your username and password and you are connected to your server.

Install MariaDB repository and software
Here are the commands to install MariaDB 10.3 from the MariaDB repository on your Ubuntu system:

$ sudo apt-get install software-properties-common
$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
$ sudo add-apt-repository 'deb [arch=amd64] http://mirror.sax.uk.as61049.net/mariadb/repo/10.3/ubuntu bionic main'

Once the key is imported and the repository added you can install MariaDB 10.3 from the MariaDB repository with:

$ sudo apt update


Install Apache With PHP. https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-18-04-lamp/

Sign in as root with sudo su And enter the following commands Run the following command to install MariaDB-server and client:

apt-get -y install mariadb-server mariadb-client

Now we set a root password for MariaDB. mysql_secure_installation
Test the login to MariaDB with the "mysql command"

mysql u root -p and enter the MariaDB root password that you've set above.
To leave the MySQL/MariaDB shell, enter the command "quit" and press enter. Apache 2 is available as an Ubuntu package, therefore we can install it like this:

apt-get -y install apache2

Now direct your browser to http://<Your IP Address> and you should see the Apache2 default page (It works!):
The document root of the apache default vhost is /var/www/html on Ubuntu and the main configuration file is /etc/apache2/apache2.conf. The configuration system is fully documented in /usr/share/doc/apache2/README.Debian.gz.


Install PHP 7.2

We can install PHP 7.2 and the Apache PHP module as follows:

apt-get -y install php7.2 libapache2-mod-php7.2

Then restart Apache:

systemctl restart apache2

Test PHP and get details about your PHP installation
The document root of the default web site is /var/www/html. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version. So as root user still

nano /var/www/html/info.php
<?php
phpinfo();


Save the document. Then change the owner of the info.php file to the www-data user and group.

chown www-data:www-data /var/www/html/info.php

Now we call that file in a browser (e.g. http://<Your Server IP Address>/info.php):
Get MySQL / MariaDB support in PHP
To get MySQL support in PHP, we can install the php7.2-mysql package. It's a good idea to install some other PHP modules as well as you might need them for your applications. You can search for available PHP modules like this:

apt-cache search php7.2 and apt-cache search php- as not all PHP packages have the version number 7.2 in their name.

Pick the ones you need and install them like this (I installed all of them): Type the following commands into the terminal

apt-get -y install php7.2-mysql php7.2-curl php7.2-gd php7.2-intl php-pear php-imagick php7.2-imap php7.2- php-memcached
php7.2-pspell php7.2-recode php7.2-sqlite3 php7.2-tidy php7.2-xmlrpc php7.2-xsl php7.2-mbstring php-gettext apt-get install mysql-server Now restart Apache2:
systemctl restart apache2



Install the Opcache + APCu PHP cache to speed up PHP

PHP 7 ships with a built-in opcode cacher for caching and optimizing PHP intermediate code, it has the name 'opcache' and is available in the package php7.0-opcache. It is strongly recommended to have an Opcache installed to speed up your PHP page. Besides opcache, I will install APCu which is a compatibility wrapper for opcache to provide the functions of the APC cache, an often used caching system in PHP 5.x versions and many CMS systems still use it.
Opcache and APCu can be installed as follows:

apt-get -y install php7.2-opcache php-apcu

Don't worry if it shows that Opcache is already installed. Now restart Apache:

systemctl restart apache2


Enable the SSL website in apache
SSL/ TLS is a security layer to encrypt the connection between the web browser and your server. Most web browsers start to show sites as insecure today when the connection between the server and the web browser is not encrypted with SSL. In this chapter, I will show you how to secure your website with SSL.
Execute the following commands on your server to enable SSL (https://) support. Run:

a2enmod ssl
a2ensite default-ssl


which enables the SSL module and adds a symlink in the /etc/apache2/sites-enabled folder to the file /etc/apache2/sites-available/default-ssl.conf to include it into the active apache configuration. Then restart apache to enable the new configuration:

systemctl restart apache2

Now test the SSL connection by opening https://<Your IP Address> in a web browser.
The closed "Green Padlock" in front of the URL in the browser shows that the connection is encrypted.


Install phpMyAdmin

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-on-ubuntu-18-04

$ sudo apt-update
$ sudo apt install phpmyAdmin php-mbstring php gettext

Warning: When the prompt appears, “apache2” is highlighted, but not selected. If you do not hit SPACE to select Apache, the installer will not move the necessary files during installation. Hit SPACE, TAB, and then ENTER to select Apache.
• For the server selection, choose apache2
• Select Yes when asked whether to use dbconfig-common to set up the database
• You will then be asked to choose and confirm a MySQL application password for phpMyAdmin
The installation process adds the phpMyAdmin Apache configuration file into the /etc/apache2/conf-enabled/ directory, where it is read automatically. The only thing you need to do is explicitly enable the mbstring PHP extension, which you can do by typing:

$ sudo phpenmod mbstring

Afterwards, restart Apache for your changes to be recognized:

$ sudo systemctl restart apache2

phpMyAdmin is now installed and configured. However, before you can log in and begin interacting with your MySQL databases, you will need to ensure that your MySQL users have the privileges required for interacting with the program.

Step 2 — Adjusting User Authentication and Privileges
When you installed phpMyAdmin onto your server, it automatically created a database user called phpmyadmin which performs certain underlying processes for the program. Rather than logging in as this user with the administrative password you set during installation, it’s recommended that you log in as either your root MySQL user or as a user dedicated to managing databases through the phpMyAdmin interface. Configuring Password Access for the MySQL Root Account
In Ubuntu systems running MySQL 5.7 (and later versions), the root MySQL user is set to authenticate using the auth_socket plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program — like phpMyAdmin — to access the user.
In order to log in to phpMyAdmin as your root MySQL user, you will need to switch its authentication method from auth_socket to mysql_native_password if you haven’t already done so. To do this, open up the MySQL prompt from your terminal:

$ sudo mysql

Next, check which authentication method each of your MySQL user accounts use with the following command:
SELECT user,authentication_string,plugin,host FROM mysql.user;
In this example, you can see that the root user does in fact authenticate using the auth_socket plugin. To configure the root account to authenticate with a password, run the following ALTER USER command. Be sure to change password to a strong password of your choosing:

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

Then, run FLUSH PRIVILEGES which tells the server to reload the grant tables and put your new changes into effect:

FLUSH PRIVILEGES;

Check the authentication methods employed by each of your users again to confirm that root no longer authenticates using the auth_socket plugin:
SELECT user,authentication_string,plugin,host FROM mysql.user;
You can see from the output that the root user will authenticate using a password. You can now log in to the phpMyAdmin interface as your root user with the password you’ve set for it here. Configuring Password Access for a Dedicated MySQL User
Alternatively, some may find that it better suits their workflow to connect to phpMyAdmin with a dedicated user. To do this, open up the MySQL shell once again:

$ sudo mysql

Note: If you have password authentication enabled, as described in the previous section, you will need to use a different command to access the MySQL shell. The following will run your MySQL client with regular user privileges, and you will only gain administrator privileges within the database by authenticating:

mysql -u root -p

From there, create a new user and give it a strong password:

CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'password';

Then, grant your new user appropriate privileges. For example, you could grant the user privileges to all tables within the database, as well as the power to add, change, and remove user privileges, with this command:

GRANT ALL PRIVILEGES ON *.* TO 'sammy'@'localhost' WITH GRANT OPTION;

Following that, exit the MySQL shell:

exit

You can now access the web interface by visiting your server's domain name or public IP address followed by /phpmyadmin:
https://your_domain_or_IP/phpmyadmin
Log in to the interface, either as root or with the new username and password you just configured.

Step 3 — Securing Your phpMyAdmin Instance

Because of its ubiquity, phpMyAdmin is a popular target for attackers, and you should take extra care to prevent unauthorized access. One of the easiest ways of doing this is to place a gateway in front of the entire application by using Apache's built-in .htaccess authentication and authorization functionalities.
To do this, you must first enable the use of .htaccess file overrides by editing your Apache configuration file.
Edit the linked file that has been placed in your Apache configuration directory:

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

Add an AllowOverride All directive within the <Directory /usr/share/phpmyadmin> section of the configuration file, like this:

/etc/apache2/conf-available/phpmyadmin.conf
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All

. . .
When you have added this line, save and close the file.
To implement the changes you made, restart Apache:

$ sudo systemctl restart apache2

Now that you have enabled .htaccess use for your application, you need to create one to actually implement some security.
In order for this to be successful, the file must be created within the application directory. You can create the necessary file and open it in your text editor with root privileges by typing:

$ sudo nano /usr/share/phpmyadmin/.htaccess

Within this file, enter the following information:

/usr/share/phpmyadmin/.htaccess
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user


Here is what each of these lines mean:

AuthType Basic: This line specifies the authentication type that you are implementing. This type will implement password authentication using a password file.
AuthName: This sets the message for the authentication dialog box. You should keep this generic so that unauthorized users won't gain any information about what is being protected.
AuthUserFile: This sets the location of the password file that will be used for authentication. This should be outside of the directories that are being served. We will create this file shortly.
Require valid-user: This specifies that only authenticated users should be given access to this resource. This is what actually stops unauthorized users from entering.
When you are finished, save and close the file.
The location that you selected for your password file was /etc/phpmyadmin/.htpasswd. You can now create this file and pass it an initial user with the htpasswd utility:

$ sudo htpasswd -c /etc/phpmyadmin/.htpasswd username

You will be prompted to select and confirm a password for the user you are creating. Afterwards, the file is created with the hashed password that you entered.
If you want to enter an additional user, you need to do so without the -c flag, like this:

$ sudo htpasswd /etc/phpmyadmin/.htpasswd additionaluser

Now, when you access your phpMyAdmin subdirectory, you will be prompted for the additional account name and password that you just configured:
https://domain_name_or_IP/phpmyadmin
After entering the Apache authentication, you'll be taken to the regular phpMyAdmin authentication page to enter your MySQL credentials. This setup adds an additional layer of security, which is desirable since phpMyAdmin has suffered from vulnerabilities in the past.

How to create files and directorys in var/www folder on your server https://askubuntu.com/questions/181481/how-to-create-files-and-directorys-in-var-www

In a terminal use the next commands: (cd = Change Directory) cd /var/www mkdir = Make Directory, this command requires elevated privileges, so run it with sudo or gksudo sudo mkdir foldername
(where foldername is the name of the folder that you wish to create).
You can create subfolders from within /var/www without changing to the desired destination by using:
sudo mkdir foldername/subfolder
How to install cubecart on your localhost
First go to https://www.cubecart.com/download and download the latest zip file.
Create a folder on your laptop, something like “shop”. Unzip the file into the directory you have created. https://www.fastcomet.com/tutorials/cubecart/manual-installation
Then run putty. https://superuser.com/questions/19318/how-can-i-give-write-access-of-a-folder-to-all-users-in-linux
The files / folders under /var/www/html cannot be written to which means no uploading. So, you will have to enter the following commands

$ cd /var/www
$ sudo usermod -a -G www-data <some_user>
$ sudo chgrp -R www-data /var/www
$ sudo chmod -R g+w /var/www

Additionally, you should make the directory and all directories below it "set GID", so that all new files and directories created under /var/www are owned by the www-data group.

$ sudo find /var/www -type d -exec chmod 2775 {} \;

Next upload the cubecart folder on your laptop and put it on your server under /var/www/html
Next you need to make a database for the cubecart installation. Using putty terminal, enter the following:
Now, log into your MySQL database as root by typing:

mysql -p

Then, it will ask you for your password. This is the password that you entered for your database when you installed your MySQL database on your server.

Create the database
It is time to actually create the database you will be using for your website shopfront. To do this, first choose a good name (we'll use the name gallery as an example), and type:

create database gallery;

…and press enter. You will then see the following appear:
Query OK, 1 row affected (0.16 sec)
This is good, and confirms that the database has been added.
Create a database user and password
Now, create a username and a password for your new database. The password should be very secure. Let's say that the username will be ryan and the password will be GanD1do. You will then type the following: grant all privileges on gallery.* to 'ryan'@'localhost' identified by "GanD1do";
Where you replace:
gallery with the name of the database you just created, ryan with the username you chose
GanD1do with the password you chose for your user
Then, type:

flush privileges; and finally:
exit;
Exit your server
You may now exit your server by typing:

exit

Then point your web browser to http://<Your IP Address>/<cubecart-folder>
The cubecart screen should now be showing the compatibility check screen, and all the stuff that’s needed should be installed
Then continue to follow the installation instructions at the above listed website. (https://www.fastcomet.com/tutorials/cubecart/manual-installation)
If all has gone well the store should install and at the end you will be given a web link to log into the admin page, and start configuring the store and uploading products. The admin address will look something like : http://<Your IP Address>/<Sub folder if you created it>/admin_*&^%$.php
Copy and paste the admin link into your browser and you will get the cubecart log in screen.

One final step before you can start adding products to cubecart.

When going to your shopfront through your web browser you can see the products, see the “Latest” Products on the home screen, add them direct to your basket, but you get an error message when trying to go in to the product page:
The requested URL /shop/<your-product-description>.html was not found on this server. Apache/2.4.29 (Ubuntu) Server at <your-server-IP-address> Port 80"

Here is the steps you need to do to resolve the problem. https://stackoverflow.com/questions/18740419/how-to-set-allowoverride-all Open Putty and log into Ubuntu Server

sudo nano /etc/apache2/apache2.conf
Find the following section:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

and change it to;
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Save and exit file
sudo service apache2 restart
sudo a2enmod rewrite to enable module rewrite.
sudo systemctl restart apache2



Install Plex Media Server on Ubuntu 18.04 Bionic Beaver https://manjaro.site/install-plex-media-server-ubuntu-18-04-bionic-beaver/

Step 1. Download the installer
cd /tmp
wget https://downloads.plex.tv/plex-media-server/1.13.9.5456-ecd600442/plexmediaserver_1.13.9.5456-ecd600442_amd64.deb
Step 2. Install PMS
Now, use the following command to install the DEB package we downloaded from the first step above.
sudo dpkg -i plex.tv/plex-media-server/1.13.9.5456-ecd600442/plexmediaserver_1.13.9.5456-ecd600442_amd64.deb
Step 3. Configure Plex Media Server
Now, open a web browser and type the following address. Change the IP address with your Ubuntu 18.04 IP address.
http://192.168.1.6:32400/manage



SSH Commands
Please don't forget to delete the info.php file when you don't need it anymore as it provides sensitive details of your server. Run the following command to delete the file.
rm -f /var/www/html/info.php
To stop SSH server execute:
$ sudo service ssh stop
To start SSH server execute:
$ sudo service ssh start
To restart SSH server execute:
$ sudo service ssh restart
To disable SSH server to start during boot execute:
$ sudo systemctl disable ssh
To enable SSH server to start during boot execute:
$ sudo systemctl enable ssh

Appendix A
List Your Network Interfaces.
In a terminal enter the following command :
$ ifconfig -a
You will see I have a network card called “enp3s3”. So I would then do the following :
$ sudo su
<enter root password>
# nano /etc/netplan/50-cloud-init.yaml
Copy and paste the following into the file. Paste exactly as listed : The exact listing is here. You need to copy / paste as listed on the link page. It doesnt get listed right here. I have a text file here. Copy all the text in the text file, and paste it into the netplan file.

The gateway IP is the ip link to my router, change this for your router ip address.

enp0s3 - This is the network card name. Do the ifconfig - a above, make a note of your network card, and change enp0s3 for your cards name.
DHCP4 is No as we don’t want dynamic, and below it is <addresses>. Ive set my static ip address to 192.168.1.100 and you MUST include the /24. You can set your static ip address to what ever you wish.

gateway4 is the ip address of your router. Change this to point to your own router.
Save the document and exit, then reboot. Your server will now have a static ip address.

Re-Installing Plex on Your Ubuntu Server, and it fails to find your media server.

Open a terminal and type the following commands, then reboot. Plex should then start.

sudo mkdir /var/lib/plexmediaserver/Library
sudo chmod 777 -R /var/lib/plexmediaserver/Library
service plexmediaserver restart

Meetings

We try to meet regularly in Newbury, either at the Retail Park, or at Costa Coffee in the town centre. Parking is our main concern for people wishing to turn up.

User Help Sessions

We try to help people with their questions, or know enough to Google and give advice on possible actions.

Live / Install Discs

We are happy to provide a live disc or help with installing a Distro onto your machines HDD. But try a live disc to see if you like it.