templave v1

This commit is contained in:
2026-03-06 08:57:05 +02:00
commit 17dbdad28b
50 changed files with 8720 additions and 0 deletions

75
deploy/scripts/deploy.sh Normal file
View File

@@ -0,0 +1,75 @@
#!/bin/bash
# Laravel Deployment Script
# Usage: ./deploy.sh /var/www/your-app [branch]
set -e
APP_PATH="${1:-/var/www/laravel}"
BRANCH="${2:-main}"
if [ ! -d "$APP_PATH" ]; then
echo "Error: Directory $APP_PATH does not exist"
exit 1
fi
cd "$APP_PATH"
echo "=========================================="
echo "Deploying Laravel Application"
echo "Path: $APP_PATH"
echo "Branch: $BRANCH"
echo "=========================================="
# Enable maintenance mode
echo "[1/9] Enabling maintenance mode..."
php artisan down --retry=60 || true
# Pull latest code
echo "[2/9] Pulling latest changes..."
git fetch origin
git reset --hard origin/$BRANCH
# Install PHP dependencies
echo "[3/9] Installing Composer dependencies..."
composer install --no-dev --optimize-autoloader --no-interaction
# Install and build frontend assets
echo "[4/9] Installing Node dependencies..."
npm ci --production=false
echo "[5/9] Building frontend assets..."
npm run build
# Run migrations
echo "[6/9] Running database migrations..."
php artisan migrate --force
# Clear and optimize
echo "[7/9] Optimizing application..."
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
# Fix permissions
echo "[8/9] Fixing permissions..."
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
# Restart services
echo "[9/9] Restarting services..."
sudo systemctl restart php8.3-fpm
# Restart queue workers if using Supervisor
if [ -f /etc/supervisor/conf.d/laravel-worker.conf ]; then
sudo supervisorctl restart laravel-worker:*
fi
# Disable maintenance mode
php artisan up
echo ""
echo "=========================================="
echo "Deployment complete!"
echo "=========================================="

View File

@@ -0,0 +1,43 @@
#!/bin/bash
# Fix Laravel file permissions
# Usage: ./fix-permissions.sh /var/www/your-app
set -e
if [ -z "$1" ]; then
echo "Usage: $0 /path/to/laravel/app"
exit 1
fi
APP_PATH="$1"
if [ ! -d "$APP_PATH" ]; then
echo "Error: Directory $APP_PATH does not exist"
exit 1
fi
echo "Fixing permissions for: $APP_PATH"
# Set ownership
sudo chown -R www-data:www-data "$APP_PATH"
# Set directory permissions
sudo find "$APP_PATH" -type d -exec chmod 755 {} \;
# Set file permissions
sudo find "$APP_PATH" -type f -exec chmod 644 {} \;
# Make storage and cache writable
sudo chmod -R 775 "$APP_PATH/storage"
sudo chmod -R 775 "$APP_PATH/bootstrap/cache"
# Set ACL for current user to maintain access
if command -v setfacl &> /dev/null; then
sudo setfacl -Rm u:$(whoami):rwx "$APP_PATH/storage"
sudo setfacl -Rm u:$(whoami):rwx "$APP_PATH/bootstrap/cache"
sudo setfacl -dRm u:$(whoami):rwx "$APP_PATH/storage"
sudo setfacl -dRm u:$(whoami):rwx "$APP_PATH/bootstrap/cache"
fi
echo "Permissions fixed successfully!"

View File

@@ -0,0 +1,6 @@
# Laravel Scheduler Cron Job
# Add this to crontab: sudo crontab -e -u www-data
# Or copy to /etc/cron.d/laravel-scheduler
# Run Laravel scheduler every minute
* * * * * www-data cd /var/www/your-app && php artisan schedule:run >> /dev/null 2>&1

View File

@@ -0,0 +1,202 @@
#!/bin/bash
# Laravel Server Setup Script for Ubuntu 24.04
# Run as root or with sudo
set -e
echo "=========================================="
echo "Laravel Server Setup for Ubuntu 24.04"
echo "=========================================="
# Update system
echo "[1/8] Updating system packages..."
apt update && apt upgrade -y
# Install essential packages
echo "[2/8] Installing essential packages..."
apt install -y \
software-properties-common \
curl \
git \
unzip \
supervisor \
acl
# Add PHP repository and install PHP 8.3
echo "[3/8] Installing PHP 8.3 and extensions..."
add-apt-repository -y ppa:ondrej/php
apt update
apt install -y \
php8.3-fpm \
php8.3-cli \
php8.3-mysql \
php8.3-pgsql \
php8.3-sqlite3 \
php8.3-redis \
php8.3-mbstring \
php8.3-xml \
php8.3-curl \
php8.3-zip \
php8.3-bcmath \
php8.3-intl \
php8.3-gd \
php8.3-imagick \
php8.3-opcache
# Install Composer
echo "[4/8] Installing Composer..."
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Install Node.js 20.x
echo "[5/8] Installing Node.js 20.x..."
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs
# Database selection
echo "[6/8] Database Installation..."
echo ""
echo "Select database server to install:"
echo "1) MySQL 8.0"
echo "2) PostgreSQL 16"
echo "3) SQLite only (no server needed)"
echo "4) Both MySQL and PostgreSQL"
read -p "Enter choice [1-4]: " DB_CHOICE
case $DB_CHOICE in
1)
apt install -y mysql-server
systemctl enable mysql
systemctl start mysql
echo "MySQL 8.0 installed."
echo ""
echo "To secure MySQL, run: sudo mysql_secure_installation"
echo "To create database:"
echo " sudo mysql"
echo " CREATE DATABASE your_app;"
echo " CREATE USER 'your_user'@'localhost' IDENTIFIED BY 'password';"
echo " GRANT ALL PRIVILEGES ON your_app.* TO 'your_user'@'localhost';"
echo " FLUSH PRIVILEGES;"
;;
2)
apt install -y postgresql postgresql-contrib
systemctl enable postgresql
systemctl start postgresql
echo "PostgreSQL 16 installed."
echo ""
echo "To create database:"
echo " sudo -u postgres psql"
echo " CREATE DATABASE your_app;"
echo " CREATE USER your_user WITH ENCRYPTED PASSWORD 'password';"
echo " GRANT ALL PRIVILEGES ON DATABASE your_app TO your_user;"
;;
3)
echo "SQLite selected - no server installation needed."
echo "SQLite is included with PHP (php8.3-sqlite3 already installed)."
;;
4)
apt install -y mysql-server postgresql postgresql-contrib
systemctl enable mysql postgresql
systemctl start mysql postgresql
echo "Both MySQL and PostgreSQL installed."
;;
esac
# Install Redis
echo "[7/8] Installing Redis..."
apt install -y redis-server
systemctl enable redis-server
systemctl start redis-server
# Web server selection
echo "[8/8] Web Server Installation..."
echo ""
echo "Select web server to install:"
echo "1) Nginx (recommended for Nginx Proxy Manager setup)"
echo "2) Apache"
echo "3) Both"
echo "4) Skip (install manually later)"
read -p "Enter choice [1-4]: " WEB_SERVER_CHOICE
case $WEB_SERVER_CHOICE in
1)
apt install -y nginx
systemctl enable nginx
systemctl start nginx
echo "Nginx installed."
;;
2)
apt install -y apache2 libapache2-mod-fcgid
a2enmod rewrite headers ssl proxy_fcgi deflate expires setenvif
systemctl enable apache2
systemctl start apache2
echo "Apache installed with required modules."
;;
3)
apt install -y nginx apache2 libapache2-mod-fcgid
a2enmod rewrite headers ssl proxy_fcgi deflate expires setenvif
systemctl enable nginx apache2
# Stop Apache by default to avoid port conflict
systemctl stop apache2
systemctl start nginx
echo "Both installed. Nginx is running. Apache is stopped (start manually when needed)."
;;
4)
echo "Skipping web server installation."
;;
esac
# Configure PHP-FPM
echo ""
echo "Configuring PHP-FPM..."
cat > /etc/php/8.3/fpm/conf.d/99-laravel.ini << 'EOF'
upload_max_filesize = 100M
post_max_size = 100M
max_execution_time = 300
memory_limit = 512M
opcache.enable = 1
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.validate_timestamps = 0
EOF
systemctl restart php8.3-fpm
# Create web directory
echo ""
echo "Creating web directory structure..."
mkdir -p /var/www
chown -R www-data:www-data /var/www
# Setup firewall
echo ""
echo "Configuring UFW firewall..."
ufw allow OpenSSH
ufw allow 'Nginx Full' 2>/dev/null || true
ufw allow 'Apache Full' 2>/dev/null || true
ufw --force enable
echo ""
echo "=========================================="
echo "Server setup complete!"
echo "=========================================="
echo ""
echo "Installed:"
echo " - PHP 8.3 with FPM and extensions (MySQL, PostgreSQL, SQLite drivers)"
echo " - Composer"
echo " - Node.js 20.x"
echo " - Database server (based on selection)"
echo " - Redis"
echo " - Web server (based on selection)"
echo ""
echo "Next steps:"
echo " 1. Create database and user for your selected database"
echo " 2. Clone your Laravel app to /var/www/your-app"
echo " 3. Copy appropriate .env file from deploy/production/"
echo " - .env.mysql.production"
echo " - .env.pgsql.production"
echo " - .env.sqlite.production"
echo " 4. Configure web server (use configs from deploy/nginx or deploy/apache)"
echo " 5. Set permissions: deploy/scripts/fix-permissions.sh"
echo ""

View File

@@ -0,0 +1,14 @@
# Laravel Scheduler via Supervisor (alternative to cron)
# Copy to: /etc/supervisor/conf.d/laravel-scheduler.conf
# This runs the scheduler in a loop instead of using cron
[program:laravel-scheduler]
process_name=%(program_name)s
command=/bin/bash -c "while [ true ]; do php /var/www/your-app/artisan schedule:run --verbose --no-interaction >> /var/www/your-app/storage/logs/scheduler.log 2>&1; sleep 60; done"
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/your-app/storage/logs/supervisor-scheduler.log
stopwaitsecs=60

View File

@@ -0,0 +1,12 @@
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/your-app/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=2
redirect_stderr=true
stdout_logfile=/var/www/your-app/storage/logs/worker.log
stopwaitsecs=3600