The following tutorial will allow you to install an extension on a shared hosting.
IMPORTANT : Please do a backup to the files you are going to modify. I am in no way responsible if you'll break anything. If you don't really know how to modify files using a FTP connection or using composer or... anything else, please stop here and wait for a future Flarum release that will allow installing extensions using a graphical interface.
Requirements :
- flarum
already on your local machine (the source code, it doesn't have to be installed)
- composer
installed locally
- a FTP account & client (Filezilla, etc...)
- 5 minutes ?
---------- [START] LATER EDIT ----------
This tutorial explains how to install an extension when you don't have the same extensions on the local and the remote installs.
If you have the exact same extensions on both installs, it's enough to copy the vendor
folder.
( thanks @luceos )
---------- [END] LATER EDIT ----------
That's all... So, let's do this :
Installing extension on a shared hosting
First step it will be to install the extension on your local machine (in your Flarum folder) using the command :
composer require [vendor]/[extension-name]
Once the extension successfully installed locally we'll then launch our FTP client, connect to our host and upload the folder created by the extension to the corresponding [vendor]
folder on the server.
Please be careful - some extension will also install dependencies - in this case you have to copy those folders too and, then, repeat the following steps for each [vendor]/[extension-name]
Now, once the extension files were copied to the server, we'll have to "tell" Flarum that we added a new extension. Normally, when running composer require
all these modifications are done by composer
.
For the following steps we'll copy/paste code from our local Flarum installation to the files on the server
We'll edit the following files :
1) vendor\composer\installed.json
You'll see at the end of the file a new { ... }
block like this :
} ,
{
"name": "ircmaxell/random-lib",
"version": "v1.2.0",
"version_normalized": "1.2.0.0",
...
...
}
You will have to copy all this block (please be careful at the comma that's between the new block and the previous one) to the vendor\composer\installed.json
file found on your server. You'll add the code block at the end of the file, before the ]
character.
2) vendor\composer\autoload_static.php
On the local copy of this file you're going to search [extension-name]
(or [vendor]
, but look carefully because you can have multiple extensions from the same vendor)
You'll find it in 2 places :
==> public static $prefixLengthsPsr4 = array(...)
Like this :
<?php
'D' =>
array (
...
'Davis\\Split\\' => 12,
...
),
==> public static $prefixDirsPsr4 = array (...)
Like this :
<?php
'Davis\\Split\\' =>
array (
0 => __DIR__ . '/..' . '/davis/flarum-ext-split/src',
),
Each of the occurrence must be copied in the "same" place on the vendor\composer\autoload_static.php
file on your server.
3) vendor\composer\autoload_psr4.php
Just for the autoload_static.php
file, we'll do a search for [extension-name]
or [vendor]
.
Here we're only going to find it on one line like this :
'Davis\\Split\\' => array($vendorDir . '/davis/flarum-ext-split/src'),
Same thing, copy it to the vendor\composer\autoload_psr4.php
file on your server.
That's all, now in your admin panel you can see and activate your newly added extension.
If you have any question please don't hesitate to ask...