Here’s a fresh new guide on installing Flarum on shared hosting.
Step 1: Pick a good shared hosting provider
This is harder than it sounds because there are so many web hosts out there. But, you need a web host who offers SSH access and allows you to create a folder one level below your public files. (Sure, there are ways to get Flarum running without either of these but this tutorial is for the easiest and what I think is the best way.) A final tip on the web host if you are not a coder. Shop around for one that offers a nice, clean, modern interface for managing files. In other words, the old “cPanel” set up is OK and many people love it, but if you want Flarum because you are a creator/webmaster, not a coder, then you need a host who gives you features like: one click security settings, one click forced https, one click cache tools, one click this, one click that.
I know this is long winded so far but going with a good host is super important. If you’re not a developer, you should want a foolproof hosting set up. And, these types of hosts are typically very cheap for the first 1 to 3 years, then could be a little pricey but you are paying for everything to be done for you (almost). And, the more expensive hosts, sometimes, also offer faster, more secure, overall better services. Ok, someone hand me a ladder... this soapbox is huge. 🪜
Step 2: Create a folder outside of your public_html folder - but on the same level as your public_html folder. Think of this new folder as the hidden, eccentric introvert, and the public_html folder as the extrovert not afraid of showing the world everything. (public_html is the most common name a shared host gives this folder... it could be different for you.)
Go into your new web host’s nice and simple interface (because remember you shopped around and picked a good one) and go to the File Manager. You should see a public_html or public folder of some type. Don’t go into that folder yet. Just create a new folder (NOT IN THE public folder but on the same level, or outside of the public, however you say it 🤷♂️). Your quality shared host already has things set up so that this new folder will be hidden from the public (nice and secure). For tutorial purposes I will pretend you named this folder, “zero.”
To be clear, this means your File Manager directory tree now looks something like the below. Maybe not exactly. Your shared host might only have two levels. Or three. I don’t know. No one knows. But you. 🙂
- Level one that you can’t see because the shared host hides it
- Level two (maybe) that you can’t see
- Level with your new folder “zero” and public_html
Or, to put it another way:
- Account Name
- zero & public_html visible within same location
Zero is where you will put all of Flarum’s core files EXCEPT the “public” folder. That folder’s contents will be moved/copied to the public_html folder. But, we aren’t there yet. Forget I said that. Just go ahead to step 3.
Step 3: Get your SSH client set up. (Termius is great)
To download/install Flarum you will need to do it from a command line environment. More specifically you need to have a SSH client on you computer or device. I highly recommend Termius. It’s free and can be used on a smart phone or computer. Plus it looks nice.
Now you will open the SSH client like Termius, add a new host, and input the settings your web host gives you. This may require searching your web host’s FAQs and/or doing some web searches for tutorials. You will input the correct port, username and password. You will also need a key. You can copy the private key from your web host’s settings and paste it into the appropriate spot in the SSH client. Get connected.
Let’s pause and evaluate where we’re at...
So far we picked a great host with a foolproof interface. We added a folder outside of aka on the same level as the public_html folder, and we got the SSH connection all set up and connected using something like Termius. Now we are ready to install Flarum.
Step 4: Install with Composer
You already picked a great web host so they also have composer ready. In your command line tool like Termius, type:
Or, another way to put it is you are getting yourself pointed to that new folder you made, the one we named “zero.”
Next in the command like paste:
composer create-project flarum/flarum . --stability=beta
Watch all of the files download into that folder which you added outside of/on the same level as your public folder.
Step 5: Move Flarum public files to your “real” public folder (like public_html)
Now in your nice web host’s interface, go to the File Manager. Go into that new folder (hypothetically “zero”) and now you will see Flarum core. One of the folders is “Public.” Move the folders/files inside of “Public” to your real public area (many times public_html). My shared host has an easy copy/paste feature. I just copy everything in Flarum’s public folder and then paste it into my “real” public folder. Then you can delete that Flarum public folder. It won’t be needed since its files are in your actual public folder now.
Step 6: Adjust where site.php and index.php are pointing to
Now everything is where it needs to be but before you navigate to your site, you need to make sure that the site.php file in your “zero” folder (or whatever you named the folder) and the index.php file in your public_html folder (or whatever it’s called) are pointing to the right stuff. You can try it as-is, but in my experience, on shared hosting, it works best if you do something like the following:
In site.php, the vendor autoload line, make it point to the vendor folder which is in the same directory... I removed the beginning slash and the DIR which you will see in Flarum’s official install instructions. Maybe this isn’t always necessary. At some point it’s what worked for me, and so I stuck with it. In short, make that line:
Then the part down further which points to the main parts of Flarum will also need to be modified most likely. This varies depending on how your web host has their customers set up. But, just find out the direct, full path to your folders. For example, the first two folders you see below might not be obvious/visible. You might even have to ask your host what the full/direct path is. One way your code could end up looking is something like...
'base' => '/home/customer/youraccount/zero',
'public' => '/home/customer/youraccount/public_html',
'storage' => '/home/customer/youraccount/zero/storage',
So, above, the first two levels are just the way your host set things up (maybe) and then you are either pointing to that zero folder or your public folder.
Next, go to your public (public_html) folder and edit the index.php file. Here you just need to make sure you are pointing back to site.php correctly using a similar format as seen above (using a specific/direct/full path).
Step 7: Create the database and user
Again, since you picked a great host with a few clicks you will have the database set up. Do some web searches for how to do this or ask your host if needed. You will need the database name, username, and user password for the next step.
Step 8: Navigate to site and fill out install form
It’s all downhill from here. Go to your website. Fill in the Flarum install form with your database information and admin user credentials. Click install.
The page will redirect to your new Flarum forum. Congratulations!
Step 9: Add forced https and force either the WWW version or non-WWW version of your site by adding the appropriate rules to the public .htaccess file.
Your host probably has these instructions somewhere... or, search the web. Also, I’m realizing in the instructions above I never said to make sure you have a SSL certificate. But once again, if you picked a great host, you’ll have a free certificate either already installed or ready with a few clicks. This certificate is what makes your forum URL start with https instead of just http. It’s more secure. The whole www to non-www (or vice versa) .htaccess rule is a good best practice no matter what. Which ever way you choose, make sure the base url in Flarum’s config file matches (the www or non-www part). Whenever I do a Flarum installation on a shared host the config file is usually fine. But, it could need a tweak.
That’s about it. Best of luck to you!