I wanted to try Flarum for the longest time but simply did not have the skills to install it. Time and time again I would try but I would get stuck at various points and just give up out of pure frustration.
Yesterday, I finally got Flarum installed and I was over the moon with excitement and a sense of accomplishment! After playing in the admin panel for the better part of the last 2 days, I thought I'd share my install method so others that have been wanting to try Flarum can finally get to do so.
This guide is for installing Flarum on a DigitalOcean LAMP Server on Ubuntu 14.04
A: I am a total newbie, and have written this how-to article simply to help other newbies having difficulty installing Flarum. This guide will take you through the installation process that (finally) worked for me.
B: There might be some bad info here. I am not a security expert, so I take no responsibility if anything ‘bad’ happens to your Flarum installation.
C: This installation guide assumes you are using Flarum in a test environment.
D: I am hoping some experienced members can look through this and offer any suggestions or correct any errors or bad advice I might have given.
Ok, let’s get cracking!
- SETTING UP YOUR DIGITALOCEAN DROPLET
Create an account on DigitalOcean. Login in with your username and password and create a new Droplet.
Click on One-click Apps and select LAMP on 14.04. I chose the $10/month option since I don’t know if the $5 setup will suffice or not. Select the geographical area that best suits your community (I use San Francisco). At the bottom where it says ‘Select Additional Options’ I normally select the first three (3) checkboxes.
- CONNECTING TO YOUR DROPLET VIA SSH
Check your email for the DigitalOcean account info that was sent to you and copy the password.
Open up your terminal app (if you’re on a Mac) or download and install Putty (for Windows users) and connect to your server. On a Mac type the following into the terminal:
Hit Command+V (or CTRL+V for Windows) to paste the password you copied earlier
Hit Command+V again (or CTRL+V for Windows)
Type your new root password
Type your new root password again
NOTE: You will see your server’s MOTD (message of the day). Write down the MySQL password as you will need it later. If you lose it you can always logout and login again to see the MOTD and password.
- CREATE A NEW USER
(this will create a new user called flarum; change it to your liking if you want to use a different name).
You will be asked to enter and confirm a password for this user (just hit Enter for the rest of the questions).
Now we must give our new user sudo privileges:
Search for the following line:
root ALL=(ALL:ALL) ALL
Enter your new user directly below so it looks like this (here, I will do it for my newly created ‘flarum’ user)
root ALL=(ALL:ALL) ALL
flarum ALL=(ALL:ALL) ALL
Type Ctrl+X to exit and then type Y (to save the changes) then hit Enter once more to exit the Vi editor.
Now, your new user is able to execute commands with administrative privileges. Let's logout of the root account:
- LOGIN WITH NEW USER ACCOUNT
(if you chose different name for your newly created user then use it instead of flarum)
- UPDATING UBUNTU
sudo apt-get update && sudo apt-get upgrade
(you might be asked to enter the password you set for this new user)
- SETTING A SWAPFILE & TWEAKS
The DigitalOcean Droplet we create will not come with a swapfile by default, so we will add one and make a couple other adjustments.
Let’s create the file first. Here, we will be creating a 2GB file:
sudo fallocate -l 2G /swapfile
Now we enable the file:
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Now we make the swapfile permanent:
sudo nano /etc/fstab
At the bottom of the file add the following line:
/swapfile none swap sw 0 0
Type CTRL+X to exit the editor, then hit Y to save the changes, and hit Enter again to exit.
We can also make a couple tweaks:
sudo sysctl vm.swappiness=10
sudo sysctl vm.vfs_cache_pressure=50
Now we make the above 2 tweaks permanent:
sudo nano /etc/sysctl.conf
At the bottom of the file add the following 2 lines:
Hit CTRL+X to exit, then hit Y to save and hit Enter again to exit.
- ENABLE APACHE MOD REWRITE
sudo a2enmod rewrite
(you might have to enter your user password)
Now we must restart Apache:
sudo service apache2 restart
Now we edit the default VirtualHost to use mod_rewrite from within .htaccess files:
sudo nano /etc/apache2/sites-available/000-default.conf
Search for “DocumentRoot /var/www/html” and add the following lines directly below it:
Hit CTRL+X to exit, then Y to save, and Enter to close the editor. Now we must restart Apache:
sudo service apache2 restart
- INSTALLING COMPOSER (GLOBALLY)
sudo curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
- INSTALLING FLARUM
I am hoping for some input from experienced members on this part because I don’t know if I’m doing this right or not, but it seems to get the job done.
Navigate to your web directory:
You will notice there are two (2) files in this folder, index.html and info.php. For reasons unknown to me, Flarum will not install into a folder that is not empty, so I delete these 2 files. However, before I delete them I first connect to my server via FTP and download the files to my computer just in case I need them in the future.
sudo rm index.html
sudo rm info.php
Now let’s install Flarum:
sudo composer create-project flarum/flarum . --stability=beta
You will notice the Flarum installer has paused and is waiting for your Token.
Notice the web address at the bottom of the terminal window? Well, you need to go to that address in your browser, however, if you don’t have a GitHub account you will need to create one first. Once you have your GitHub account, paste the address into your browser. Do not change any settings, just click the 'Generate Token" at the bottom of the screen and copy/paste it into the terminal and hit enter to finish with the Flarum installer.
Note: you should copy/paste the token into a text file for future safe keeping.
Now you can access your Flarum installation by typing your.servers.ip.address in your browser:
Uh oh, we have problems! Looks like we have issues with directory permissions.
Don’t panic, you’re almost home!
- DIRECTORY PERMISSIONS
We still need to make a couple more changes before we can successfully access the Flarum admin panel.
First, we need to give ownership of the following folders to Apache (known as the www-data user to the Operating System):
sudo chgrp www-data /var/www/html
sudo chgrp -R www-data /var/www/html/assets
sudo chgrp -R www-data /var/www/html/extensions
sudo chgrp -R www-data /var/www/html/storage
sudo chmod 775 /var/www/html
sudo chmod -R 775 /var/www/html/assets
sudo chmod -R 775 /var/www/html/extensions
sudo chmod -R 775 /var/www/html/storage
- FLARUM SETUP
Now refresh the page in your web browser and you will see the directory issues have been solved.
Woohoo, you did it!
- MYSQL SETUP
Not so fast, you still have a couple steps to go! You will notice that MySQL info is required. We will need to access the MySQL shell to create a database. First, we secure MySQL:
Type your root password when prompted. Now you will see: "You already have a root password set, so you can safely answer 'n'."
Enter n to not change the MySQL root password
Enter Y for the next question(s)
Now we access the MySQL shell:
mysql -u root -p
You are asked for your MySQL root password (this is NOT the root user password). Remember the password you wrote down way back at the end of Section 2? Now enter that password and hit Enter. If you didn’t write it down simply logout of your server and login again to see the MOTD (message of the day) along with your MySQL password. There is likely a faster way to show the MOTD but I am unaware of it.
Let’s see the databases already installed:
You will see the following three (3) default databases. I have no idea whether they should be removed or not so I just leave them alone.
Let’s create our database. I’m going to call mine ‘flarum’:
CREATE DATABASE flarum;
If you list the databases again you will see your new database:
Ok, let’s exit the MySQL shell:
Now go back to Section 10 and complete the setup:
Forum Title: Enter the name of your new forum.
MySQL Host: Leave this as the default (localhost)
MySQL Database: Enter your database name (in my example above I used flarum)
MySQL Username: root
MySQL Password: Enter the password you copied from your server’s MOTD at the end of Section 2
Table Prefix: I just use some descriptive identifier like myforum01_
Admin Username: admin (or whatever you like to use)
Admin Email: email for your admin account
Admin Password: the admin password you want to use