Can I figure out how to set up a website?


After completing the Linux Up Skill challenge (https://www.reddit.com/r/linuxupskillchallenge/), I have a web-facing Linode Linux VPS that I don't know what to do with. Why not try a new project?

Goal

update (Nov 21, 2021): (The site has been decommissioned)

Process

I searched for “selfhosted photo album”, reddit had one with 13 upvotes, called https://www.piwigo.org/

I looked at the 'discover' for two seconds and then decided to give it a try

Evaluate Piwigo

  1. SSH into machine
  2. Copy url to download
  3. Download the archive:
    • wget https://www.piwigo.org/download/dlcounter.php?code=latest
    • annoying problem: got a file with a bad name (I guess I should use -O), but figured it out:
  file dlcounter.php\?code\=latest  # Weird filename, use file to determine the actual type (zip archive)
  mv dlcounter.php\?code\=latest piwigo.zip # Move to a better name
  unzip piwgo # not sure why this worked without me typing ".zip", but it did

Look around the extracted contents. It seems like php stuff, with an 'install.php file'. Gonna configure a PHP stack with a mysql database and then try loading install.php in my browser (literally just assuming that's the right thing to do).

Configure my web server

Duckduckgo search for something about basic php server config, found this, digital ocean is reputable I think:

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-20-04

Find my public IP, to see if I still have apache correctly running from the skill up challenge:

 curl https://ipinfo.io/ip

I saved that into a script, because it tends to come up pretty often:

  echo curl https://ipinfo.io/ip ; echo > my_ip
  chmod +x my_ip 

Then install mysql server (weirdly big package, 250MB) and configure it to be secure

  sudo apt install mysql-server
  sudo mysql_secure_installation

Install PHP and some modules.

sudo apt install php libapache2-mod-php php-mysql

Next up, the instructions say to set up a virtual host?

Nah, apache is already working fine, maybe i'll come back to that when I want another site on this host.

For now, move everything to /var/www/html and try it

Piwigo encountered a non recoverable error

PHP extension "mysqli" is not loaded

Time for another more web searche That takes me to stackoverflow: https://stackoverflow.com/questions/54500881/how-do-i-enable-mysqli-for-my-php-script/54500903

Ok it says i need to edit php.ini, but where's that?

  locate php.ini

No results, need to update my locate database again (since i just installed php):

  sudo updatedb

Found it

  vim /etc/php/7.4/apache2/php.ini 

oops, read only

  sudo vim /etc/php/7.4/apache2/php.ini 

I'm supposed to add extension=php_mysqli.so, but actually it was already there, i just uncommented it.

How to restart a service again?

  history | grep apache

Okay, yeah

  sudo systemctl restart apache2

Success, PHP should be able to interact with MySQL now.

Next I need to create a database user for piwigo.

Search the web again “mysql cheat sheet”, 'create user' is one of the first things listed. I created a user called 'piwigo' and a database called 'lucy':

mysql> CREATE USER 'piwigo'@'localhost' IDENTIFIED BY '<redacted>';
Query OK, 0 rows affected (0.07 sec)

mysql> CREATE DATABASE lucy
    -> ;
Query OK, 1 row affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON * . * TO 'piwigo'@'localhost';
Query OK, 0 rows affected (0.01 sec)

Added those credentials to my password manager.

Entered credentials for admin and SQL users in the Piwigo admin setup console. Next, another error:

    GD library is missing

Searched the web again and this was simple, I just needed to install another package:

sudo apt install php-gd

Next error, when exiting the admin panel.

Fatal error: Uncaught Error: Call to undefined function mb_substr() in /var/www/html/admin/intro.php:354 Stack trace: #0 /var/www/html/admin.php(298): include() #1 {main} thrown in /var/www/html/admin/intro.php on line 354

https://www.php.net/manual/en/mbstring.installation.php

I remember this from somewhere. “mbstring” is PHP's multi-byte string module.

Fixed with sudo apt install php-mbstring

next steps

Subdomain

instead of buying a new domain, can i just set up a subdomain? searched “how to add a subdomain” got this https://www.godaddy.com/help/create-a-subdomain-4080#smhvid

Very simple, just needed to add another A record in the DNS config.

tested by visiting the site and it works! i still need an SSL cert tho.

TLS (https)

let's do let's encrypt certbot https://certbot.eff.org/lets-encrypt/ubuntufocal-apache

This was SO easy

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/lucy.dominicds.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/lucy.dominicds.com/privkey.pem
   Your certificate will expire on 2021-06-02. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again with the "certonly" option. To non-interactively
   renew *all* of your certificates, run "certbot renew"

Conclusion

At this point, the server is up and running with Piwigo. Next, I created an administrator account, stripped metadata from my pictures (using exiftool), and uploaded them. After that, a bit of admin panel configuration tweaking, added a new favicon, and that's it.