How to install Elgg with Nginx on Ubuntu 14.04

elgg vpsThis step by step tutorial will show you how to install Elgg with Nginx on an Ubuntu 14.04 VPS. Elgg is an open source social networking engine that is easy to install and set up, then used to power your social network.
This tutorial was tested and written for an Ubuntu VPS, but it should work on any Debian based Linux distribution.

At the time of writing of this tutorial, Elgg 2.0.1 is the latest and recommended version and it requires:

  • Apache or Nginx web server with support for URL rewriting
  • PHP (version 5.5 or better) with GD graphics library and mbstring extension library.
  • MySQL (version 5 or better) installed on your Linux VPS.

Make sure your OS package list and the OS packages are up to date by running the following commands:

sudo apt-get update
sudo apt-get upgrade

Stop and remove Apache2 service:

sudo service apache2 stop
sudo apt-get remove apache2
sudo apt-get autoremove

Install Nginx and MySQL on your virtual server:

sudo apt-get update
sudo apt-get install nginx mysql-server

Configure nginx to start on boot:

sudo update-rc.d -f nginx defaults

Install PHP and PHP modules required by Elgg:

sudo apt-get install php5 php5-cli php5-fpm php5-mysql php5-gd

Download the latest version of Elgg at and upload it to the ‘opt’ directory on your server:

cd /opt/
wget -O
mv elgg-2.0.1 /var/www/elgg/

It is recommended to use an SSL certificate for your Elgg installation, so order an SSL certificate here. Save the SSL certificate and its private key to files named ‘file.crt’ and ‘private.key’ respectively and upload them to ‘/etc/nginx’ directory.
Remove the default Nginx server block, then create a new Nginx configuration file and add the following virtual block for your domain name:

rm /etc/nginx/sites-enabled/default
vi /etc/nginx/sites-available/

Add the following lines:

server {
listen 80;
# If you have an SSL certificate, uncomment the 3 lines below:
# listen 443 ssl;
# ssl_certificate /etc/nginx/file.crt;
# ssl_certificate_key /etc/nginx/private.key;

	root /var/www/elgg/;
	index index.php index.html index.htm;
	gzip on;

	access_log /var/log/nginx/;
	error_log /var/log/nginx/;

	client_max_body_size 8M;

	location ~ (^\.|/\.) {
		return 403;

	location = /rewrite.php {
		rewrite ^(.*)$ /install.php;

	location / {
		try_files $uri $uri/ @elgg;

	location ~ \.php$ {
		try_files $uri @elgg;
		fastcgi_index index.php;
		fastcgi_pass localhost:9000;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include /etc/nginx/fastcgi_params;

	location @elgg {
		fastcgi_pass localhost:9000;

		include /etc/nginx/fastcgi_params;
		fastcgi_param SCRIPT_FILENAME $document_root/index.php;
		fastcgi_param SCRIPT_NAME     /index.php;
		fastcgi_param QUERY_STRING    __elgg_uri=$uri&$args;

Do not forget to replace with your actual domain name.

Enable the new Nginx configuration file:

ln -sf /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Open the ‘/etc/php5/fpm/pool.d/www.conf’ configuration file and change the ‘listen’ variable from:

listen = /var/run/php5-fpm.sock


listen =;

Test the Nginx configuration:

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

Restart php5-fpm and Nginx services for the changes to take effect:

sudo service php5-fpm restart
sudo service nginx restart

Set the proper permissions of the ‘/var/www/elgg’ directory:

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

Elgg needs a special directory outside of the document root to store uploaded files including profile icons and photos, so create a directory and set proper permissions using the following commands:

mkdir -p /opt/data
chmod 770 /opt/data
chown www-data /opt/data

Also, Elgg requires a MySQL database, so create a new MySQL user and database:

mysql -u root -p
mysql> create database elggdb;
mysql> GRANT ALL PRIVILEGES ON elggdb.* TO 'elgguser'@'localhost' IDENTIFIED BY 'Y0UR-PASSW0RD';
mysql> flush privileges;
mysql> quit

Do not forget to replace ‘Y0UR-PASSW0RD’ with a strong password.
Open in your favorite web browser and follow the on-screen instructions: enter the database username, password and database name, site name, site email address, data directory and create an administrator account.
elgg back-end

That is it. The Elgg installation is complete.
Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install Elgg with Nginx for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

How to Install Ruby 2.0 and RubyGems 2.1.11 on Ubuntu 13.10 from source
Install CachetHQ on Debian 7 VPS
How to install Panda3D on Ubuntu 10.04
There are currently no comments.