Skip to content

Installation on Ubuntu 18.04 LTS, 16.04 LTS, Debian 10, Debian 9

siaimes edited this page Jan 7, 2021 · 8 revisions

1. Install Nginx

Update system:

sudo apt-get update
sudo apt-get upgrade

Install Nginx:

sudo apt-get install nginx -y

Remove the default Nginx configuration file:

sudo rm /etc/nginx/sites-enabled/default

Make a copy of the default configuration file:

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/www.example.com

where www.example.com is your actual server name.

Edit your site definition:

sudo vi /etc/nginx/sites-available/www.example.com

Enter your actual server name. For example:

server_name www.example.com;

Create a symbolic link from your site configuration file to the /etc/nginx/sites-enabled/ directory:

sudo ln -s /etc/nginx/sites-available/www.example.com /etc/nginx/sites-enabled/

Restart Nginx:

sudo systemctl restart nginx

2. Install Free SSL Certificate

Install Cerbot for Nginx according to the official documentation depending on the Linux distribution you choose. Then run Certbot:

sudo certbot --nginx
  1. Enter email address
  2. Enter a for agree
  3. Enter y or n for email address sent to Electronic Frontier Foundation
  4. If a list of domain names appears, enter the number of your domain name from the list
  5. Enter 2 if you want to force HTTPS

Set up Certbot to do renewal every 90 days:

sudo certbot renew --dry-run

Open a browser and do an initial test of the HTTPS version of the website. You will see a message, "Welcome to nginx!"

3. Install MariaDB

Install packages:

sudo apt install mariadb-server -y

Secure MariaDB:

sudo mysql_secure_installation
  1. There is no current password for root, so press Enter
  2. Enter y to set root password
  3. Enter new root password
  4. Re-enter new password
  5. Enter y to remove anonymous users
  6. Enter y to disallow root login remotely
  7. Enter y to remove test database and access to it
  8. Enter y to reload privilege tables now

4. Create Database and User

Generate a strong password for the MariaDB user:

openssl rand -base64 12

Example result:

RzNjmuA3kokja9qL

Log into MariaDB as root:

sudo mysql -u root -p

Enter the password you chose for the root user when you did mysql_secure_installation.

Create a database for Trojan-Panel

CREATE DATABASE trojan;

Create a user for the Trojan-Panel database with the strong password generated above:

GRANT ALL PRIVILEGES ON trojan.* to trojan@'%' IDENTIFIED BY 'RzNjmuA3kokja9qL';

Reload privileges:

FLUSH PRIVILEGES;

Check that database and user now exist:

SHOW DATABASES;
SELECT User FROM mysql.user;

Quit MariaDB shell:

quit;

5. Install PHP

For Ubuntu 16.04 LTS:

sudo apt install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install -y php7.2-fpm php7.2-mysql php7.2-cli php7.2-xml php7.2-json php7.2-mbstring php7.2-tokenizer php7.2-bcmath

For Debian 9:

sudo apt install -y apt-transport-https ca-certificates
wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update
sudo apt install -y php7.2-fpm php7.2-mysql php7.2-cli php7.2-xml php7.2-json php7.2-mbstring php7.2-tokenizer php7.2-bcmath

For other Linux distributions indicated in the title:

sudo apt install php-fpm php-mysql php-cli php-xml php-json php-mbstring php-tokenizer php-bcmath

6. Configure Nginx for PHP

Update your site definition:

sudo vi /etc/nginx/sites-available/www.example.com

Add index.php as the first possibility for index file:

index index.php index.html index.htm index.nginx-debian.html;

Uncomment PHP location block, and make sure unix socket file name corresponds to the PHP version you installed(One can use php -v to identify the version of PHP):

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

Restart Nginx:

sudo systemctl restart nginx

Build a test page:

sudo vi /var/www/html/index.php

Insert contents:

<?php
  phpinfo();
?>

Test the HTTPS index page. You will see the PHP info page.

7. Install Trojan-Panel Prerequisites

Install Laravel prerequisites:

sudo apt install curl git unzip -y

Install PHP composer:

cd /var/www
sudo curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Install NodeJS and NPM:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt install nodejs
node -v
npm -v

8. Install Trojan-Panel

Note: run as a non-root user, otherwise you will get an error when running npm install.

sudo git clone https://github.com/trojan-gfw/trojan-panel.git
sudo chown -R $USER:$USER trojan-panel
cd trojan-panel
composer install
npm install

9. Set Up Trojan-Panel Environment

Copy the the sample environment variable file to its final destination:

cp .env.example .env

Generate an app encryption key:

php artisan key:generate

Edit the environment file:

vi .env

Set values for APP_URL and DB_PASSWORD. For example:

APP_URL=https://www.example.com

and

DB_PASSWORD=RzNjmuA3kokja9qL

Create tables:

php artisan migrate

Enter yes to confirm that you want to run the command.

10. Test

Update your site definition again:

sudo vi /etc/nginx/sites-available/www.example.com

Make /var/www/trojan-panel/public the new web root:

root /var/www/trojan-panel/public;

Insert index.php into URLs:

try_files $uri $uri/ /index.php?$query_string;

Change owner to web server:

sudo chown -R www-data:www-data /var/www/trojan-panel
cd ~

Restart Nginx:

sudo systemctl restart nginx

Test access to site.

If there are errors:

sudo tail /var/log/nginx/error.log

Now you can modify the mysql block of your trojan server to point to the panel server. Please refer to the authenticator documentation for how to use the panel.