Step-by-Step Guide to Installing Elgg Social Network on Ubuntu 22.04

Elgg is a free, open-source, highly customizable web framework and CMS designed to create online social environments. Written in PHP and utilizing MySQL as a database backend, Elgg offers a straightforward and user-friendly interface, allowing beginners to easily manage content via a web browser. It is a powerful tool for schools, colleges, and universities to establish their own social network on campus, making Elgg one of the most versatile social networking engines available.

This guide will walk you through the process of installing Elgg with Nginx and securing it with Let’s Encrypt SSL on Ubuntu 22.04.

Prerequisites

  • A server running Ubuntu 22.04.
  • A valid domain name pointed to your server’s IP address.
  • A configured root password on the server.

Getting Started

Begin by updating the system packages to their latest versions. Run the following command to update all packages:

apt-get update -y

After updating, you can proceed to the installation steps.

Install Nginx, PHP, and MariaDB

Ensure that Nginx, MariaDB, PHP, and the necessary PHP extensions are installed. Use the following command to install them if they are not already present:

apt-get install nginx mariadb-server php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath unzip curl -y

After installation, edit the PHP configuration file to adjust some default settings:

nano /etc/php/8.1/fpm/php.ini

Modify the following parameters according to your needs:

memory_limit = 256M
post_max_size = 64M
upload_max_filesize = 32M
date.timezone = UTC 

Save and close the file, then restart the PHP-FPM service to implement the changes:

systemctl restart php8.1-fpm

Configure MariaDB Database

Next, create a database and user for Elgg. Log in to MySQL using the command:

mysql

Once inside, execute the following commands to create a database and a user:

CREATE DATABASE elggdb;
CREATE USER elgguser@localhost IDENTIFIED BY 'securepassword';

Grant all privileges to the newly created Elgg database:

GRANT ALL PRIVILEGES ON elggdb.* TO elgguser@localhost;

Flush the privileges and exit MySQL:

FLUSH PRIVILEGES;
EXIT;

The MariaDB database and user are now set up for Elgg. Proceed to the next step.

Install Elgg on Ubuntu 22.04

Download the latest version of Elgg from the official GitHub repository using the command:

wget https://github.com/Elgg/Elgg/releases/download/4.2.3/elgg-4.2.3.zip

Extract the downloaded archive with:

unzip elgg-*.zip

Move the extracted files to the Nginx web root directory:

mv elgg-4.2.3 /var/www/html/elgg

Create a data directory and adjust ownership and permissions as follows:

mkdir /var/www/html/data
chown -R www-data:www-data /var/www/html/elgg/
chown -R www-data:www-data /var/www/html/data
chmod -R 755 /var/www/html/elgg

Elgg is now positioned in the Nginx web root directory. Continue to the next step.

Create an Nginx Virtual Host for Elgg

Configure a virtual host in Nginx to serve Elgg over the internet. Create the configuration file using:

nano /etc/nginx/conf.d/elgg.conf

Add the following content:

server {
  listen 80;

  server_name elgg.example.com;
  root /var/www/html/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/php8.1-fpm.sock;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }
}

Save and exit the file, then verify the Nginx configuration with:

nginx -t

Should the output confirm the configuration is correct, restart Nginx to apply changes:

systemctl restart nginx

You can also verify Nginx’s status by running:

systemctl status nginx

Access Elgg Web Interface

With Elgg installed and configured with Nginx, you can access it in your web browser using the URL http://elgg.example.com. This will bring up the Elgg welcome page:

Elgg Welcome

Click on the Next button to proceed to the PHP requirements check page:

PHP Requirements Check

After confirming all requirements, move forward to the database configuration step:

Database Configuration

Database Configuration Continued

Input your database details, data directory path, and site URL. Click Next to reach the site configuration page:

Site Configuration

Once your site settings are submitted, advance to the creation of an Elgg admin user:

Admin User Creation

Fill in the credentials for your admin user and click Next. When finished, you’ll see the following confirmation:

Elgg Installation Complete

Proceed by clicking on Go to site to access the Elgg dashboard:

Elgg Dashboard

Enable Let’s Encrypt SSL on Elgg

To secure your Elgg website, install the Certbot Let’s Encrypt client:

apt-get install python3-certbot-nginx -y

Next, apply Let’s Encrypt SSL using:

certbot --nginx -d elgg.example.com

Enter a valid email address and agree to the terms of service when prompted:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): you@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 elgg.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/elgg.conf

When prompted whether to redirect HTTP traffic to HTTPS, choose the appropriate option:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

Upon completion, the output should confirm success:

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/elgg.conf

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

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/elgg.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/elgg.example.com/privkey.pem
   Your cert will expire on 2022-10-19. 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

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

Conclusion

Congratulations! You have successfully installed Elgg with Nginx and secured it with Let’s Encrypt SSL on Ubuntu 22.04. With this setup, you can now create a social networking platform tailored to your school, college, or university. If you have any questions, feel free to ask.

FAQ

  • What is Elgg?
    Elgg is an open-source web framework and content management system for building social networking platforms.
  • Why should I use Nginx instead of Apache?
    Nginx is known for its high performance, scalability, and efficient handling of high-volume traffic, making it an excellent choice for serving a social networking site like Elgg.
  • How often should I update Let’s Encrypt SSL certificates?
    Let’s Encrypt SSL certificates are valid for 90 days. It is recommended to renew them every 60 days to avoid unexpected expirations.
  • Can I use other databases instead of MariaDB?
    Elgg typically uses MySQL/MariaDB, but it may support other databases via plugins. However, using MySQL or MariaDB is recommended for optimal performance and compatibility.