How to Install Flarum Forum on Ubuntu 20.04
You’ll learn how to get a fresh Flarum instance up and running on a clean Ubuntu 20.04 machine, from installing PHP and MySQL to tweaking file permissions so the forum actually starts.
Prerequisites
- A non‑root user with sudo privileges (don’t run everything as root – it’s a security risk).
- At least 2 GB of RAM; Flarum is lightweight but a database server likes a bit more headroom.
- An active internet connection for pulling packages.
Set Up the Web Server and PHP
1. Update package lists
sudo apt update
Keeps your system from installing broken or outdated libraries.
2. Install Apache, MySQL, and PHP‑8.0
sudo apt install -y apache2 mysql-server php8.0 php8.0-mbstring php8.0-xml php8.0-curl php8.0-gd php8.0-zip composer
Composer is required later; we’ll get it as part of the PHP stack.
3. Enable required Apache modules
sudo a2enmod rewrite headers env
rewrite lets Flarum use pretty URLs, and headers is needed for some security headers that Flarum relies on.
4. Restart Apache
sudo systemctl restart apache2
Create a Database
1. Log into MySQL as root (or the root user you set up during installation).
sudo mysql -u root -p
2. Run these commands to create a new database and user:
CREATE DATABASE flarum CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'flarum_user'@'localhost' IDENTIFIED BY 'StrongPasswordHere'; GRANT ALL PRIVILEGES ON flarum.* TO 'flarum_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
Flarum will need a separate, dedicated database to avoid collisions with other sites.
Download and Configure Flarum
1. Create the web root directory
sudo mkdir /var/www/flarum sudo chown $USER:$USER /var/www/flarum
This keeps ownership under your regular user, which is safer than running Apache as root.
2. Navigate into it and pull the latest release with Composer
cd /var/www/flarum composer create-project flarum/flarum .
Observation: I’ve seen forums break on a fresh install when people skip this step and just copy files from a zip; Composer pulls in exactly the right versions of dependencies.
3. Create an Apache virtual host file (replace example.com with your domain or IP).
sudo nano /etc/apache2/sites-available/flarum.conf
Add:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/flarum/public
<Directory /var/www/flarum/public>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/flarum_error.log
CustomLog ${APACHE_LOG_DIR}/flarum_access.log combined
</VirtualHost>
4. Enable the site and reload Apache
sudo a2ensite flarum.conf sudo systemctl reload apache2
Final Touches and Security
1. Set proper permissions on storage directories – Flarum needs to write cache, logs, etc.
cd /var/www/flarum chmod -R 775 storage bootstrap/cache chown -R $USER:www-data storage bootstrap/cache
2. Run the installation wizard
Open a browser and go to http://example.com.
The web interface will ask for the database credentials you set up earlier, plus basic forum details.
Fill it out; once done, you’re good to go.
3. (Optional) Harden Apache – add an .htaccess snippet or use a reverse proxy.
I’ve seen 500 errors after a bad permission change; double‑check that the public/.htaccess is intact and that PHP isn’t throwing any warnings.
4. Keep everything updated
sudo apt upgrade -y composer update --no-dev
That’s it—your new Flarum forum should be live, running on a solid Ubuntu 20.04 stack. If you hit hiccups, check the Apache error log; it usually tells you exactly where things went off track.