Private
Protection
Special Offers
Catalog
Auto donation
How to set up a web server for an L2 project website on Ubuntu: Apache or Nginx, PHP 8 via PHP-FPM, MariaDB, a firewall, HTTPS and correct file permissions.
The php5 and libapache2-mod-auth-mysql packages, the gksudo editor and service control through /etc/init.d from old guides no longer exist in current Ubuntu releases. Below is an up-to-date setup of a web server for a project website (home page, registration, user panel, statistics) on Ubuntu 22.04 or 24.04 LTS. All commands are run as a regular user with sudo rights.
| Ubuntu | PHP from the repository | PHP-FPM service | MariaDB |
|---|---|---|---|
| 22.04 LTS | 8.1 | php8.1-fpm | 10.6 |
| 24.04 LTS | 8.3 | php8.3-fpm | 10.11 |
The examples use PHP 8.3 (Ubuntu 24.04); on 22.04 replace 8.3 with 8.1. php -v shows the installed version, and ls /run/php/ shows the name of the PHP-FPM socket.
Apache or Nginx? Apache understands .htaccess files, which most CMSs and L2 website scripts rely on. Nginx serves static files faster and uses less memory, but .htaccess rules have to be rewritten into the site config. Pick one: the two cannot both listen on port 80.
sudo apt update
sudo apt upgrade -ysudo apt install -y mariadb-server mariadb-client
sudo systemctl enable --now mariadb
sudo mysql_secure_installationThe security script asks a few questions. Answer Y to removing anonymous users, disallowing remote root login and removing the test database. On Ubuntu root logs in to MariaDB with sudo mysql (unix_socket authentication), so you do not have to switch it or set a root password. In newer versions the same tool is called mariadb-secure-installation.
Create a database and a separate user for the website:
sudo mysql
CREATE DATABASE l2site CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'l2site'@'localhost' IDENTIFIED BY 'CHANGE_ME_StrongPass';
GRANT ALL PRIVILEGES ON l2site.* TO 'l2site'@'localhost';
FLUSH PRIVILEGES;
EXIT;Instead of MariaDB you can install MySQL 8.0 (sudo apt install mysql-server); the commands are the same and the service is called mysql.
sudo apt install -y apache2 php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip php-intl
sudo a2enmod proxy_fcgi setenvif rewrite headers
sudo a2enconf php8.3-fpm
sudo systemctl restart apache2The proxy_fcgi module hands PHP scripts to PHP-FPM, and rewrite is needed for friendly URLs and .htaccess rules. Do not install libapache2-mod-php alongside: it is the old way of running PHP and switches Apache to the less efficient mpm_prefork mode.
Create a virtual host in /etc/apache2/sites-available/example.com.conf (replace example.com with your domain). nano is a convenient editor: sudo nano /etc/apache2/sites-available/example.com.conf.
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>Create the site folder, enable the host, disable the default one and test the config:
sudo mkdir -p /var/www/example.com/public_html
sudo a2ensite example.com.conf
sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl reload apache2sudo apt install -y nginx php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip php-intl
sudo mkdir -p /var/www/example.com/public_htmlThe site config goes into /etc/nginx/sites-available/example.com:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com/public_html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~ /\.(ht|git) {
deny all;
}
}Enable the site, disable the default one and test the config:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginxdeny all, otherwise they can be downloaded by a direct link.PHP settings for websites live in /etc/php/8.3/fpm/php.ini (console scripts use a separate /etc/php/8.3/cli/php.ini). Typical values:
memory_limit = 256M
upload_max_filesize = 32M
post_max_size = 32M
max_execution_time = 60
date.timezone = UTC
expose_php = OffRestart PHP-FPM after changes: sudo systemctl restart php8.3-fpm. php -m lists the loaded extensions; missing ones are installed as php-name packages, for example php-bcmath or php-redis.
To check that PHP works, create a test file:
echo '<?php phpinfo();' | sudo tee /var/www/example.com/public_html/info.phpOpen http://example.com/info.php in a browser: the Server API line should say FPM/FastCGI. Be sure to delete the file afterwards: sudo rm /var/www/example.com/public_html/info.php.
sudo ufw allow OpenSSH
sudo ufw allow "Apache Full" # for Nginx: sudo ufw allow "Nginx Full"
sudo ufw enable
sudo ufw statusThe Apache Full and Nginx Full profiles open ports 80 and 443. Add the SSH rule before enabling ufw, or you will lock yourself out; if SSH runs on a non-standard port, open that port instead, for example sudo ufw allow 2222/tcp. If the game server runs on the same machine, open its ports too: sudo ufw allow 2106/tcp and sudo ufw allow 7777/tcp. There is no need to open the database port 3306.
A free Let's Encrypt certificate is issued with the certbot tool. Before that, the A records for the domain and www must point to the server IP, and port 80 must be open.
# Apache
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache -d example.com -d www.example.com
# Nginx
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
# test automatic renewal
sudo certbot renew --dry-runCertbot adds the HTTPS settings and an http-to-https redirect to the site config by itself. Renewal runs automatically from a systemd timer.
The site files go into /var/www/example.com/public_html. The web server and PHP-FPM run as the www-data user. A convenient scheme: the files are owned by your user (the one you upload the site with over SFTP) with the www-data group; folders 755, files 644, and write access only to folders where the script stores data (cache, uploads, compiled templates).
sudo chown -R $USER:www-data /var/www/example.com
sudo find /var/www/example.com -type d -exec chmod 755 {} \;
sudo find /var/www/example.com -type f -exec chmod 644 {} \;
# write access only where the site stores data (example: cache)
sudo chmod -R g+w /var/www/example.com/public_html/cache
# the file with the database password (name depends on the site script)
sudo chmod 640 /var/www/example.com/public_html/config.php| Command | What it does |
|---|---|
sudo systemctl status apache2 | service status (same for nginx, php8.3-fpm, mariadb) |
sudo systemctl restart name | restart a service |
sudo systemctl reload apache2 | reload the config without dropping connections |
sudo systemctl enable name | enable start at boot |
sudo apache2ctl configtest, sudo nginx -t | test the config before a restart |
sudo journalctl -u php8.3-fpm | service log |
| Path | Contents |
|---|---|
/var/www/ | website files |
/etc/apache2/sites-available/ | Apache virtual hosts |
/etc/nginx/sites-available/ | Nginx site configs |
/etc/php/8.3/fpm/php.ini | PHP settings for websites |
/etc/php/8.3/fpm/pool.d/www.conf | PHP-FPM pool: user, number of processes |
/etc/mysql/mariadb.conf.d/50-server.cnf | MariaDB server settings |
/var/log/apache2/, /var/log/nginx/ | web server logs |
Setting up the game server on Windows is covered in the Windows setup guide. We can also deploy the website and the server for you as a turnkey project; ready-made server packs are available too.
Published 22 November 2026
We help with the server pack, setup, protection and launch — one-off or on an ongoing basis.
Get L2‑Scripts news by email
And 5% off all studio services while you stay subscribed.
The discount is valid while you are subscribed: when ordering, tell the manager your subscription address on Telegram.
Search
News