> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leaderos.net/llms.txt
> Use this file to discover all available pages before exploring further.

# How to install LeaderOS on Ubuntu

> A full guide for installing, configuring and running LeaderOS on your Ubuntu server, for use in production.

<Warning>
  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](/configuring-dns).
</Warning>

## Auto Installation

<Warning>Use this script only for fresh installation! If it's not a fresh installation, install it manually.</Warning>

Download the installation script

```bash theme={null}
wget https://installer.leaderos.net/leaderos_installer.sh
```

Make the script executable.

```bash theme={null}
chmod +x leaderos_installer.sh
```

Run the script.

```bash theme={null}
./leaderos_installer.sh
```

## Manual Installation

Install Nginx package

```bash theme={null}
sudo apt install nginx -y
```

Ensure that nginx is running with the `systemctl start` command:

```bash theme={null}
sudo systemctl start nginx
```

<Note>Make sure you you enable the 80 and 443 firewall ports.</Note>

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

```bash theme={null}
sudo mkdir -p /var/www/your_domain.com/html
```

Next, assign ownership of the directory with the www-data.

```bash theme={null}
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`:

```bash theme={null}
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:

```nginx theme={null}
server {
    listen 80;
    listen [::]:80;

    root /var/www/your_domain.com/html;
    index /apps/main/public/index.php;

    server_name your_domain.com www.your_domain.com;

    client_max_body_size 128M;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }

    location = /favicon.ico {
        rewrite ^ /apps/main/public/favicon.png last;
    }

    location ~* \.(ini|log|sh|sql|htaccess)$ {
        deny all;
    }

    location ~ "(^|/)apps/(dashboard|api|auto-install|install)(?!/public)(/?)" {
        return 403;
    }

    location ~ "(^|/)apps/main(?!/public|/app/views/themes/[0-9a-zA-Z-_]+/assets)(/?)" {
        return 403;
    }

    # Auto Installer Assets
    location ~ "auto-install/assets/(.*)$" {
        try_files $uri $uri/ /apps/auto-install/public/assets/$1;
    }

    # Installer Assets
    location ~ "install/assets/(.*)$" {
        try_files $uri $uri/ /apps/install/public/assets/$1;
    }

    # Dashboard Assets (cached)
    location ~* ^/dashboard/assets/(.+)\.(\d+)\.(js|css|png|jpeg|jpg|webp|svg|gif|ico|mp3|mp4|json|ttf|eot|woff|woff2)$ {
        try_files /apps/dashboard/public/assets/$1.$3 =404;
    }

    # Dashboard Assets direct access
    location ~ ^/dashboard/assets/(.+)\.(js|css|png|jpeg|jpg|webp|svg|gif|ico|mp3|mp4|json|ttf|eot|woff|woff2)$ {
        try_files $uri /apps/dashboard/public/assets/$1.$2;
    }

    # Images for Main
    location ~ "assets/core/images/(.*)$" {
        try_files $uri $uri/ /apps/main/public/images/$1;
    }

    # Theme Assets (cached)
    location ~* ^/assets/([0-9a-zA-Z-_]+)/(.+)\.(\d+)\.(js|css|png|jpeg|jpg|webp|svg|gif|ico|mp3|mp4|json|ttf|eot|woff|woff2)$ {
        try_files /apps/main/app/views/themes/$1/assets/$2.$4 =404;
    }

    # Theme Assets direct access
    location ~ ^/assets/([0-9a-zA-Z-_]+)/(.+)\.(js|css|png|jpeg|jpg|webp|svg|gif|ico|mp3|mp4|json|ttf|eot|woff|woff2)$ {
        try_files /apps/main/app/views/themes/$1/assets/$2.$3 =404;
    }

    location /auto-install {
        try_files $uri $uri/ /apps/auto-install/public/index.php?$query_string;
    }

    location /install {
        try_files $uri $uri/ /apps/install/public/index.php?$query_string;
    }

    location /api {
        try_files $uri $uri/ /apps/api/public/index.php?$query_string;
    }

    location /dashboard {
        try_files $uri $uri/ /apps/dashboard/public/index.php?$query_string;
    }

    location / {
        try_files $uri $uri/ /apps/main/public/index.php?$query_string;
    }
}
```

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.

```bash theme={null}
sudo systemctl restart nginx
```

### Installing PHP 7.4

#### Ubuntu

Thereafter, install some important packages to fulfill the post.

```bash theme={null}
sudo apt install software-properties-common -y
```

The next step is to add the ondrej PPA repository.

```bash theme={null}
sudo add-apt-repository ppa:ondrej/php -y
```

Refresh APT to load the new repository:

```bash theme={null}
sudo apt update -y
```

And now you can install PHP 7.4

```bash theme={null}
sudo apt install php7.4 php7.4-fpm -y
```

<Warning>
  **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`
</Warning>

Install required php extensions.

```bash theme={null}
sudo apt install php7.4-{cli,common,curl,zip,mysql,mbstring,json} -y
```

Start and enable the php7.4-fpm service.

```bash theme={null}
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
```

#### Debian

Thereafter, install some important packages to fulfill the post.

```bash theme={null}
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.

```bash theme={null}
curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x
```

Refresh APT to load the new repository:

```bash theme={null}
sudo apt update -y
```

And now you can install PHP 7.4

```bash theme={null}
sudo apt install php7.4 php7.4-fpm -y
```

Install required php extensions.

```bash theme={null}
sudo apt install php7.4-{cli,common,curl,zip,mysql,mbstring,json} -y
```

Start and enable the php7.4-fpm service.

```bash theme={null}
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.

```bash theme={null}
sudo nano /etc/php/7.4/fpm/php.ini
```

Add these lines at the end.

```ini theme={null}
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
```

<img src="https://mintcdn.com/leaderos/RSiB1c7CNJn9Y9yJ/images/installation/vps-vds/php-ini.png?fit=max&auto=format&n=RSiB1c7CNJn9Y9yJ&q=85&s=e9f5692b822d7c93fdd6ebd57e73f9d7" alt="Image" width="768" height="241" data-path="images/installation/vps-vds/php-ini.png" />

Then save and exit the file. Now we need to restart the nginx and php-fpm for the settings to come into effect.

```bash theme={null}
sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm
```

### Installing Ioncube Loader

Download IonCube Loader files.

```bash theme={null}
wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
```

Then uncompress the downloaded file using the tar command.

```bash theme={null}
tar -zxvf ioncube_loaders_lin_x86*
```

Switch into the unzipped folder.

```bash theme={null}
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.

```bash theme={null}
php -i | grep extension_dir
```

<Info>
  **Output:**
  extension\_dir => /usr/lib/php/20190902 => /usr/lib/php/20190902
</Info>

Next we need to copy ioncube loader for our PHP 7.4 version to the extension directory (/usr/lib/php/20190902).
<Note> Make sure to replace the PHP version and extension directory in the above command according to your system configuration. </Note>

```bash theme={null}
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.

```bash theme={null}
sudo nano /etc/php/7.4/fpm/php.ini
```

Then add below line as the first line in the respective php.ini file.

```ini theme={null}
zend_extension = /usr/lib/php/20190902/ioncube_loader_lin_7.4.so
```

<img src="https://mintcdn.com/leaderos/RSiB1c7CNJn9Y9yJ/images/installation/vps-vds/php-ini2.png?fit=max&auto=format&n=RSiB1c7CNJn9Y9yJ&q=85&s=ec471a8bd1ea4c22571e5629e1304598" alt="Image" width="768" height="92" data-path="images/installation/vps-vds/php-ini2.png" />

Then save and exit the file. Now we need to restart the nginx and php-fpm for the ioncube loaders to come into effect.

```bash theme={null}
sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm
```

### Installing MariaDB (MySQL)

Install the mariadb package.

```bash theme={null}
sudo apt install mariadb-server -y
```

Ensure that MariaDB is running with the systemctl start command:

```bash theme={null}
sudo systemctl start mariadb.service
```

Additionally, consider enabling MariaDB to start every time on system startup as shown.

```bash theme={null}
sudo systemctl enable mariadb.service
```

Open up the MariaDB prompt from your terminal:

```bash theme={null}
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.

```sql theme={null}
CREATE USER 'leaderos_user'@'localhost' IDENTIFIED BY 'secret_password';
```

Next, create a database:

```sql theme={null}
CREATE DATABASE leaderos_db;
```

Next, grant all privileges to leaderos user. This effectively assigns all the database root user’s permissions to the user.

```sql theme={null}
GRANT ALL PRIVILEGES ON leaderos_db.* TO 'leaderos_user'@'localhost' WITH GRANT OPTION;
```

To apply the changes, flush the privileges.

```sql theme={null}
FLUSH PRIVILEGES;
```

Finally, exit the MariaDB prompt.

```sql theme={null}
exit
```

#### Configuring MariaDB (MySQL)

Open the MariaDB configration file.

```bash theme={null}
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
```

Add these lines under \[mysqld] section.

```ini theme={null}
sql_mode="ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
```

<img src="https://mintcdn.com/leaderos/RSiB1c7CNJn9Y9yJ/images/installation/vps-vds/server-config.png?fit=max&auto=format&n=RSiB1c7CNJn9Y9yJ&q=85&s=cec55183c189a34eaad55f332d7bdfc9" alt="Image" width="768" height="278" data-path="images/installation/vps-vds/server-config.png" />

Then save and exit the file. Now we need to restart the MariaDB for the settings to come into effect.

```bash theme={null}
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.

<img src="https://mintcdn.com/leaderos/GmBzH65cL-PgW9dg/images/installation/cpanel/install-step-1.png?fit=max&auto=format&n=GmBzH65cL-PgW9dg&q=85&s=3c23415a864f8fc464ec4f74f167aab0" alt="Image" width="2304" height="1086" data-path="images/installation/cpanel/install-step-1.png" />

<Note>If you get "File error! Please contact LeaderOS. (connect.php)" error, assign ownership of the directory with the www-data.</Note>

```bash theme={null}
sudo chown -R www-data:www-data /var/www/your_domain.com/html
```
