How to Install Elgg with Nginx on Ubuntu 18.04

How to Install Elgg with Nginx on Ubuntu 18.04

In this tutorial, we will show you how to install Elgg on an Ubuntu 18.04 VPS with the Nginx web server.

Elgg is an open-source social networking platform where users are able to build all kinds of social environments, such as a campus-wide social network for your university, school, or college, or an internal collaborative platform for your organization. It offers many additional features such as blogging, micro blogging, networking, groups and much more.

Prerequisites

  • For the purposes of this tutorial, we will be using an Ubuntu 18.04 VPS
  • You will also need a working LEMP (Linux, Nginx, MySQL, PHP) stack.
  • Full SSH root access or a user with sudo privileges is also required.

Step 1: Connect to Your Server

Before we begin, you will need to connect to your server via SSH as the root user or as any other user that has sudo privileges.

To connect to your server as the root user, use the following command:

ssh root@IP_ADDRESS -p PORT_NUMBER

Make sure to replace IP_ADDRESS and PORT_NUMBER with your actual server IP address and SSH port number.

Once logged in, make sure that your server is up-to-date by running the following commands:

sudo apt update
sudo apt upgrade

Step 2: Install LEMP

Before we proceed with the Elgg installation, we will need to prepare our server and set up a LEMP stack. If you already have a working LEMP stack installed on your server, you can skip this and go to the next step of this tutorial.

We will start with the Nginx web server installation. To install the Nginx on your server, run the following command:

sudo apt install nginx

To install the MySQL database server, enter the following command:

sudo apt install mysql-server

You can then run the following command to secure your MySQL installation:

sudo mysql_secure_installation

If the program asks you to enter your current MySQL root password, just press your [Enter] key once, as no password is set by default when installing MySQL.

A few more questions will be displayed on-screen – it is recommended that you answer yes to all of them by entering the character ‘Y’:

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

You will also need to enable Nginx and MySQL to start on boot with:

sudo systemctl enable nginx
sudo systemctl enable mysql

Now it’s time to install PHP. Ubuntu 18.04 comes with PHP 7.2 by default, so that’s the version we’ll be installing in this tutorial.

To install PHP 7.2 along with the other extensions required by Elgg, run the following command:

sudo apt install php7.2 php7.2-mysql php7.2-opcache php7.2-xml php7.2-xmlrpc php7.2-gd php7.2-mbstring php7.2-json

To verify that PHP 7.2 is successfully installed, run the following command:

php -v

You should get the following output on your screen:

PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

Step 3: Download Elgg

Now that we have our LEMP stack set up, we can start with our Elgg installation and configuration.

Let’s download the latest stable Elgg version from this link. At the moment of writing this tutorial, the latest stable version is Elgg 3.0.3. To download this version on your server, you can run the following command:

sudo wget https://elgg.org/download/elgg-3.0.3.zip

Let’s extract the files to the /var/www location on our server with this next line:

sudo unzip elgg-3.0.3.zip -d /var/www

Note: If you don’t have the unzip package installed on your server, you can install it with the following command: sudo apt install unzip

Rename the elgg-3.0.3 directory to elgg:

sudo mv /var/www/elgg-3.0.3 /var/www/elgg

Elgg needs a special folder to store uploaded files, such as profile icons and photos. For security reasons, it is also recommended for this directory to be created outside the document root directory of our Elgg installation. The directory will be called data and you can create it with the following command:

sudo mkdir -p /var/www/data

The owner of all these files needs to be the user of the web server running on your system. In our example, we are using the Nginx web server and Nginx runs under the www-data user on Ubuntu 18.04.  To change the owner and set the correct permissions for these files, you need to run the following command:

sudo chown -R www-data:www-data /var/www/elgg
sudo chown -R www-data:www-data /var/www/data
sudo chmod -R 750 /var/www/elgg

Step 4: Configure the Database

Next, we need to create a new database for our Elgg application. To do this, log in to your MySQL database server as the root user by typing the following command:

sudo mysql -u root -p

Then enter the password you made for your MySQL user during step 2. Once you are signed in, create a new database and user by running the following commands on the MySQL shell:

CREATE DATABASE elgg_db;
CREATE USER elgg_user@localhost IDENTIFIED BY 'strong-password';
GRANT ALL PRIVILEGES ON elgg_db.* TO elgg_user@localhost;
FLUSH PRIVILEGES;

You can replace the database and username with your own and also make sure to replace strong-password with an actual strong password.

To exit the MySQL database server command line, type:

exit

Step 5: Configure Nginx

In this step, we will show you how to create a virtual host file for Nginx – this is so you can access your Elgg using your domain name.

Create the virtual host file by executing the following command:

sudo nano /etc/nginx/sites-enabled/elgg.conf

And enter the following information:

server {
  listen 80;

  server_name mydomain.com;
  root /var/www/elgg;

  index index.php;
  
  access_log /var/log/nginx/elgg_access.log;
  error_log /var/log/nginx/elgg_error.log;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php$ {
    fastcgi_index index.php;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_keep_conn on;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }
}

In our example, we will use a domain called mydomain.com. Make sure to replace mydomain.com with your actual domain/subdomain name that you would like to use for your Elgg instance.

To enable the server block in Nginx, you need to create a symbolic link to the sites-enabled directory. Use the following command to create a symbolic link:

sudo ln -s /etc/nginx/sites-available/elgg.conf /etc/nginx/sites-enabled/elgg.conf

Check if there are errors with the newly created Nginx configuration:

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If the syntax is OK and there are no errors, we can restart Nginx.

sudo systemctl restart nginx

Step 6: Installing Elgg Using the Web Interface

You can now navigate to http://mydomain.com in your browser to start the Elgg installation wizard.

The first page will check if all server requirements are met. If there are some missing dependencies, you should install them on your server and then refresh the page again. Once you make sure everything is set up properly, you can click on “Next” at the bottom of the page to continue to the next step.

On the next page, you need to enter your database information (username, database name, and password). You will also need to enter the Data Directory path (/var/www/data) and enter your Site URL (http://mydomain.com/):

Next, you will need to enter your Site name and create an admin account before finishing the installation.

Once this is done, Elgg has been successfully installed on your system.

You can now access your admin panel and login with your admin account at http://mydomain.com/admin

That’s it! Elgg has been successfully installed on your Ubuntu 18.04 server.


Of course, you don’t have to know how to install Elgg on Ubuntu 18.04 if you have Managed Ubuntu Hosting or Managed Elgg Hosting with us. You can simply ask our support team to install Elgg on Ubuntu 18.04 for you. They are available 24/7, and will be able to help you with the installation of Elgg on Ubuntu 18.04.

PS. If you enjoyed reading this blog post on how to install Elgg on Ubuntu 18.04, feel free to share it on social networks by using the shortcuts below, or simply leave a comment in the comments section. Thank you.

Leave a Comment