Skip to content

Commit cc47487

Browse files
askvortsov1funkeyedavwheat
authored
Add composer guide, "how to update" docs. Improve a few other articles. (#194)
Co-authored-by: Daniel <6577746+funkeye@users.noreply.github.com> Co-authored-by: David Wheatley <hi@davwheat.dev>
1 parent 8f5b9d2 commit cc47487

File tree

8 files changed

+313
-13
lines changed

8 files changed

+313
-13
lines changed

docs/.vuepress/config/locales/en/sidebar.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ module.exports = {
9292
title: 'Setting Up',
9393
collapsable: false,
9494
children: [
95+
'composer',
9596
'install',
9697
'update',
9798
'troubleshoot'
@@ -109,6 +110,13 @@ module.exports = {
109110
'mail',
110111
'console'
111112
]
113+
},
114+
{
115+
title: 'Advanced',
116+
collapsable: false,
117+
children: [
118+
'extenders'
119+
]
112120
}
113121
],
114122
}

docs/composer.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
2+
# Composer
3+
4+
Flarum uses a program called composer[Composer](https://getcomposer.org) to manage its dependencies and extensions.
5+
You'll need to use composer if you want to:
6+
7+
- Install or update Flarum
8+
- Install, update, or remove Flarum extensions
9+
10+
This guide is provided as a brief explanation of Composer. We highly recommend consulting the [official documentation](https://getcomposer.org/doc/00-intro.md) for more information.
11+
12+
::: tip Composer v2
13+
Historically, Composer has caused issues on shared hosting due to huge memory use. In 2020, [Composer v2 was released](https://blog.packagist.com/composer-2-0-is-now-available/) with massive performance and memory usage improvements that eliminate these problems. Make sure your server is using Composer v2!
14+
:::
15+
16+
## What is Composer?
17+
18+
> Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. — [Composer Introduction]([https://getcomposer.org/doc/00-intro.md](https://getcomposer.org/doc/00-intro.md))
19+
20+
Each Flarum installation consists primarily of Flarum core and a set of [extensions](extensions.md).Each of these has its own dependencies and releases.
21+
22+
Back in the day, forum frameworks would manage extensions by having users upload zip files with the extension code. That seems simple enough, but issues quickly become evident:
23+
24+
- Uploading random zip files from the internet tends to be a bad idea. Requiring that extensions be downloaded from a central source like [Packagist](https://packagist.org/) makes it somewhat more tedious to spam malicious code, and ensures that source code is available on GitHub for free/public extensions.
25+
- Let's say Extension A requires v4 of some library, and Extension B requires v5 of that same library. With a zip-based solution, either one of the two dependencies could override the other, causing all sorts of inconsistent problems. Or both would attempt to run at once, which would cause PHP to crash (you can't declare the same class twice).
26+
- Zip files can cause a lot of headache if trying to automate deployments, run automated tests, or scale to multiple server nodes.
27+
- There is no good way to ensure conflicting extension versions can't be installed, or that system PHP version and extension requirements are met.
28+
- Sure, we can upgrade extensions by replacing the zip file. But what about upgrading Flarum core? And how can we ensure that extensions can declare which versions of core they're compatible with?
29+
30+
Composer takes care of all these issues, and more!
31+
32+
## Flarum and Composer
33+
34+
When you go to [install Flarum](install.md#installing), you're actually doing 2 things:
35+
36+
1. Downloading a boilerplate "skeleton" for Flarum. This includes an `index.php` file that handles web requests, a `flarum` file that provides a CLI, and a bunch of web server config and folder setup. This is taken from the [`flarum/flarum` github repository](https://github.com/flarum/flarum), and doesn't actually contain any of the code necessary for Flarum to run.
37+
2. Installing `composer` packages necessary for Flarum, namely Flarum core, and several bundled extensions. These are called by the `index.php` and `flarum` files from step 1, and are the implementation of Flarum. These are specified in a `composer.json` file included in the skeleton.
38+
39+
When you want to update Flarum or add/update/remove extensions, you'll do so by running `composer` commands. Each command is different, but all commands follow the same general process:
40+
41+
1. Update the `composer.json` file to add/remove/update the package.
42+
2. Do a bunch of math to get the latest compatible versions of everything if possible, or figure out why the requested arrangement is impossible.
43+
3. If everything works, download new versions of everything that needs to be updated. If not, revert the `composer.json` changes
44+
45+
When running `composer.json` commands, make sure to pay attention to the output. If there's an error, it'll probably tell you if it's because of extension incompatibilities, an unsupported PHP version, missing PHP extensions, or something else.
46+
47+
### The `composer.json` File
48+
49+
As mentioned above, the entire composer configuration for your Flarum site is contained inside the `composer.json` file. You can consult the [composer documentation](https://getcomposer.org/doc/04-schema.md) for a specific schema, but for now, let's go over an annotated `composer.json` from `flarum/flarum`:
50+
51+
```jsonc
52+
{
53+
// This following section is mostly just metadata about the package.
54+
// For forum admins, this doesn't really matter.
55+
"name": "flarum/flarum",
56+
"description": "Delightfully simple forum software.",
57+
"type": "project",
58+
"keywords": [
59+
"forum",
60+
"discussion"
61+
],
62+
"homepage": "https://flarum.org/",
63+
"license": "MIT",
64+
"authors": [
65+
{
66+
"name": "Flarum",
67+
"email": "info@flarum.org",
68+
"homepage": "https://flarum.org/team"
69+
}
70+
],
71+
"support": {
72+
"issues": "https://github.com/flarum/core/issues",
73+
"source": "https://github.com/flarum/flarum",
74+
"docs": "https://flarum.org/docs/"
75+
},
76+
// End of metadata
77+
78+
// This next section is the one we care about the most.
79+
// It's a list of packages we want, and the versions for each.
80+
// We'll discuss this shortly.
81+
"require": {
82+
"flarum/core": "^0.1.0",
83+
"flarum/approval": "^0.1.0",
84+
"flarum/bbcode": "^0.1.0",
85+
"flarum/emoji": "^0.1.0",
86+
"flarum/lang-english": "^0.1.0",
87+
"flarum/flags": "^0.1.0",
88+
"flarum/likes": "^0.1.0",
89+
"flarum/lock": "^0.1.0",
90+
"flarum/markdown": "^0.1.0",
91+
"flarum/mentions": "^0.1.0",
92+
"flarum/nicknames": "^0.1.0",
93+
"flarum/pusher": "^0.1.0",
94+
"flarum/statistics": "^0.1.0",
95+
"flarum/sticky": "^0.1.0",
96+
"flarum/subscriptions": "^0.1.0",
97+
"flarum/suspend": "^0.1.0",
98+
"flarum/tags": "^0.1.0"
99+
},
100+
101+
// Various composer config. The ones here are sensible defaults.
102+
// See https://getcomposer.org/doc/06-config.md for a list of options.
103+
"config": {
104+
"preferred-install": "dist",
105+
"sort-packages": true
106+
},
107+
108+
// Since Flarum is still in beta, this tells composer that it's ok
109+
// to install beta packages. Once a stable version is tagged, this
110+
// line can be removed.
111+
"minimum-stability": "beta",
112+
113+
// If composer can find a stable (not dev, alpha, or beta) version
114+
// of a package, it should use that. Generally speaking, production
115+
// sites shouldn't run beta software unless you know what you're doing.
116+
"prefer-stable": true
117+
}
118+
```
119+
120+
Let's focus on that `require` section. Each entry is the name of a composer package, and a version string.
121+
To read more about version strings, see the relevant [composer documentation](https://semver.org/).
122+
123+
For Flarum projects, there's several types of entries you'll see in the `require` section of your root install's `flarum/core`:
124+
125+
- You MUST have a `flarum/core` entry. This should have an explicit version string corresponding to the major release you want to install. For Flarum beta versions, this would be `^0.1.0`.
126+
- You should have an entry for each extension you've installed. Some bundled extensions are included by default (e.g. `flarum/tags`, `flarum/suspend`, etc), [others you'll add via composer commands](extensions.md). Unless you have a reason to do otherwise (e.g. you're testing a beta version of a package), we recommend using an asterisk as the version string for extensions (`*`). This means "install the latest version compatible with my flarum/core".
127+
- Some extensions / features might require PHP packages that aren't Flarum extensions. For example, you need the guzzle library to use the [Mailgun mail driver](mail.md). In these cases, the instructions for the extension/feature in question should explain which version string to use.
128+
129+
## How to install Composer?
130+
131+
As with any other software, Composer must first be [installed]([https://getcomposer.org/download/) on the server where Flarum is running. There are several options depending on the type of web hosting you have.
132+
133+
### Dedicated Web Server
134+
135+
In this case you can install composer as recommended in the Composer [guide]([https://getcomposer.org/doc/00-intro.md#system-requirements)
136+
137+
### Managed / Shared hosting
138+
139+
If Composer is not preinstalled (you can check this by running `composer --version`), you can use a [manual installation](https://getcomposer.org/composer-stable.phar). Just upload the composer.phar to your folder and run `/path/to/your/php7 composer.phar COMMAND` for any command documented as `composer COMMAND`.
140+
141+
::: danger
142+
Some articles on the internet will mention that you can use tools like a PHP shell. If you are not sure what you are doing or what they are talking about - be careful! An unprotected web shell is **extremely** dangerous.
143+
:::
144+
145+
## How do I use Composer?
146+
147+
You'll need to use Composer over the **C**ommand-**l**ine **i**nterface (CLI). Be sure you can access your server over **S**ecure **Sh**ell (SSH).
148+
149+
Once you have Composer installed, you should be able to run Composer commands in your SSH terminal via `composer COMMAND`.
150+
151+
::: Optimizations
152+
After most commands, you'll want to run `composer dump-autoload -a`. Essentially, this caches PHP files so they run faster.
153+
:::
154+
155+
## I don't have SSH access
156+
157+
Most decent hosts should provide SSH access for shared hosting. If your host doesn't (and you can't switch to a good host that does offer it), hope might not yet be lost. You have several options:
158+
159+
- Use alternatives like [Pockethold](https://github.com/UvUno/pockethold) to install Flarum. Note that you'll still need composer (and SSH) to install extensions.
160+
- Install composer on your computer, and run the `install` command locally. Then upload the files via FTP to your host. To make modifications (updating Flarum, installing/updating/removing extensions), download the current versions of the files, run whatever composer commands you need locally, and then replace the `composer.json` and `composer.lock` files, and the `vendor` directory of your install with your local copy. Make sure to create backups before doing this!
161+
- Some web hosts might provide a GUI for managing composer. The command line version is generally preferably, but if a GUI is the only possibility, consult your host's documentation for information on how to use it.
162+
163+
Note that these workarounds are not officially supported! The only officially supported way to install and manage Flarum is through Composer.

docs/extenders.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Local Extenders
2+
3+
If there are customizations you want to make to your site without distributing an entire extension, you can do so by using **local extenders**. Each Flarum installation comes with an `extend.php` file where you can add extender instances, just like in a full extension.
4+
5+
See our [extension documentation](extend/start.md) for more information about extenders (and even an [example of a local extender](extend/start.md#hello-world)).
6+
7+
If you need to create new files (when adding a custom class to be imported for extenders), you'll need to adjust your composer.json a bit.
8+
Add the following:
9+
10+
```json
11+
"autoload": {
12+
"psr-4": {
13+
"App\\": "app/"
14+
}
15+
},
16+
```
17+
18+
Now you can create new PHP files in an `app` subdirectory using the `App\...` namespace.
19+
20+
::: tip Local Extenders vs Extensions
21+
Local extenders can be good for small tweaks, but if you need large customizations, an extension might be a better choice:
22+
a separate codebase, cleaner handling of many files, developer tooling, and the ability to easily open source are big benefits.
23+
:::

docs/extensions.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ Flarum has a wide ecosystem of extensions, most of which are open source and fre
1616
Just like Flarum, extensions are installed through [Composer](https://getcomposer.org), using SSH. To install a typical extension:
1717

1818
1. `cd` to your Flarum directory. This directory should contain `composer.json`, `flarum` files and a `storage` directory (among others). You can check directory contents via `ls -la`.
19-
2. Run `composer require COMPOSER_PACKAGE_NAME`. This should be provided by the extension's documentation.
19+
2. Run `composer require COMPOSER_PACKAGE_NAME:*`. This should be provided by the extension's documentation.
20+
21+
## Updating Extensions
22+
23+
Follow the instructions provided by extension developers. If you're using `*` as the version string for extensions ([as is recommended](composer.md)), running the commands listed in the [Flarum upgrade guide](update.md) should update all your extensions.
24+
25+
## Uninstalling Extensions
26+
27+
Similarly to installation, to remove an extension:
28+
29+
0. If you want to remove all database tables created by the extension, click the "Uninstall" button in the admin dashboard. See [below](#managing-extensions) for more information.
30+
1. `cd` to your Flarum directory.
31+
2. Run `composer remove COMPOSER_PACKAGE_NAME:*`. This should be provided by the extension's documentation.
2032

2133
## Managing Extensions
2234

docs/faq.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,4 @@ Yes, but not for a while. Our focus right now is on getting Flarum stable and fe
4242
4343
The real answer is that we generally keep an eye on our community for stand-out members who would make good staff. Honestly, for most of our current staff, what they did before becoming staff wasn't much different from what they do now.
4444

45-
Find a passion and contribute however you feel is best. Then let it take its course. You don't have to have a badge to be respected here.
46-
47-
<!--
48-
### Why does Flarum use Composer? Why can't I just download a ZIP?
49-
https://github.com/flarum/docs/issues/20
50-
-->
45+
Find a passion and contribute however you feel is best. Then let it take its course. You don't have to have a badge to be respected here.

docs/install.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ Before you install Flarum, it's important to check that your server meets the re
2020
* **SSH (command-line) access** to run Composer
2121

2222
::: tip Shared Hosting
23-
At this stage, it's not possible to install Flarum by downloading a ZIP file and uploading the files to your web server. This is because Flarum uses a dependency-management system called [Composer](https://getcomposer.org) which needs to run on the command line.
23+
It's not possible to install Flarum by downloading a ZIP file and uploading the files to your web server. This is because Flarum uses a dependency-management system called [Composer](https://getcomposer.org) which needs to run on the command line.
2424

25-
This doesn't necessarily mean you need a VPS. Some shared hosts give you SSH access, through which you should be able to install Composer and Flarum just fine. For other hosts without SSH, you can try workarounds such as [Pockethold](https://github.com/andreherberth/pockethold).
25+
This doesn't necessarily mean you need a VPS. Most decent hosts support SSH access, through which you should be able to install Composer and Flarum just fine.
2626
:::
2727

2828
## Installing
2929

30-
Flarum uses [Composer](https://getcomposer.org) to manage its dependencies and extensions. Before installing Flarum, you will need to [install Composer](https://getcomposer.org) on your machine. Afterwards, run this command in an empty location that you want Flarum to be installed in:
30+
Flarum uses [Composer](https://getcomposer.org) to manage its dependencies and extensions. If you're not familiar with it, read [our guide](composer.md) for information on what it is and how to set it up. Afterwards, run this command in an empty location that you want Flarum to be installed in:
3131

3232
```bash
3333
composer create-project flarum/flarum . --stability=beta

docs/troubleshoot.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Next, you should take a few minutes to search the [Support forum](https://discus
66

77
## Step 0: Turn on debug mode
88

9+
::: danger Skip on Production
10+
These debugging tools are very useful, but can expose information that shouldn't be public.
11+
These are fine if you're on a staging or development environment, but if you don't know what you're doing, skip this step when on a production environment.
12+
:::
13+
914
Before you proceed, you should enable Flarum's debugging tools. Simply open up **config.php** with a text editor, change the `debug` value to `true`, and save the file. This will cause Flarum to display detailed error messages, giving you an insight into what's going wrong.
1015

1116
If you've been seeing blank pages and the above change doesn't help, try setting `display_errors` to `On` in your **php.ini** configuration file.
@@ -18,7 +23,8 @@ A lot of issues can be fixed with the following:
1823
* Clear the backend cache with [`php flarum cache:clear`](console.md).
1924
* Make sure your database is updated with [`php flarum migrate`](console.md).
2025
* Ensure that the [email configuration](mail.md) in your admin dashboard is correct: invalid email config will cause errors when registering, resetting a password, changing emails, and sending notifications.
21-
* Check that your `config.php` is correct. For instance, make sure that the right `url` is being used.
26+
* Check that your `config.php` is correct. For instance, make sure that the right `url` is being used (`https` vs `http` and case sensitivity matter here!).
27+
* One potential culprit could be a custom header, custom footer, or custom LESS. If your issue is in the frontend, try temporarily removing those via the Appearance page of the admin dashboard.
2228

2329
You'll also want to take a look at the output of [`php flarum info`](console.md) to ensure that nothing major is out of place.
2430

@@ -38,7 +44,7 @@ If it looks like you're going to need help solving the problem, it's time to get
3844
* Displayed in the browser console (Chrome: More tools -> Developer Tools -> Console)
3945
* Recorded in the server's error log (e.g. `/var/log/nginx/error.log`)
4046
* Recorded in PHP-FPM's error log (e.g. `/var/log/php7.x-fpm.log`)
41-
* Recorded by Flarum (`storage/logs/flarum.log`)
47+
* Recorded by Flarum (`storage/logs`)
4248

4349
Copy any messages to a text file and jot down a few notes about *when* the error occurred, *what* you were doing at the time, and so on. Be sure to include any insights you may have gleaned about the conditions under which the issue does and doesn't occur. Add as much information as possible about your server environment: OS version, web server version, PHP version and handler, et cetera.
4450

0 commit comments

Comments
 (0)