| 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | RED='\033[0;31m' |
| 5 | YELLOW='\033[1;33m' |
| 6 | GREEN='\033[0;32m' |
| 7 | LIGHT_BLUE='\033[1;34m' |
| 8 | NC='\033[0m' |
| 9 | |
| 10 | prompt() { |
| 11 | local PROMPT_MESSAGE=$1 |
| 12 | local DEFAULT_VALUE=$2 |
| 13 | read -p "$PROMPT_MESSAGE [$DEFAULT_VALUE]: " INPUT |
| 14 | echo "${INPUT:-$DEFAULT_VALUE}" |
| 15 | } |
| 16 | |
| 17 | confirm_clean_install() { |
| 18 | echo -e ${LIGHT_BLUE}"=================================================================${NC}" |
| 19 | echo -e ${LIGHT_BLUE}" Pterodactyl Panel Installer v1.2.0 for Debian 12 by VS-Shop${NC}" |
| 20 | echo -e ${LIGHT_BLUE}"=================================================================${NC}" |
| 21 | echo -e "${YELLOW}This script is built for a clean installation of Debian 12 (Bookworm).${NC}" |
| 22 | echo -e "${YELLOW}Please confirm your system matches this requirement.${NC}" |
| 23 | echo -e ${LIGHT_BLUE}"=================================================================${NC}" |
| 24 | |
| 25 | while true; do |
| 26 | read -p "Is this a clean installation of Debian 12? (Y/N): " response |
| 27 | case $response in |
| 28 | [Yy]* ) break;; |
| 29 | [Nn]* ) echo -e "${RED}Please reinstall Debian 12 and run the script again.${NC}"; exit;; |
| 30 | * ) echo -e "${RED}Please answer with 'Y' (Yes) or 'N' (No).${NC}";; |
| 31 | esac |
| 32 | done |
| 33 | } |
| 34 | |
| 35 | confirm_clean_install |
| 36 | |
| 37 | DOMAIN=$(prompt "Enter the domain name you want to use for the Pterodactyl panel (e.g., panel.example.com)" "panel.example.com") |
| 38 | ADMIN_EMAIL=$(prompt "Enter an email address for Certbot to use (for urgent renewal notices and security advisories)" "admin@example.com") |
| 39 | |
| 40 | echo -e "${GREEN}Updating system and installing base dependencies...${NC}" |
| 41 | apt update |
| 42 | apt -y install curl gnupg apt-transport-https ca-certificates lsb-release software-properties-common sudo unzip git tar cron |
| 43 | |
| 44 | echo -e "${GREEN}Installing PHP 8.3 and required extensions...${NC}" |
| 45 | echo "deb https://packages.sury.org/php/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/sury-php.list |
| 46 | curl -fsSL https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/sury-php.gpg |
| 47 | |
| 48 | apt update |
| 49 | apt -y install php8.3 php8.3-{cli,common,gd,mysql,mbstring,bcmath,xml,fpm,curl,zip} |
| 50 | |
| 51 | echo -e "${GREEN}Installing MariaDB, NGINX, Redis...${NC}" |
| 52 | apt -y install mariadb-server nginx redis-server |
| 53 | |
| 54 | echo -e "${GREEN}Installing Composer...${NC}" |
| 55 | curl -sS https://getcomposer.org/installer | php |
| 56 | mv composer.phar /usr/local/bin/composer |
| 57 | |
| 58 | echo -e "${GREEN}Creating Pterodactyl installation directory...${NC}" |
| 59 | mkdir -p /var/www/pterodactyl |
| 60 | cd /var/www/pterodactyl |
| 61 | |
| 62 | echo -e "${GREEN}Downloading Pterodactyl panel...${NC}" |
| 63 | curl -Lo panel.tar.gz https://github.com/pterodactyl/panel/releases/latest/download/panel.tar.gz |
| 64 | tar -xzvf panel.tar.gz |
| 65 | chmod -R 755 storage/* bootstrap/cache/ |
| 66 | |
| 67 | echo -e "${GREEN}Setting up the MySQL database for Pterodactyl...${NC}" |
| 68 | DB_USER=$(prompt "Enter the MySQL user for Pterodactyl" "pterodactyl") |
| 69 | DB_PASSWORD=$(prompt "Enter the MySQL password for $DB_USER" "yourPassword") |
| 70 | DB_NAME=$(prompt "Enter the database name for Pterodactyl" "panel") |
| 71 | |
| 72 | mysql -u root <<MYSQL_SCRIPT |
| 73 | CREATE USER '${DB_USER}'@'127.0.0.1' IDENTIFIED BY '${DB_PASSWORD}'; |
| 74 | CREATE DATABASE ${DB_NAME}; |
| 75 | GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'127.0.0.1' WITH GRANT OPTION; |
| 76 | FLUSH PRIVILEGES; |
| 77 | MYSQL_SCRIPT |
| 78 | |
| 79 | echo -e "${GREEN}Installing Composer dependencies...${NC}" |
| 80 | cp .env.example .env |
| 81 | COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --optimize-autoloader |
| 82 | |
| 83 | echo -e "${GREEN}Generating application key...${NC}" |
| 84 | php artisan key:generate --force |
| 85 | |
| 86 | echo -e "${GREEN}Running environment setup...${NC}" |
| 87 | php artisan p:environment:setup |
| 88 | |
| 89 | echo -e "${GREEN}Running database setup...${NC}" |
| 90 | php artisan p:environment:database |
| 91 | |
| 92 | echo -e "${GREEN}Setting up mail environment...${NC}" |
| 93 | php artisan p:environment:mail |
| 94 | |
| 95 | echo -e "${GREEN}Migrating and seeding database...${NC}" |
| 96 | php artisan migrate --seed --force |
| 97 | |
| 98 | echo -e "${GREEN}Creating Pterodactyl admin user...${NC}" |
| 99 | php artisan p:user:make |
| 100 | |
| 101 | echo -e "${GREEN}Setting ownership of Pterodactyl files...${NC}" |
| 102 | chown -R www-data:www-data /var/www/pterodactyl/* |
| 103 | |
| 104 | echo -e "${GREEN}Setting up cron job for schedule...${NC}" |
| 105 | (crontab -l ; echo "* * * * * php /var/www/pterodactyl/artisan schedule:run >> /dev/null 2>&1") | crontab - |
| 106 | |
| 107 | echo -e "${GREEN}Creating systemd service for queue worker...${NC}" |
| 108 | cat <<EOF | tee /etc/systemd/system/pteroq.service |
| 109 | [Unit] |
| 110 | Description=Pterodactyl Queue Worker |
| 111 | After=redis-server.service |
| 112 | |
| 113 | [Service] |
| 114 | User=www-data |
| 115 | Group=www-data |
| 116 | Restart=always |
| 117 | ExecStart=/usr/bin/php /var/www/pterodactyl/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3 |
| 118 | StartLimitInterval=180 |
| 119 | StartLimitBurst=30 |
| 120 | RestartSec=5s |
| 121 | |
| 122 | [Install] |
| 123 | WantedBy=multi-user.target |
| 124 | EOF |
| 125 | |
| 126 | systemctl enable --now redis-server |
| 127 | systemctl enable --now pteroq.service |
| 128 | |
| 129 | echo -e "${GREEN}Creating Nginx configuration for Certbot...${NC}" |
| 130 | cat > /etc/nginx/sites-available/pterodactyl.conf <<EOF |
| 131 | server { |
| 132 | listen 80; |
| 133 | server_name $DOMAIN; |
| 134 | |
| 135 | root /var/www/pterodactyl/public; |
| 136 | index index.html index.htm index.php; |
| 137 | charset utf-8; |
| 138 | |
| 139 | location / { |
| 140 | try_files \$uri \$uri/ /index.php?\$query_string; |
| 141 | } |
| 142 | |
| 143 | location = /favicon.ico { access_log off; log_not_found off; } |
| 144 | location = /robots.txt { access_log off; log_not_found off; } |
| 145 | |
| 146 | access_log off; |
| 147 | error_log /var/log/nginx/pterodactyl.app-error.log error; |
| 148 | |
| 149 | client_max_body_size 100m; |
| 150 | client_body_timeout 120s; |
| 151 | |
| 152 | sendfile off; |
| 153 | |
| 154 | location ~ \.php\$ { |
| 155 | fastcgi_split_path_info ^(.+\.php)(/.+)\$; |
| 156 | fastcgi_pass unix:/run/php/php8.3-fpm.sock; |
| 157 | fastcgi_index index.php; |
| 158 | include fastcgi_params; |
| 159 | fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M"; |
| 160 | fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; |
| 161 | fastcgi_param HTTP_PROXY ""; |
| 162 | fastcgi_intercept_errors off; |
| 163 | fastcgi_buffer_size 16k; |
| 164 | fastcgi_buffers 4 16k; |
| 165 | fastcgi_connect_timeout 300; |
| 166 | fastcgi_send_timeout 300; |
| 167 | fastcgi_read_timeout 300; |
| 168 | } |
| 169 | |
| 170 | location ~ /\.ht { |
| 171 | deny all; |
| 172 | } |
| 173 | } |
| 174 | EOF |
| 175 | |
| 176 | ln -s /etc/nginx/sites-available/pterodactyl.conf /etc/nginx/sites-enabled/pterodactyl.conf |
| 177 | systemctl restart nginx |
| 178 | |
| 179 | echo -e "${GREEN}Installing Certbot...${NC}" |
| 180 | apt -y install certbot python3-certbot-nginx |
| 181 | |
| 182 | echo -e "${GREEN}Obtaining SSL certificate using Certbot...${NC}" |
| 183 | certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email "$ADMIN_EMAIL" -d "$DOMAIN" |
| 184 | |
| 185 | echo -e "${GREEN}Pterodactyl Installation complete on Debian!${NC}" |
| 186 | echo -e "${LIGHT_BLUE}Visit: https://$DOMAIN to begin setup.${NC}" |