How to install Elkarte on Ubuntu

ElkArte is a free, open source, and powerful forum software licensed with an open source BSD 3 clause license. It is a simple, lightweight, and easy-to-use forum software that allows you to create your forum community. Elkarte is specifically designed to give you all the features you need for a fully functional community forum right out of the box.

In this tutorial, we will show you how to install the Elkarte forum software on an Ubuntu 18.04 server.

Requirements

  • A server running Ubuntu 18.04.
  • A root password is set up on your server.

First steps

Before you start, you need to update your system to the latest version. You can do this by running the following command:

apt-get update -y
apt-get upgrade -y

Once your system is updated, reboot it to apply the changes.

Install Apache, PHP and MariaDB

Elkarte runs on a web server based on PHP and uses MySQL/MariaDB to store the data. Therefore, you need to install Apache, MariaDB server, PHP and other required packages in your system. You can install them all by running the following command:

apt-get install apache2 mariadb-server php7.2 libapache2-mod-php7.2 php7.2-common php7.2-curl php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-mysql php7.2-gd php7.2-pgsql php7.2-xml php7.2-cli php7.2-imagick php7.2-bcmath php7.2-gmp php7.2-zip git -y

When all packages are installed, open the php.ini file and change some settings:

nano /etc/php/7.2/apache2/php.ini

Change the following lines:

memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

Save and close the file when you are done. Then start the Apache and MariaDB services and enable them with the following command, so that they will be started after a system reboot:

systemctl start apache2
systemctl start mariadb
systemctl enable apache2
systemctl enable mariadb

When you are done with that, you can proceed to the next step.

Configure database for Elkarte

MariaDB is not backed up by default. Therefore, it is recommended to back it up first. You can backup it by running the following command:

mysql_secure_installation

This script sets up the root password, removes anonymous users, disallows remote root login, and removes the test database as shown below:

    Enter current password for root (enter for none):
    Set root password? [Y/n]: N
    Remove anonymous users? [Y/n]: Y
    Disallow root login remotely? [Y/n]: Y
    Remove test database and access to it? [Y/n]:  Y
    Reload privilege tables now? [Y/n]:  Y

Once the MariaDB is backed up, log into the MariaDB shell with the following command:

mysql -u root

Enter your root password and create a database and user for Elkarte using the following command:

MariaDB [(none)]> CREATE DATABASE elkdb;
MariaDB [(none)]> CREATE USER 'elkuser'@'localhost' IDENTIFIED BY 'password';

Next, grant all permissions to elkdb with the following command:

MariaDB [(none)]> GRANT ALL ON elkdb.* TO 'elkuser'@'localhost' WITH GRANT OPTION;

Clear the permissions and exit the MariaDB shell with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Install Elkarte

First you need to download the latest version of Elkarte from the official website. You can download it with the following command:

cd /var/www/html/
git clone https://github.com/elkarte/Elkarte.git

Next, give Elkarte the proper permissions with the following command:

chown -R www-data:www-data /var/www/html/Elkarte/
chmod -R 755 /var/www/html/Elkarte/

Once you are done with that, you can proceed to the next step.

Configure Apache for Elkarte

First you need to create a configuration file for the virtual Apache host for Elkarte. You can create it with the following command:

nano /etc/apache2/sites-available/elkarte.conf

Paste the following lines:

<VirtualHost *:80>
     ServerAdmin admin@example.com
     DocumentRoot /var/www/html/Elkarte
     ServerName example.com
     ServerAlias www.example.com

     <Directory /var/www/html/Elkarte/>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Save and close the file when you are done. Then enable the Apache virtual host and the rewrite module with the following command:

a2ensite elkarte.conf
a2enmod rewrite

Finally, restart the Apache service to apply the changes:

systemctl restart apache2

When you are done, you can proceed to the next step.

Accessing the Elkarte Web Interface

Now open your web browser and enter the URL http://example.com. You will be redirected to the Elkarte installation page:

Click on the Next button. You should see the following page:

Enter your database name, database username and password and click the Next button. You should see the following page:

Now enter the URL of your forum and click the Next button. You should see the following page:

Now click the Next button to populate the database. You should see the following page:

Enter your administrator username, password and email address and click the Continue button. Once the installation is complete, you should see the following page:

Now click on “Your newly installed board”. You will then be redirected to the Elkarte Dashboard, as shown below:

Enter your administrator username and password and click the Log In” button. You should see the following page:

Securing ElkArte with Let’s Encrypt.

At this point, you have installed and configured Elkarte. Next, it is recommended that you secure it with Let’s Encrypt free SSL.

To do this, you need to install Certbot on your system. By default, the latest version of Certbot is not available in the default Ubuntu 18.04 repository. Therefore, add the Certbot repository with the following command:

add-apt-repository ppa:certbot/certbot

Once the repository is added, update the repository and install Certbot with the following command:

apt-get update -y
apt-get install certbot python-certbot-apache -y

Once Certbot is installed, run the following command to download and install the SSL certificate for your domain example.com.

certbot --apache -d example.com

You will be asked to enter your email address and agree to the terms and conditions (see below):

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): admin@example.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/example.com-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/example.com-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/example.com-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Then type 2 and press Enter to download and install a free SSL certificate for your domain. Once the installation is successfully completed. You should receive the following output:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/example.com.conf to ssl vhost in /etc/apache2/sites-available/
example.com-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2019-10-22. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:
   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

You can now securely access your Elkarte using the URL https://example.com.