Sep 4, 2024 3 min read

Pterodactyl Panel: Simplifying Self-Hosting

Pterodactyl Panel: Simplifying Self-Hosting
Table of Contents

Pterodactyl Panel is an open-source game server management panel that enables users to host and manage their own game servers with full control and customization. Designed with developers and system administrators in mind, it runs in Docker containers for isolation and efficiency, providing a clean, user-friendly interface to manage multiple servers. In this guide, we’ll cover the steps to install, configure, secure, log, back up, update, and optimize Pterodactyl Panel for self-hosting.

Installing Pterodactyl Panel

πŸ“¦ Docker/Docker Compose Setup

To run Pterodactyl Panel using Docker Compose, create a docker-compose.yml file with the appropriate configurations. This method ensures easy deployment and management.


version: '3.7'

services:

panel:

image: ghcr.io/pterodactyl/panel:latest

container_name: pterodactyl_panel

ports:

- "8080:80"

volumes:

- ./pterodactyl_data:/var/www/html

environment:

- APP_URL=http://yourdomain.com

- DB_HOST=db

- DB_PORT=3306

- DB_USERNAME=pterodactyl

- DB_PASSWORD=yourpassword

depends_on:

- db

db:

image: mysql:5.7

container_name: pterodactyl_db

environment:

- MYSQL_ROOT_PASSWORD=yourrootpassword

- MYSQL_DATABASE=pterodactyl

- MYSQL_USER=pterodactyl

- MYSQL_PASSWORD=yourpassword

volumes:

- ./db_data:/var/lib/mysql

Run the following commands to deploy the stack:


mkdir pterodactyl && cd pterodactyl

nano docker-compose.yml

docker-compose up -d

πŸš€ Manual Installation

For direct installation on a Linux server, follow these steps:

  1. Update the system:

sudo apt update && sudo apt upgrade -y

  1. Install dependencies:

sudo apt install -y curl tar unzip git nginx mysql-server php-cli php-mbstring php-xml php-bcmath php-curl php-zip composer

  1. Download and set up Pterodactyl Panel:

cd /var/www

sudo git clone https://github.com/pterodactyl/panel.git

cd panel

sudo composer install --no-dev --optimize-autoloader

cp .env.example .env

php artisan key:generate

  1. Configure the .env file with your database credentials and other settings, then set permissions:

chown -R www-data:www-data /var/www/panel

chmod -R 755 /var/www/panel/storage /var/www/panel/bootstrap/cache

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

To route traffic to Pterodactyl Panel, create an Nginx server block:


sudo nano /etc/nginx/sites-available/pterodactyl

Add the following configuration:


server {

listen 80;

server_name yourdomain.com;

root /var/www/panel/public;

index index.php index.html;

location / {

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

}

location ~ \.php$ {

include snippets/fastcgi-php.conf;

fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

location ~ /\.ht {

deny all;

}

}

Enable the configuration and reload Nginx:


sudo ln -s /etc/nginx/sites-available/pterodactyl /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

πŸ”’ SSL/TLS Setup

Secure your site with Let's Encrypt:


sudo apt install certbot python3-certbot-nginx -y

sudo certbot --nginx -d yourdomain.com

sudo systemctl reload nginx

Logging and Debugging Pterodactyl Panel

πŸ—ƒοΈ Enabling Debug Logs

Enable debug mode by editing the .env file in your Pterodactyl installation:


nano /var/www/panel/.env

Set the APP_DEBUG variable to true:


APP_DEBUG=true

Restart the application:


php artisan queue:restart

πŸ“„ Viewing Logs

For logs in Docker, use:


docker logs pterodactyl_panel

For manual installations, check logs in the storage/logs directory:


tail -f /var/www/panel/storage/logs/laravel.log

Backup and Restore

πŸ—‚οΈ File-Based Backups

Backup configuration and data:


tar -czvf pterodactyl_backup.tar.gz /var/www/panel /var/lib/mysql

πŸ”„ Database Backups

Export the database:


mysqldump -u pterodactyl -p pterodactyl > pterodactyl_db_backup.sql

Restore the database:


mysql -u pterodactyl -p pterodactyl < pterodactyl_db_backup.sql

πŸ“… Automated Backup Scripts

Use a cron job to automate backups:


crontab -e

Add this line to backup daily:


0 3 * * * tar -czvf /path/to/backup/pterodactyl_$(date +\%F).tar.gz /var/www/panel /var/lib/mysql

Updating and Upgrading Pterodactyl Panel

⬆️ Updating Docker Images

Pull the latest Docker image and restart the container:


docker-compose pull

docker-compose up -d

πŸ› οΈ Manual Updates

For manual installations:


cd /var/www/panel

git pull origin release

composer install --no-dev --optimize-autoloader

php artisan migrate --force

php artisan queue:restart

Leveraging Pterodactyl Panel’s Unique Features

πŸ”§ Enabling APIs

Access the admin panel, navigate to Settings > API, and generate an API key. Use this key in scripts or applications to interact with the panel. Example using curl:


curl -X GET "https://yourdomain.com/api/servers" \

-H "Authorization: Bearer YOUR_API_KEY" \

-H "Accept: application/json"

🌟 Advanced Configurations

To integrate custom tools or plugins, place them in the appropriate directories under /var/www/panel and configure settings in the .env file. For example, to enable Redis:


CACHE_DRIVER=redis

QUEUE_CONNECTION=redis

Restart the queue to apply changes:


php artisan queue:restart

Wrapping Up

This guide provided a comprehensive walkthrough for deploying, configuring, and managing Pterodactyl Panel, a robust solution for self-hosting game servers. With its flexibility, open-source nature, and powerful features, Pterodactyl empowers developers and system administrators to take full control of their hosting environment. Implement the steps here, and you’ll be well on your way to mastering Pterodactyl Panel!

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.