Flarum is a new type of simple design discussion fora which is currently in beta version. Although beta, you can use for production purpose if you are not going to test new extensions. Here are the steps on how to install Flarum on Ubuntu 16.04 with Apache2 with required permissions, configuring SendGrid as SMTP Mail Server. We covered the parts which peoples commonly face as problems. Minimum 1 GB RAM need for practical reasons.
Steps On How To Install Flarum On Ubuntu 16.04 : First Create LAMP Server
Essentially we will build a LAMP Server with HTTP/2 support, then install Composer, then install Flarum. Skip to next sub header if you already running a LAMP or LEMP server. First update, upgrade and install Percona MySQL Server (we prefer Percona, you can use MariaDB or MySQL) :
1 2 3 4 5 6 7 8 | apt update apt upgrade apt-get install software-properties-common python-software-properties wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb sudo apt-get update sudo apt-get install percona-server-server-5.6 mysql_secure_installation |
Act accordingly to the options which will prompt you. Now login to MySQL server :
---
1 | mysql -u root -h localhost -p |
Then run the commands :
1 2 3 | CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'; CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'; CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'; |
Now we need to create a database, we are showing with root
user, you should create a user in production server :
1 2 3 4 5 | CREATE DATABASE flarum2017; GRANT SELECT,DELETE,INSERT,UPDATE ON *.* TO 'root'@'localhost'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'; FLUSH PRIVILEGES; SHOW DATABASES; |
Now install Apache2 :
1 2 3 4 5 6 | sudo add-apt-repository ppa:ondrej/apache2 sudo apt-get update sudo apt-get install apache2 a2enmod http2 sudo apt-get install curl git git |
Now we need to install PHP :
1 2 3 4 5 6 | apt-get -y install php7.0 libapache2-mod-php7.0 systemctl restart apache2 apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring php-gettext php7.0-bcmath systemctl restart apache2 apt-get -y install php7.0-opcache php-apcu systemctl restart apache2 |
Let us perform additional steps to configure Apache2 and Let’s Encrypt :
1 2 3 4 5 6 | a2enmod ssl systemctl restart apache2 a2ensite default-ssl systemctl restart apache2 apt-get -y install python-letsencrypt-apache apt-get -y install python-certbot-apache |
If your domain name is abhishekghosh.pro
, then run this :
1 | letsencrypt --apache -d abhishekghosh.pro -d www.abhishekghosh.pro |
Create a cron :
1 | crontab -e |
Add this entry at bottom to auto renew letsencrypt
:
1 | 0 1 * * * /usr/bin/letsencrypt renew &> /dev/null |
Now, perform minimum tweaks :
1 | nano /etc/apache2/mods-available/mpm_prefork.conf |
Change the config in this way :
1 2 3 4 5 6 7 8 | <IfModule mpm_prefork_module> StartServers 5 MinSpareServers 20 MaxSpareServers 40 MaxRequestWorkers 256 MaxConnectionsPerChild 4500 </IfModule> |
Open :
1 | nano /etc/php/7.0/apache2/php.ini |
At minimum change few settings like these :
1 2 3 | max_input_time = 30 error_reporting = E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR error_log = /var/log/php/error.log |
Activate these modules :
1 2 3 4 5 | sudo a2dismod mpm_event sudo a2enmod mpm_prefork sudo a2enmod headers sudo a2enmod rewrite sudo a2enmod expires |
Then run config test :
1 2 | apachectl -t sudo systemctl restart apache2.service |
1 2 | sudo chown -R www-data:www-data /var/www/html sudo find /var/www/html/ -type d -exec chmod g+s {} \; |
Your website should be accessible by HTTPS URL and able to process PHP.
Steps On How To Install Flarum On Ubuntu 16.04 : Next Install Composer
We need to install Composer to install, update Flarum and extensions of Flarum. If you are not used with Composer, only know that it is a tool to manage PHP dependencies and some PHP based web softwares and not going to disturb your existing running web application. Run these :
1 2 3 | cd ~ curl -sS https://getcomposer.org/installer -o composer-setup.php php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" |
You should get Installer verified
message. Now run :
1 | sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer |
If you run the command :
1 | composer |
You’ll understand that Composer is ready.
Install Flarum With Composer
Almost done, change directory to where you want to install Flarum, like :
1 | /var/www/html |
as on root with Apache2’s default FTP root or subdirectory like :
1 | /var/www/html/forum |
For new, fresh installation you must delete the default Apache2 file :
1 | rm /var/www/html/index.html |
Then run this command :
1 | composer create-project flarum/flarum . --stability=beta |
Create an .htaccess
file :
1 | nano .htaccess |
Unless it is subdirectory, you possibly will need :
1 2 3 | <Directory "/var/www/html"> AllowOverride All </Directory> |
You should have proper permission, if /var/www/html
is your location of Flarum run these :
1 2 3 4 5 6 7 8 | sudo chgrp www-data /var/www/html sudo chgrp -R www-data /var/www/html/assets sudo chgrp -R www-data /var/www/html/extensions sudo chgrp -R www-data /var/www/html/storage sudo chmod 775 /var/www/html sudo chmod -R 775 /var/www/html/assets sudo chmod -R 775 /var/www/html/extensions sudo chmod -R 775 /var/www/html/storage |
Now, if you point towards the URL on browser, you’ll get a Web UI where you will be instructed to CHMOD some directories with more open permission. Run those commands, fill the web form with database details and run the installer script. If you are getting error, they will be out of need more liberal permission.
Ask on Flarum about your error (if any) :
1 | https://discuss.flarum.org/ |
Configuring Mail Like With SendGrid
If you use service like SendGrid, these are correct settings :
1 2 3 4 5 6 | Driver : smtp Host : smtp.sendgrid.net Port : 587 Encryption : tls Username : apikey Password : |
Username will be apikey
and password is your real API key copied from SendGrid account.