I just recently had to migrate content to a new server and fresh install flarum beta 8. For that reason I have encountered a lot of strange problems and lack of information. I am not an expert or even a developer... I am just a student that has spent the last 3 days banging my head against the wall trying to understand this and I have figured it out how to do it and decided to spare some headaches and teach everyone.
What I want?
- be able to have multiple websites and apps on the same server
- run flarum smoothly
- try not to kill myself trying to make this work
I'll organize this tutorial in sections
- Setup the server
- Install Flarum
- SetUp Nginx
- Set up Database
- Throw a huge party and invite me 😂
1. Server
For this I used a 5€ droplet from DigitalOcean. Create a simple one and access it via ssh.
These are the requirements:
Using the root user lets install the nginx and create a new sudo user (because it is not recommended to do a lot in root... it might break your droplet).
apt-get update
apt-get install nginx
adduser username
usermod -aG sudo username
su - username
(change "username" to the name you want... it will ask you for a password and then information... you can skip the information by typing the key enter in all)
Install mysql
sudo apt-get install mysql-server
Install php in my case php 7.2
Search it online... it depends on the version
Install ALL the php extentions they ask
Now here is where it starts go get tricky. Besides the one they ask you have also to instal php-fpm for nginx to work properly.
sudo apt-get install php-xml php-gd php-json php-mbstring php-mysql php-fpm
Tokenizer is already included and the openssl should be as well but you can test it running php -i | grep -i openssl
and it should show amongst other things OpenSSL support => enabled.
I am writing this by memory or by serching online so some things might be miss typed... Correct me if I am wrong.
2. Install Flarum
First install composer
Download composer.phar
and then move it to the bin directory like this:
mv /path/to/file/composer.phar /usr/local/bin/composer
Install flarum
So now its time to install Flarum. Since I want to have multiple apps in the same server I have selected the directory /var/www
for all my apps. Each will be in its own folder inside that www/ folder. I've created a folder for flarum and install it.
sudo mkdir /var/www/flarum
cd /var/www/flarum
composer create-project flarum/flarum . --stability=beta
any question see the flarum tutorial: https://flarum.org/docs/install.html#installing
3. SetUp Nginx
Now is where my knowledge goes out of the window and my desire to take my own life begun. It took me 2 days to figure this out and understand how it works.
Nginx is the software that recives the http and https requests and points them to the right directory where the app or website files are located. One of my main goals was being able to have mutiple websites and apps on the same server and Nginx can do that. It is called Server Blocks and it is fairly easy to understand but confusing to implement.
You have to create a .conf file in the sites-available/
folder for every website or app (in my case located in /etc/nginx/sites-available
). When Nginx recieves an http or https request it will search in all of these files for the one that it corresponds to. Each .conf file will represent one app and will have information like the domain expected for the app and location of the files in the server.
Create the new .conf file:
sudo nano /etc/nginx/sites-available/flarum.conf
this will open a text editor where you can insert the code.
My .conf file looks like this (and is named flarum.conf):
server {
listen 80;
listen [::]:80;
root /var/www/flarum/public;
index index.php index.html index.htm;
server_name example.com;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
include /var/www/flarum/.nginx.conf;
}
Change any necessary details like the "example.com" and "root /var/www/flarum;" and include /var/www/flarum/.nginx.conf; if it is in other folder.
To save and exit the editor just do ctrl+x and then type "y" to save and enter.
Now we need to disable the default website of nginx and make our new flarum website enabled:
sudo rm /etc/nginx/sites.enabled/default
sudo ln -s /etc/nginx/sites-available/flarum.conf /etc/nginx/sites-enabled/
By now the domain should be working.
4. Create DataBase
Ok so it should be all working but you need a database and a user to give to flarum so it can finish the installation and start looking like a proper website.
For this we need to first create the database.
Switch to the root user and access mysql:
su - root
mysql -u root -p
you might need to type the root password
Then lets create the database, user and assign premissions
CREATE DATABASE flarumdb;
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON flarumdb.* To 'newuser'@'localhost';
exit
I named the databased flarumdb...
Replace newuser and password with whatever you want but leave the '' there!!!! This user is only for flarum so the password can be a random combination of letters and numbers
Party like there is no tomorrow
Ok by now everything should be working and you have a database and a user with privileges to that database.
Access the domain and finish the setup of flarum.
I have written all this by memmory and with a little of googl help so there might be mistakes and maybe things missing... I have done this but not while I typed so please correct me if there is anything wrong. The more you correct me the easier it will be for the next guy trying to install it 😉
PS: If you want I can make a tutorial on migrating to a new server and other things like that