Kreezcraft

Installing Pterodactyl on Ubuntu 24

Introduction: Pterodactyl is a robust platform for managing game servers, but setting it up on Ubuntu 24 can present unique challenges. While most resources available focus on Ubuntu 22, this guide takes things a step further, showcasing an all-in-one script tailored for Ubuntu 24. This script not only fixes common issues but also gives you the nuclear option to completely reinstall Pterodactyl—ideal for those who need a fresh start. Note that while some of the steps might work on Ubuntu 23, this guide specifically targets Ubuntu 24, and mileage may vary for other versions. The Challenges: During my Pterodactyl setup on Ubuntu 24, I encountered several roadblocks—permissions errors, outdated Node.js warnings, and package dependency issues. Fixing these required more than just a standard approach. After a deep dive into troubleshooting, I compiled a script that handles everything from removing the old installation to setting up a fresh instance with correct permissions. The Solution: This script was crafted to nuke your existing installation from orbit and then rebuild everything from scratch, fixing permissions along the way. It’s designed to automate the most time-consuming tasks, allowing you to get your server up and running faster. Here’s the script that saved the day: bash
#!/bin/bash

echo "Starting Pterodactyl nuke and reinstall process..."

# Stop services
echo "Stopping Nginx and PHP-FPM services..."
systemctl stop nginx
systemctl stop php8.1-fpm

# Remove existing Pterodactyl installation
echo "Removing existing Pterodactyl installation..."
rm -rf /var/www/pterodactyl

# Remove database
echo "Dropping Pterodactyl database..."
mysql -u root -p -e "DROP DATABASE IF EXISTS pterodactyl;"

# Remove Pterodactyl user
echo "Removing Pterodactyl user..."
userdel -r pterodactyl

# Reinstall dependencies
echo "Reinstalling dependencies..."
apt-get update
apt-get install -y apt-transport-https ca-certificates curl gnupg

# Add NodeSource repository
echo "Adding Node.js repository..."
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -

# Install Node.js and Yarn
echo "Installing Node.js and Yarn..."
apt-get install -y nodejs
npm install -g yarn

# Clone Pterodactyl panel
echo "Cloning Pterodactyl panel..."
mkdir -p /var/www/pterodactyl
cd /var/www/pterodactyl
curl -Lo panel.tar.gz https://github.com/pterodactyl/panel/releases/latest/download/panel.tar.gz
tar -xzvf panel.tar.gz
rm panel.tar.gz
cp .env.example .env

# Install PHP dependencies
echo "Installing PHP dependencies..."
apt-get install -y software-properties-common
add-apt-repository -y ppa:ondrej/php
apt-get update
apt-get install -y php8.1 php8.1-fpm php8.1-mysql php8.1-cli php8.1-xml php8.1-mbstring php8.1-curl php8.1-zip

# Install Composer
echo "Installing Composer..."
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

# Install Pterodactyl dependencies
echo "Installing Pterodactyl dependencies..."
composer install --no-dev --optimize-autoloader

# Set permissions
echo "Setting permissions for Pterodactyl directory..."
chown -R www-data:www-data /var/www/pterodactyl
chmod -R 755 /var/www/pterodactyl

# Generate app key
echo "Generating app key..."
php artisan key:generate --force

# Configure Pterodactyl
echo "Configuring Pterodactyl..."
php artisan p:environment:setup
php artisan p:environment:database
php artisan p:environment:mail

# Run migrations
echo "Running migrations..."
php artisan migrate --force

# Fix cross-env permissions
echo "Fixing permissions for cross-env..."
chown -R www-data:www-data /var/www/pterodactyl/vendor/laravel

# Install frontend dependencies
echo "Installing frontend dependencies..."
yarn install --force

# Build frontend assets
echo "Building frontend assets..."
yarn run build:production --force

# Set permissions for storage and cache
echo "Setting permissions for storage and cache..."
chown -R www-data:www-data /var/www/pterodactyl/storage /var/www/pterodactyl/bootstrap/cache

# Clear caches
echo "Clearing Laravel caches..."
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear

# Restart services
echo "Restarting Nginx and PHP-FPM services..."
systemctl start nginx
systemctl start php8.1-fpm

echo "Pterodactyl installation and setup completed successfully!"
How to Use the Script: Backup Your Data: Before running this script, ensure that you have backed up your important data, especially your databases and any custom configurations. Run the Script: Simply copy the script to a file, make it executable, and run it. The script will take care of stopping services, removing existing installations, and setting up a fresh instance of Pterodactyl with all necessary dependencies. Check Permissions: The script includes steps to fix permissions, ensuring that Pterodactyl runs smoothly without any permission errors. Conclusion: This guide and script should give you a solid foundation for managing Pterodactyl on Ubuntu 24. While parts of this process may work on Ubuntu 23, it’s specifically tailored for Ubuntu 24. If you’re struggling with your installation or just need a fresh start, this script could be the silver bullet you’ve been searching for. Share your experiences and let me know if this worked for you on my Discord. Happy hosting!