Skip to main content

Part 2 - Installing Linux Apache, MySQL and PHP (LAMP) on your VPS

In Part 1 - Creating a website on your VPS we learned about the possibility of setting up a website on our VPS.

You have your VPS set up properly and you registered a domain.

New site user

In order to keep our website privileges separate from Plex, we could create a new user for maintaining the website. You can skip this if you want to use your regular Plex user, but for added security I would definitely recommend creating a separate user.

First, start a PuTTY session and login as yourusername that you created in Part 2 of the Plex tutorial (in that tutorial we used plexuser).

If you want to keep using that account for your website, you can skip to the next subheading (Install LAMP and allow in firewall). If you prefer to create a new user, read on.

You will need to switch to root:

sudo -s

Think of a username you want to use for your site maintainance. Then type:

adduser yoursiteusername

Where yoursiteusername is the name you are going to use to maintain your site. I picked siteuser as my username.

Follow the prompts as you did before, then give your user sudo privileges:

usermod -aG sudo yoursiteusername

Then enter

sudo visudo

Use the arrow keys on your keyboard to scroll to the bottom and add on a new line:

yoursiteusername ALL=(ALL) NOPASSWD:ALL

You will now have two users added to this file. It will look like this:

Save this file by hitting Ctrl-O, then Enter. Exit the editor by hitting Ctrl-X.

Exit the terminal now (just close the PuTTY window) and log back in with your brand new username and password. Make sure you see your newly created user before the green prompt, instead of your Plex user.

Install LAMP and allow in firewall

Let's install Linux Apache, MySQP and PHP (in case you wondered what LAMP stood for, well, now you saw the light). Type

sudo apt-get update

Wait for the prompt to come back, then type

sudo apt-get install lamp-server^

Answer "Y" to the question if you want to continue. Then hit Enter several times to finish the installation.

When done, we need to edit the config file:

sudo nano /etc/apache2/apache2.conf

Then scroll to the bottom of the file and add on a new line:

ServerName yournewdomain

Of course you need to replace yournewdomain with the one you registered in part 1.

I registered, so mine looks like this:

Save with Ctrl-O, then Enter. Exit with Ctrl-X.

Lastly, we'll adjust our firewall to allow Apache:

sudo ufw allow in "Apache Full"

Reload Apache:

sudo systemctl restart apache2

At this point, you should already be able to visit your brand new website and admire the default page.

So far, so good!

Configuring MySQL

We're not finished yet... MySQL is a dangerous tool in the hands of the wrong person, so first thing we'll do is secure it.

sudo mysql_secure_installation

It will ask you for a root password, but just press Enter - we haven't got a root password yet.

Next it will ask you if you want to set a root password, answer "Y". Use a password generator to create a really long, difficult and random password. Make sure you store it somewhere safe, you will need this password again in Part 4 and every time you need to perform database maintenance.

Type "Y" for removing anonymous users, "Y" for disallowing root login remotely, "Y" for removing the test database and "Y" for reloading the privilege tables. Pfew! We're safe!

You can now continue with Part 3 - Prerequisites to setup your domain.