Vuoi una piattaforma sociale che sia davvero tua? Elgg è un social engine libero e open source scritto in PHP che permette a privati e organizzazioni di mettere in piedi un sito di community completo — con condivisione di file, blog, gruppi e persino erogazione di corsi — sulla propria infrastruttura.
Gira senza problemi sullo stack classico LAMP o LEMP: Apache o Nginx, PHP e MySQL o MariaDB. In questa guida installeremo l'ultima release di Elgg su Debian 9 e la renderemo raggiungibile su una rete pubblica o privata.
Che cosa ti serve
- Una macchina virtuale o un VPS Debian 9, preferibilmente in installazione minimale
- Accesso root, diretto o tramite sudo
- Un IP statico sull'interfaccia esterna, così che i visitatori possano raggiungere il sito
- Un nome di dominio puntato al server (facoltativo: funziona anche l'indirizzo IP)
- Un server di posta in sede o un servizio SMTP esterno, se vuoi registrazioni e notifiche via email
Passo 1: preparare il sistema
Accedi come root e porta la macchina completamente aggiornata:
apt update
apt upgrade
Assegna alla macchina un hostname adeguato — sostituisci con il tuo dominio:
hostnamectl set-hostname www.socialnet.org
Conferma che la modifica sia stata applicata:
hostnamectl
cat /etc/hostname
hostname –s
hostname –f
Riavvia, così che hostname e aggiornamenti del kernel si applichino in modo pulito:
systemctl reboot
Una volta tornato online, installa qualche utility per download ed estrazione:
apt install wget zip unzip curl
Passo 2: installare lo stack LAMP
Elgg conserva utenti, sessioni, post, commenti e tutto il resto in un database relazionale, quindi si parte da MariaDB:
apt install mariadb-server mariadb-client
Debian 9 distribuisce MariaDB con un account root non protetto. Accedi e rimuovi l'autenticazione tramite plugin senza password:
mysql -h localhost
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
MariaDB [mysql]> update user set plugin='' where user='root';
Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> exit
Bye
Ora esegui lo script di hardening di Debian e rispondi sì a ogni domanda: imposta una password di root, elimina gli utenti anonimi, blocca gli accessi root remoti e cancella il database di test:
mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Verifica che l'hardening abbia funzionato: questo comando deve essere rifiutato:
mysql -h localhost -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Questo invece deve riuscire:
mysql -h localhost -u root -p
Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 15 Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> exit Bye
Sistemato il database, installa Apache e PHP con tutti i moduli richiesti da Elgg:
apt install apache2 libapache2-mod-php7.0 php7.0 php7.0-gd php7.0-opcache php7.0-mbstring php7.0-xml php7.0-mysql
Esegui un backup della configurazione PHP prima di toccarla:
cp /etc/php/7.0/apache2/php.ini{,.backup} nano /etc/php/7.0/apache2/php.ini
Modifica questi valori in php.ini:
file_uploads = On default_charset = UTF-8 memory_limit = 128M upload_max_filesize = 100M date.timezone = Europe/London
Aumenta upload_max_filesize se la tua community deve condividere allegati di grandi dimensioni e imposta date.timezone sulla tua area geografica, usando l'elenco di riferimento su https://php.net/manual/en/timezones.php.
Accelera il rendering delle pagine aggiungendo queste impostazioni OPCache sotto la sezione [opcache] esistente:
opcache.enable=1 opcache.enable_cli=1 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=10000 opcache.memory_consumption=128 opcache.save_comments=1 opcache.revalidate_freq=1
Riavvia Apache per attivare le modifiche PHP:
systemctl restart apache2
Passo 3: configurare il firewall
Consenti il traffico web tramite UFW:
ufw allow WWW
oppure
ufw allow 80/tcp
Se amministri la macchina via SSH, tieni aperta anche quella porta:
ufw allow 22/tcp
Preferisci le regole iptables? Usa queste — e apri la 22 solo se sei connesso da remoto:
apt-get install -y iptables-persistent
iptables -I INPUT -p tcp --destination-port 80 -j ACCEPT
iptables -I INPUT -p tcp --destination-port 22 -j ACCEPT
netfilter-persistent save
systemctl restart netfilter-persistent
systemctl status netfilter-persistent
systemctl enable netfilter-persistent.service
Passo 4: configurare Apache
Elgg si basa sul rewrite di .htaccess, quindi abilita mod_rewrite e il modulo TLS:
a2enmod rewrite ssl
a2ensite default-ssl.conf
Apri il vhost SSL e aggiungi il blocco directory dopo la direttiva DocumentRoot:
nano /etc/apache2/sites-enabled/default-ssl.conf
<Directory /var/www/html> Options +FollowSymlinks AllowOverride All Require all granted </Directory>
Modifica anche la riga VirtualHost in modo che risulti:
<VirtualHost *:443>
Applica il blocco identico al vhost HTTP semplice:
<Directory /var/www/html> Options +FollowSymlinks AllowOverride All Require all granted </Directory>
Riavvia Apache e raggiungi il tuo dominio via HTTP:
systemctl restart apache2
Poiché Apache ha generato un certificato self-signed al momento dell'installazione, il browser segnalerà un avviso. Accettalo per proseguire verso la pagina predefinita.
https://yourdomain.tld


Ora apri HTTPS nel firewall:
ufw allow 'WWW Full'
oppure
ufw allow 443/tcp
Con iptables:
iptables -I INPUT -p tcp --destination-port 443 -j ACCEPT
netfilter-persistent save
systemctl restart netfilter-persistent
systemctl status netfilter-persistent
Inserisci una pagina PHP info temporanea per confermare le tue impostazioni:
echo '<?php phpinfo(); ?>'| tee /var/www/html/info.php
https://yourdomain.tld/info.php
Scorri fino alla sezione date per verificare il fuso orario.

Passo 5: installare Elgg
Scarica la release corrente da https://elgg.org/about/download:
wget -O elgg-2.3.5.zip https://elgg.org/getelgg.php?forward=elgg-2.3.5.zip
ls
Estraila e verifica il contenuto:
unzip elgg-2.3.5.zip
ls -al elgg-2.3.5
Cancella la pagina segnaposto di Apache e lo script info temporaneo:
rm /var/www/html/index.html
rm /var/www/html/info.php
Copia Elgg nella document root, ricordando il file nascosto .htaccess:
cp -rf elgg-2.3.5/* /var/www/html/
cp elgg-2.3.5/.htaccess /var/www/html/
Elgg richiede una directory dati scrivibile fuori dalla webroot per upload e altri file degli utenti:
mkdir /var/www/data
chown www-data:www-data /var/www/data
Assegna ad Apache anche la proprietà della webroot:
chown -R www-data:www-data /var/www/html/
ls –al /var/www/html/
Crea il database e un account dedicato — sostituisci con i tuoi nomi e una password robusta:
mysql –u root -p
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database elgg_db;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on elgg_db.* to 'elgg_user'@'localhost' identified by 'password1234';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
Passo 6: eseguire l'installer web
Punta il browser verso il server in HTTPS:
https://yourdomain.tld
La schermata di benvenuto spiega che l'installazione si articola in sei passi. Fai clic su Next.

Elgg ora analizza il sistema e conferma che i requisiti PHP e del server web sono soddisfatti. Fai clic su Next.

Inserisci i dati del database: nome, host (localhost se MariaDB è sulla stessa macchina), nome utente e la password appena creata. Mantieni il prefisso delle tabelle predefinito oppure modificalo per un ulteriore livello di difesa, quindi scegli il fuso orario dell'applicazione e continua.

Assegna un nome al sito, fornisci un indirizzo email di contatto, correggi l'URL del sito se Elgg lo ha rilevato male e inserisci il percorso assoluto della directory data. Scegli il livello di accesso predefinito per i nuovi membri e fai clic su Next.

Crea l'account amministratore — nome visualizzato, email, nome utente e una password robusta — quindi prosegui.

Fai clic su Go to site per approdare alla dashboard di amministrazione.

Dal pannello di destra apri Configure -> Plugins e attiva le funzionalità che ti servono.

Il sito pubblico è raggiungibile allo stesso indirizzo, con le credenziali amministratore impostate durante l'installazione:
https://yourdomain.tld

Passo 7: forzare HTTPS e pianificare la manutenzione
Modifica il file .htaccess nella tua document root:
nano /var/www/html/.htaccess
Trova <IfModule mod_rewrite.c> e aggiungi il redirect subito dopo RewriteEngine On:
RewriteEngine On # Redirect to HTTPS RewriteCond %{HTTPS} off RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L] Puoi anche sovrascrivere le impostazioni PHP per singolo sito. Cerca <IfModule mod_php7.c> e aggiungi i tuoi valori subito sotto:
# Alter web server PHP settings php_value session.use_trans_sid 0 php_value register_globals 1 php_value upload_max_filesize 100M php_value post_max_size 100M
Elgg ha bisogno di un'attività pianificata per inviare le notifiche in coda, ruotare i log e compattare il database. Installala come utente Apache:
crontab -u www-data –e
Sostituisci il segnaposto con il tuo dominio e scarta l'output dei job verso /dev/null:
GET="curl -k" ELGG="https://www.socialnet.org/" OUT=" > /dev/null 2>&1" * * * * * $GET ${ELGG}cron/minute/${OUT} */5 * * * * $GET ${ELGG}cron/fiveminute/${OUT} 15,30,45,59 * * * * $GET ${ELGG}cron/fifteenmin/${OUT} 30,59 * * * * $GET ${ELGG}cron/halfhour/${OUT} @hourly $GET ${ELGG}cron/hourly/${OUT} @daily $GET ${ELGG}cron/daily/${OUT} @weekly $GET ${ELGG}cron/weekly/${OUT} @monthly $GET ${ELGG}cron/monthly/${OUT} @yearly $GET ${ELGG}cron/yearly/${OUT} @reboot $GET ${ELGG}cron/reboot/${OUT} Fatto: il tuo social network Elgg è installato su Debian 9. Se il sito sarà raggiungibile pubblicamente, sostituisci il certificato self-signed con uno rilasciato da un'autorità fidata; Let's Encrypt è un'opzione gratuita.
La documentazione ufficiale è disponibile su https://learn.elgg.org/en/stable/index.html.