How to install LeaderOS on Ubuntu
A full guide for installing, configuring and running LeaderOS on your Ubuntu server, for use in production.
Before starting the installation process, make sure your domain nameservers/DNS are configured. Otherwise, you would not be able to access to the website.
Learn how to configure your domain nameservers/DNS here.
Auto Installation
Download the installation script
wget https://installer.leaderos.net/leaderos_installer.sh
Make the script executable.
chmod +x leaderos_installer.sh
Run the script.
./leaderos_installer.sh
Manual Installation
Install Nginx package
sudo apt install nginx -y
Ensure that nginx is running with the systemctl start
command:
sudo systemctl start nginx
Setting Up Nginx Server Blocks
When using the Nginx web server, server blocks (similar to virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain from a single server. We will set up a domain called your_domain.com, but you should replace this with your own domain name.
Create directory for your your_domain.com
sudo mkdir -p /var/www/your_domain.com/html
Next, assign ownership of the directory with the www-data.
sudo chown -R www-data:www-data /var/www/your_domain.com/html
Configuring Nginx
In order for Nginx to serve this content, it’s necessary to create a server block with the correct directives. Instead of modifying the default configuration file directly, let’s make a new one at /etc/nginx/sites-available/your_domain.com
:
sudo nano /etc/nginx/sites-available/your_domain.com
Paste in the following configuration block, which is similar to the default, but updated for our new directory and domain name:
server {
listen 80;
listen [::]:80;
root /var/www/your_domain.com/html;
index index.html index.htm index.nginx-debian.html;
server_name your_domain.com www.your_domain.com;
client_max_body_size 128M;
location ~ (^|/)(apps/main|apps/dashboard-legacy|apps/install|apps/update)/private(/|$) {
return 403;
}
location ~ \.(ini|log|sh|sql|htaccess) {
deny all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
error_page 404 /apps/main/index.php?route=404;
error_page 403 /apps/main/index.php?route=404;
location ~ "(^|/)(apps/main|apps/dashboard-legacy|apps/install|apps/update)/private(/|$)" {
deny all;
}
location ~ "(^|/)apps/main/themes/(.*)/private(/|$)" {
deny all;
}
location ~ "(^|/)apps/main/themes/(.*)/theme.json(/|$)" {
deny all;
}
location ~ "(^|/)apps/(dashboard|api)(?!/public)(/?)" {
return 403;
}
rewrite ^/robots.txt(/?)$ /robots.php last;
rewrite ^/sitemap.xml(/?)$ /sitemap.php last;
rewrite ^/install(/?)$ /apps/install/index.php last;
rewrite ^/(/?)$ /apps/main/index.php?route=home last;
rewrite ^/rules(/?)$ /apps/main/index.php?route=rules last;
rewrite ^/staff(/?)$ /apps/main/index.php?route=staff last;
rewrite ^/vote(/?)$ /apps/main/index.php?route=vote last;
rewrite ^/download(/?)$ /apps/main/index.php?route=download last;
rewrite ^/download/([0-9]+)/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=download&id=$1&file=$2 last;
rewrite ^/player/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=player&id=$1 last;
rewrite ^/profile(/?)$ /apps/main/index.php?route=profile&target=profile&action=get last;
rewrite ^/profile/edit(/?)$ /apps/main/index.php?route=profile&target=profile&action=update last;
rewrite ^/profile/contact(/?)$ /apps/main/index.php?route=profile&target=profile&action=contact last;
rewrite ^/profile/change-password(/?)$ /apps/main/index.php?route=profile&target=profile&action=change-password last;
rewrite ^/login(/?)$ /apps/main/index.php?route=login last;
rewrite ^/register(/?)$ /apps/main/index.php?route=register last;
rewrite ^/recover-account(/?)$ /apps/main/index.php?route=recover last;
rewrite ^/recover-account/([0-9a-zA-Z-_]+)/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=recover&id=$1&token=$2 last;
rewrite ^/email-verification(/?)$ /apps/main/index.php?route=email-verification last;
rewrite ^/email-verification/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=email-verification&token=$1 last;
rewrite ^/verify(/?)$ /apps/main/index.php?route=tfa last;
rewrite ^/recover-verify(/?)$ /apps/main/index.php?route=tfa-recover last;
rewrite ^/recover-verify/([0-9a-zA-Z-_]+)/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=tfa-recover&id=$1&token=$2 last;
rewrite ^/logout(/?)$ /apps/main/public/ajax/logout.php last;
rewrite ^/credit/buy(/?)$ /apps/main/index.php?route=credit&target=credit&action=buy last;
rewrite ^/credit/buy/success(/?)$ /apps/main/index.php?route=credit&target=credit&action=alert&result=success last;
rewrite ^/credit/buy/error(/?)$ /apps/main/index.php?route=credit&target=credit&action=alert&result=error last;
rewrite ^/credit/send(/?)$ /apps/main/index.php?route=credit&target=credit&action=send last;
rewrite ^/credit/send/([0-9]+)(/?)$ /apps/main/index.php?route=credit&target=credit&action=send&id=$1 last;
rewrite ^/auth(/?)$ /apps/main/public/ajax/auth.php last;
rewrite ^/discord/login(/?)$ /apps/main/public/ajax/discord-login.php last;
rewrite ^/discord/link(/?)$ /apps/main/public/ajax/discord-link.php last;
rewrite ^/discord/unlink(/?)$ /apps/main/public/ajax/discord-unlink.php last;
rewrite ^/manual-payment/([0-9]+)(/?)$ /apps/main/index.php?route=manual-payment&id=$1 last;
rewrite ^/callback/([0-9a-zA-Z-_]+)(/?)$ /apps/main/public/ajax/process.php?api=$1 last;
rewrite ^/islem/([0-9a-zA-Z-_]+)(/?)$ /apps/main/public/ajax/process.php?api=$1 last;
rewrite ^/leaderboards(/?)$ /apps/main/index.php?route=leaderboards last;
rewrite ^/leaderboards/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=leaderboards&server=$1 last;
rewrite ^/store(/?)$ /apps/main/index.php?route=store&action=getAll last;
rewrite ^/store/products/([0-9]+)(/?)$ /apps/main/index.php?route=store&action=get&product=$1 last;
rewrite ^/store/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=store&action=get&category=$1 last;
rewrite ^/support(/?)$ /apps/main/index.php?route=support&target=support&action=getAll last;
rewrite ^/support/create(/?)$ /apps/main/index.php?route=support&target=support&action=insert last;
rewrite ^/support/view/([0-9]+)(/?)$ /apps/main/index.php?route=support&target=support&action=get&id=$1 last;
rewrite ^/support/delete/([0-9]+)(/?)$ /apps/main/index.php?route=support&target=support&action=delete&id=$1 last;
rewrite ^/blog/([0-9]+)(/?)$ /apps/main/index.php?route=home&page=$1 last;
rewrite ^/categories/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=home&category=$1 last;
rewrite ^/categories/([0-9a-zA-Z-_]+)/([0-9]+)(/?)$ /apps/main/index.php?route=home&category=$1&page=$2 last;
rewrite ^/tags/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=home&tag=$1 last;
rewrite ^/tags/([0-9a-zA-Z-_]+)/([0-9]+)(/?)$ /apps/main/index.php?route=home&tag=$1&page=$2 last;
rewrite ^/posts/([0-9]+)/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=news&id=$1 last;
rewrite ^/pages/([0-9]+)/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=page&id=$1 last;
rewrite ^/maintenance(/?)$ /apps/main/index.php?route=maintenance last;
rewrite ^/games(/?)$ /apps/main/index.php?route=games&action=getAll last;
rewrite ^/games/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=games&action=get&game=$1 last;
rewrite ^/help(/?)$ /apps/main/index.php?route=help&action=getAll last;
rewrite ^/help/articles/([0-9]+)/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=help&action=getArticle&id=$1 last;
rewrite ^/help/topics/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=help&action=getTopic&category=$1 last;
rewrite ^/chest(/?)$ /apps/main/index.php?route=chest&target=chest&action=getAll last;
rewrite ^/chest/gift/([0-9]+)(/?)$ /apps/main/index.php?route=chest&target=chest&action=gift&id=$1 last;
rewrite ^/gift(/?)$ /apps/main/index.php?route=gift&target=gift&action=coupon last;
rewrite ^/gift/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=gift&target=gift&action=use&id=$1 last;
rewrite ^/fortune-wheel(/?)$ /apps/main/index.php?route=lottery last;
rewrite ^/fortune-wheel/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=lottery&lottery=$1 last;
rewrite ^/play(/?)$ /apps/main/index.php?route=play last;
rewrite ^/form/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=form&action=view&form=$1 last;
rewrite ^/form/view/([0-9]+)(/?)$ /apps/main/index.php?route=form&action=get&id=$1 last;
rewrite ^/help-bazaar(/?)$ /apps/main/index.php?route=manage-bazaar&action=help last;
rewrite ^/manage-bazaar(/?)$ /apps/main/index.php?route=manage-bazaar&action=getAll last;
rewrite ^/manage-bazaar/([0-9]+)(/?)$ /apps/main/index.php?route=manage-bazaar&action=sell&id=$1 last;
rewrite ^/bazaar(/?)$ /apps/main/index.php?route=bazaar&action=getAll last;
rewrite ^/bazaar/products/([0-9]+)(/?)$ /apps/main/index.php?route=bazaar&action=get&product=$1 last;
rewrite ^/bazaar/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=bazaar&action=get&server=$1 last;
rewrite ^/orders/view/([0-9]+)(/?)$ /apps/main/index.php?route=orders&action=get&id=$1 last;
rewrite ^/orders/success(/?)$ /apps/main/index.php?route=orders&action=alert&result=success last;
rewrite ^/orders/error(/?)$ /apps/main/index.php?route=orders&action=alert&result=error last;
rewrite ^/gaming-night(/?)$ /apps/main/index.php?route=gaming-night last;
rewrite ^/gaming-night/products/([0-9]+)(/?)$ /apps/main/index.php?route=gaming-night&action=get&product=$1 last;
rewrite ^/forum(/?)$ /apps/main/index.php?route=forum&target=categories&action=getAll last;
rewrite ^/forum/categories/([0-9]+)/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=forum&target=categories&action=get&id=$1 last;
rewrite ^/forum/categories/([0-9]+)/([0-9a-zA-Z-_]+)/([0-9]+)(/?)$ /apps/main/index.php?route=forum&target=categories&action=get&id=$1&page=$3 last;
rewrite ^/forum/threads/edit/([0-9]+)(/?)$ /apps/main/index.php?route=forum&target=threads&action=update&id=$1 last;
rewrite ^/forum/threads/pin/([0-9]+)(/?)$ /apps/main/index.php?route=forum&target=threads&action=pin&id=$1 last;
rewrite ^/forum/threads/lock/([0-9]+)(/?)$ /apps/main/index.php?route=forum&target=threads&action=lock&id=$1 last;
rewrite ^/forum/threads/delete/([0-9]+)(/?)$ /apps/main/index.php?route=forum&target=threads&action=delete&id=$1 last;
rewrite ^/forum/threads/create(/?)$ /apps/main/index.php?route=forum&target=threads&action=insert last;
rewrite ^/forum/threads/([0-9]+)/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=forum&target=threads&action=get&id=$1 last;
rewrite ^/forum/replies/edit/([0-9]+)(/?)$ /apps/main/index.php?route=forum&target=replies&action=update&id=$1 last;
rewrite ^/forum/replies/delete/([0-9]+)(/?)$ /apps/main/index.php?route=forum&target=replies&action=delete&id=$1 last;
rewrite ^/punishments(/?)$ /apps/main/index.php?route=punishments&target=home last;
rewrite ^/punishments/bans(/?)$ /apps/main/index.php?route=punishments&target=bans&action=getAll last;
rewrite ^/punishments/mutes(/?)$ /apps/main/index.php?route=punishments&target=mutes&action=getAll last;
rewrite ^/punishments/kicks(/?)$ /apps/main/index.php?route=punishments&target=kicks&action=getAll last;
rewrite ^/punishments/warnings(/?)$ /apps/main/index.php?route=punishments&target=warnings&action=getAll last;
rewrite ^/suggestions(/?)$ /apps/main/index.php?route=suggestions&target=suggestion&action=getAll last;
rewrite ^/suggestions/create(/?)$ /apps/main/index.php?route=suggestions&target=suggestion&action=insert last;
rewrite ^/suggestions/like/([0-9]+)(/?)$ /apps/main/index.php?route=suggestions&target=suggestion&action=like&id=$1 last;
rewrite ^/suggestions/dislike/([0-9]+)(/?)$ /apps/main/index.php?route=suggestions&target=suggestion&action=dislike&id=$1 last;
rewrite ^/suggestions/edit/([0-9]+)(/?)$ /apps/main/index.php?route=suggestions&target=suggestion&action=update&id=$1 last;
rewrite ^/suggestions/delete/([0-9]+)(/?)$ /apps/main/index.php?route=suggestions&target=suggestion&action=delete&id=$1 last;
rewrite ^/suggestions/([0-9]+)/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=suggestions&target=suggestion&action=get&id=$1 last;
rewrite ^/suggestions/categories/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=suggestions&target=category&action=get&slug=$1 last;
rewrite ^/suggestions/replies/edit/([0-9]+)(/?)$ /apps/main/index.php?route=suggestions&target=reply&action=update&id=$1 last;
rewrite ^/suggestions/replies/delete/([0-9]+)(/?)$ /apps/main/index.php?route=suggestions&target=reply&action=delete&id=$1 last;
rewrite ^/404(/?)$ /apps/main/index.php?route=404 last;
rewrite ^/checkout(/?)$ /apps/main/index.php?route=checkout last;
rewrite ^/tebex/webhook(/?)$ /apps/main/public/ajax/tebex-webhook.php last;
rewrite ^/applications/forms/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=application&action=apply&form=$1 last;
rewrite ^/applications/([0-9]+)(/?)$ /apps/main/index.php?route=application&action=get&id=$1 last;
rewrite ^/OneSignalSDKWorker.js$ /apps/dashboard/public/assets/js/OneSignalSDKWorker.js last;
rewrite ^/OneSignalSDKUpdaterWorker.js$ /apps/dashboard/public/assets/js/OneSignalSDKUpdaterWorker.js last;
location /api {
try_files $uri $uri/ /apps/api/public/index.php?$args;
}
location ~* ^/dashboard/assets/(.+)\.(\d+)\.(js|css|png|jpg|jpeg|gif)$ {
try_files /apps/dashboard/public/assets/$1.$3 =404;
}
location /dashboard {
try_files $uri $uri/ /apps/dashboard/public/index.php?$query_string;
}
location / {
rewrite ^/([0-9a-zA-Z-_]+)(/?)$ /apps/main/index.php?route=page&slug=$1 last;
}
}
Next, let’s enable the file by creating a link from it to the sites-enabled directory, which Nginx reads from during startup:
Finally, restart nginx for the configuration to take effect.
sudo systemctl restart nginx
Installing PHP 7.4
Ubuntu
Thereafter, install some important packages to fulfill the post.
sudo apt install software-properties-common -y
The next step is to add the ondrej PPA repository.
sudo add-apt-repository ppa:ondrej/php -y
Refresh APT to load the new repository:
sudo apt update -y
And now you can install PHP 7.4
sudo apt install php7.4 php7.4-fpm -y
E: Package ‘php7.4’ has no installation candidate
If you get this error while installing PHP 7.4. Run this command:
Ubuntu 23.10:
sudo sed -i 's/mantic/jammy/' /etc/apt/sources.list.d/ondrej-ubuntu-*.sources
Ubuntu 23.04:
sudo sed -i 's/lunar/jammy/' /etc/apt/sources.list.d/ondrej-ubuntu-*.list
Then refresh APT:
sudo apt update -y
Now, you can install php 7.4:
sudo apt install php7.4 -y
Install required php extensions.
sudo apt install php7.4-{cli,common,curl,zip,mysql,mbstring,json} -y
Start and enable the php7.4-fpm service.
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
Debian
Thereafter, install some important packages to fulfill the post.
sudo apt-get install ca-certificates apt-transport-https software-properties-common curl lsb-release -y
Import and install the GPG key and repository using an automated script.
curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x
Refresh APT to load the new repository:
sudo apt update -y
And now you can install PHP 7.4
sudo apt install php7.4 php7.4-fpm -y
Install required php extensions.
sudo apt install php7.4-{cli,common,curl,zip,mysql,mbstring,json} -y
Start and enable the php7.4-fpm service.
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
Configure PHP Settings
In order for the LeaderOS software to work, some php settings need to be configured. Open the php.ini file with nano or your preferred text editor.
sudo nano /etc/php/7.4/fpm/php.ini
Add these lines at the end.
allow_url_fopen=On
short_open_tag=On
upload_max_filesize=128M
post_max_size=128M
max_input_vars=10000
memory_limit=512M
max_execution_time=600
max_input_time=600
Then save and exit the file. Now we need to restart the nginx and php-fpm for the settings to come into effect.
sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm
Installing Ioncube Loader
Download IonCube Loader files.
wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
Then uncompress the downloaded file using the tar command.
tar -zxvf ioncube_loaders_lin_x86*
Switch into the unzipped folder.
cd ioncube/
Next, find the location of the extension directory for PHP version 7.4, it is where the ioncube loader file will be installed.
php -i | grep extension_dir
Output: extension_dir => /usr/lib/php/20190902 => /usr/lib/php/20190902
Next we need to copy ioncube loader for our PHP 7.4 version to the extension directory (/usr/lib/php/20190902).
sudo cp ioncube_loader_lin_7.4.so /usr/lib/php/20190902
Now we need to configure ioncube loader to work with PHP, in the php.ini file.
sudo nano /etc/php/7.4/fpm/php.ini
Then add below line as the first line in the respective php.ini file.
zend_extension = /usr/lib/php/20190902/ioncube_loader_lin_7.4.so
Then save and exit the file. Now we need to restart the nginx and php-fpm for the ioncube loaders to come into effect.
sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm
Installing MariaDB (MySQL)
Install the mariadb package.
sudo apt install mariadb-server -y
Ensure that MariaDB is running with the systemctl start command:
sudo systemctl start mariadb.service
Additionally, consider enabling MariaDB to start every time on system startup as shown.
sudo systemctl enable mariadb.service
Open up the MariaDB prompt from your terminal:
sudo mariadb
Next, create a regular user. Here, we are creating a user called leaderos. Be sure to replace secret_password with your preferred user’s password.
CREATE USER 'leaderos_user'@'localhost' IDENTIFIED BY 'secret_password';
Next, create a database:
CREATE DATABASE leaderos_db;
Next, grant all privileges to leaderos user. This effectively assigns all the database root user’s permissions to the user.
GRANT ALL PRIVILEGES ON leaderos_db.* TO 'leaderos_user'@'localhost' WITH GRANT OPTION;
To apply the changes, flush the privileges.
FLUSH PRIVILEGES;
Finally, exit the MariaDB prompt.
exit
Configuring MariaDB (MySQL)
Open the MariaDB configration file.
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Add these lines under [mysqld] section.
sql_mode="ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Then save and exit the file. Now we need to restart the MariaDB for the settings to come into effect.
sudo systemctl restart mariadb.service
Installing LeaderOS
Upload the leaderos.zip file to /var/www/your_domain.com/html via FTP and unzip the leaderos.zip file.
Visit your website. You will see the installation page.
sudo chown -R www-data:www-data /var/www/your_domain.com/html