Installing Flarum on Ubuntu 18.04

I am setting up a forum for sharing levels for my game Rabbit Escape, and I have decided to try and use Flarum, because it looks really usable and responsive, has features we need like liking posts and following authors, and I think it will be reasonably OK to write the custom features we want.

So, I want a dev environment on my local Ubuntu 18.04 machine, and the first step to that is a standard install.

Warning: at the time of writing the Flarum docs say it does not work with PHP 7.2, which is what is included with Ubuntu 18.04, so this may not work. (So far it looks OK for me.)

Here’s how I got it working:

sudo apt install \
    apache2 \
    libapache2-mod-php \
    mariadb-server \
    php-mysql \
    php-json \
    php-gd \
    php-tokenizer \
    php-mbstring \
    php-curl

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

# Get the next line from https://getcomposer.org/download/
# Don't copy it exactly!
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

mkdir $HOME/bin
php composer-setup.php --install-dir=$HOME/bin/ --filename=composer
rm composer-setup.php

cd /var/www/html
sudo mkdir flarum
sudo chown $(whoami) flarum

# Log out and in again here to get composer to be in your PATH
cd flarum
composer create-project flarum/flarum . --stability=beta

sudo chgrp -R www-data .
sudo chmod -R 775 .

sudo a2enmod rewrite 

Next I granted the permissions for Flarum’s .htaccess file to change settings by modifying /etc/apache2/apache2.conf and adding this after the existing <Directory entries:

<Directory "/var/www/html/flarum/">
    AllowOverride All
</Directory>

and restarted Apache:

sudo systemctl restart apache2

Now I created a database in MariaDB:

$ sudo mariadb
MariaDB [(none)]> CREATE USER flarumuser IDENTIFIED BY 'flarumpassword';
MariaDB [(none)]> CREATE DATABASE flarumdb;
MariaDB [(none)]> GRANT ALL ON flarumdb.* TO flarumuser;

and went to http://localhost/flarum in my browser, and entered these details:

MySQL host: localhost
MySQL database: flarumdb
MySQL user: flarumuser
MySQL password: flarumpassword
table prefix: flarum_

Admin user: admin
Admin email: <my email address>
Admin password: adminpassword

Once I typed all those correctly and submitted, I had to wait a while, and then after it printed some details I refreshed the page and saw a local Flarum ready to customise.

Next, I looked into how to get an extension development environment up and running.

If you want to find and share levels for Rabbit Escape, check up on our progress setting up the forum at https://artificialworlds.net/rabbit-escape/levels.

Changing the Docker daemon options in systemd on Ubuntu 15.04

Update: now documenting the better way, as described in issue 14513.

Update 2: I think this way is even better (works in Ubuntu 16.04, Docker 1.12.2, Reference: dockerd command line):

sudo -s -H
echo '{"insecure-registries":["myreg.example.com:5000"]}' > /etc/docker/daemon.json
exit
sudo service docker restart

End of update 2

On earlier versions of Ubuntu (14.04 and before), changing the command line options to the Docker daemon (e.g. to allow using an insecure private registry) was just a matter of editing /etc/default/docker and uncommenting the line starting with #DOCKER_OPTS=.

On Ubuntu 15.04, even though that file still exists, editing it does not have any effect, and I found it quite tricky to work out how to change Docker’s command line, so I wrote it up here.

I wanted to use an insecure private docker registry for Docker on Ubuntu 15.04, which uses systemd.

Under systemd, we must create a config file that overrides the default Docker command line by typing sudo systemctl edit docker. In the editor which pops up, type:

[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// --insecure-registry=myreg.example.com:5000

Note: the first “ExecStart=” line is necessary.

The second “ExecStart=” line should contain whatever command line options you want to include.

Note: for docker versions before 1.10, replace “daemon” with “-d”.

With this config in place, restart the Docker service:

$ sudo systemctl restart docker

Check everything looks right for the Docker service:

$ systemctl status docker

And confirm the command line arguments have been applied with:

$ ps axwww | grep /usr/bin/docker

The instructions here: Control and configure Docker with systemd and issues: 14513 and 15859 suggest that the Docker team are not planning to make this any easier in the short term.

Docker fails to start on Ubuntu 15.04

I installed Docker on Ubuntu 15.04 using:

wget -qO- https://get.docker.com/ | sh

as described at Install Docker on Ubuntu.

I added myself to the docker group:

sudo usermod -aG docker balaaman

Then I logged out and logged in again, and ran:

docker run hello-world

and saw this:

Cannot connect to the Docker daemon. Is 'docker -d' running on this host?

When I tried to start the Docker daemon like this:

sudo service docker start

I got this error:

Failed to start docker.service: Unit docker.service is masked.

Thanks to Yannick Lizzi on this thread I found this fix:

systemctl unmask docker.service
systemctl unmask docker.socket
systemctl start docker.service

After this, I logged out and logged in again (again) and “docker run hello-world” worked fine, and all was well.

Why I use Linux

I have used Linux at home for quite a few years, and a couple of years ago I changed my work machine from Windows to Ubuntu Linux. It’s made life at work better for me.

Better for me

This move has made me much more productive, saving valuable time and money. Here is why:

Security updates happen automatically, without hitches, and rarely requiring reboots.

Since I changed, security updates are applied almost as soon as they are made available with no interaction from me. I have never seen a security upgrade that broke my system and prevented me working, whereas before I saw this several times.

My computer works faster.

My computer feels much faster to work with. In recent tests for our project, we found that the time spent waiting for a compile on my Linux machine was half that spent waiting on an identical system using Windows.

I work faster.

Because my system is more customisable than before, I can work the way that feels more comfortable to me. Support for keyboard shortcuts is more comprehensive in Linux, and I can work using the keyboard for most things, which helps prevent recurrence of RSI, from which I have suffered in the past.

I can automate repetitive tasks.

It’s much easier to write small scripts on Linux for things that I do every day. This means I spend more time thinking about the work I have to do, instead of all the button-clicking required to do it.

I can have more programs open.

My computer now works comfortably simultaneously running 3 or 4 heavy corporate applications, at least 2 copies of Eclipse, Firefox with many tabs open, several Chrome windows, 3 text editor windows, a 1GB virtual machine and many other programs, without slowing down or crashing. When I used Windows I needed fewer programs open, but because Linux manages memory better and many of the programs are less memory-hungry, I can do more things at the same time.

I can use “virtual desktops”.

It’s hard to explain why until you’ve tried it, but virtual desktops are an incredibly addictive feature. I avoid neck strain by using a single monitor directly in front of me*, but I am able to have lots of separate work spaces and can switch very quickly between them. I use one desktop for email and instant messaging, another for the Internet, and several more for programming in different environments. Switching between them happens as fast as I can press the relevant keyboard shortcut. This is a killer feature of modern Linux desktops in my opinion.

[*Multiple-monitor setups are well-supported too, of course.]

Modern tools work better.

Modern software – especially programming software – is frequently developed on Linux, and has its “home” there, meaning it is easier to install and update than on other platforms. Examples include: Python, Node.js, Perl, Vim, Emacs, Bash and Ruby, all of which are much easier to use and install on Linux than on Windows.

Better for my company

Because I use Linux, my company saves time and money.

  • Administering machines is easier. I get Ubuntu and corporate security updates automatically through the built-in security update mechanisms. The corporate updates are maintained by volunteers at my work in their spare time.
  • It’s cheaper. There is no license fee to use Ubuntu, and no added-value version to buy. Support can be paid for from several companies, including the company behind Ubuntu, Canonical.
  • I am more productive. As explained above, I am able to do more work in the same time because I use Linux.