403Webshell
Server IP : 65.108.144.40  /  Your IP : 216.73.217.165
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64
User : dev ( 1000)
PHP Version : 8.2.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/project-slim/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/project-slim/setup.sh
#!/bin/bash

# RepoRev API Setup Script
# This script helps set up the Slim 4 + Eloquent application

echo "🚀 RepoRev API Setup Script"
echo "=========================="

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Function to print colored output
print_status() {
    echo -e "${GREEN}[INFO]${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}[WARNING]${NC} $1"
}

print_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

# Check if we're in the right directory
if [ ! -f "composer.json" ]; then
    print_error "composer.json not found. Please run this script from the project root directory."
    exit 1
fi

print_status "Starting RepoRev API setup..."

# Step 1: Install Composer dependencies
print_status "Installing Composer dependencies..."
if command -v composer &> /dev/null; then
    composer install
    if [ $? -eq 0 ]; then
        print_status "✅ Composer dependencies installed successfully"
    else
        print_error "❌ Failed to install Composer dependencies"
        exit 1
    fi
else
    print_error "Composer not found. Please install Composer first."
    exit 1
fi

# Step 2: Create environment file
print_status "Setting up environment configuration..."
if [ ! -f ".env" ]; then
    cp .env.example .env
    print_status "✅ Created .env file from .env.example"
    print_warning "⚠️  Please edit .env file with your database and other configurations"
else
    print_warning "⚠️  .env file already exists, skipping creation"
fi

# Step 3: Create directories if they don't exist
print_status "Creating required directories..."
mkdir -p storage/logs storage/cache storage/uploads storage/temp
mkdir -p logs
chmod -R 755 storage/ logs/
print_status "✅ Created and set permissions for storage directories"

# Step 4: Database setup prompt
print_status "Database Setup"
echo "=============="
read -p "Do you want to set up the database now? (y/n): " setup_db

if [ "$setup_db" = "y" ] || [ "$setup_db" = "Y" ]; then
    read -p "Database host (localhost): " db_host
    db_host=${db_host:-localhost}
    
    read -p "Database name (reporev): " db_name
    db_name=${db_name:-reporev}
    
    read -p "Database username (root): " db_user
    db_user=${db_user:-root}
    
    read -s -p "Database password: " db_pass
    echo
    
    # Update .env file with database credentials
    sed -i.bak "s/DB_HOST=.*/DB_HOST=$db_host/" .env
    sed -i.bak "s/DB_NAME=.*/DB_NAME=$db_name/" .env
    sed -i.bak "s/DB_USER=.*/DB_USER=$db_user/" .env
    sed -i.bak "s/DB_PASS=.*/DB_PASS=$db_pass/" .env
    
    print_status "✅ Updated database configuration in .env"
    
    # Test database connection and create database if it doesn't exist
    print_status "Testing database connection..."
    
    # Create database if it doesn't exist
    mysql -h"$db_host" -u"$db_user" -p"$db_pass" -e "CREATE DATABASE IF NOT EXISTS $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" 2>/dev/null
    
    if [ $? -eq 0 ]; then
        print_status "✅ Database '$db_name' created/verified successfully"
        
        # Import schema
        print_status "Importing database schema..."
        mysql -h"$db_host" -u"$db_user" -p"$db_pass" "$db_name" < database/schema.sql
        
        if [ $? -eq 0 ]; then
            print_status "✅ Database schema imported successfully"
        else
            print_error "❌ Failed to import database schema"
            print_warning "You can manually import it using: mysql -u$db_user -p $db_name < database/schema.sql"
        fi
    else
        print_error "❌ Failed to connect to database or create database"
        print_warning "Please check your database credentials and try again"
    fi
else
    print_warning "⚠️  Skipping database setup. You can set it up manually later."
fi

# Step 5: Generate JWT secret
print_status "Generating JWT secret..."
jwt_secret=$(openssl rand -base64 32 2>/dev/null || head -c32 < /dev/urandom | base64)
sed -i.bak "s/JWT_SECRET=.*/JWT_SECRET=$jwt_secret/" .env
print_status "✅ Generated and updated JWT secret"

# Step 6: Web server configuration
print_status "Web Server Configuration"
echo "========================"
echo "Your application document root should point to: $(pwd)/public"
echo ""
echo "Apache Virtual Host example:"
echo "<VirtualHost *:80>"
echo "    DocumentRoot $(pwd)/public"
echo "    ServerName reporev-api.local"
echo "    <Directory $(pwd)/public>"
echo "        AllowOverride All"
echo "        Require all granted"
echo "    </Directory>"
echo "</VirtualHost>"
echo ""
echo "Don't forget to add 'reporev-api.local' to your /etc/hosts file:"
echo "127.0.0.1    reporev-api.local"

# Step 7: Final steps
print_status "Setup Summary"
echo "============="
print_status "✅ Composer dependencies installed"
print_status "✅ Environment file created"
print_status "✅ Storage directories created"
print_status "✅ JWT secret generated"

if [ "$setup_db" = "y" ] || [ "$setup_db" = "Y" ]; then
    print_status "✅ Database configured and schema imported"
fi

echo ""
print_status "🎉 Setup completed successfully!"
echo ""
print_warning "Next steps:"
echo "1. Configure your web server to point to the /public directory"
echo "2. Update .env file with additional configurations if needed"
echo "3. Test the API endpoints"
echo ""
print_status "Test the API with:"
echo "curl http://your-domain/health"
echo ""
print_status "Happy coding! 🚀"

Youez - 2016 - github.com/yon3zu
LinuXploit