HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux Bradford-Sitios 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: www-data (33)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/create-vhost-sincerbot.sh
#!/bin/bash

# Script para crear vhosts automáticamente
# Uso: ./create-vhost.sh <dominio> <carpeta> [laravel|static]

if [ $# -lt 2 ]; then
    echo "Uso: ./create-vhost.sh <dominio> <carpeta> [laravel|static]"
    echo "Ejemplo: ./create-vhost.sh api-control-accesos.hitch.cl control_accesos_api laravel"
    echo "Ejemplo: ./create-vhost.sh control-accesos.hitch.cl control_accesos static"
    exit 1
fi

DOMAIN=$1
FOLDER=$2
TYPE=${3:-laravel}
WEBROOT="/var/www/$FOLDER"

if [ ! -d "$WEBROOT" ]; then
    echo "Error: La carpeta $WEBROOT no existe"
    exit 1
fi

if [ "$TYPE" = "laravel" ]; then
    DOCROOT="$WEBROOT/public"
    if [ ! -d "$DOCROOT" ]; then
        echo "Error: La carpeta $DOCROOT no existe (proyecto Laravel debe tener /public)"
        exit 1
    fi
else
    DOCROOT="$WEBROOT"
fi

echo "=== Creando VHost para $DOMAIN ==="
echo "Carpeta: $WEBROOT"
echo "DocumentRoot: $DOCROOT"
echo "Tipo: $TYPE"
echo ""

echo "[1/5] Creando configuración del vhost..."
cat > /etc/apache2/sites-available/$DOMAIN.conf << EOF
<VirtualHost *:80>
    ServerAdmin webmaster@hitch.cl
    ServerName $DOMAIN
    ServerAlias $DOMAIN
    DocumentRoot $DOCROOT

    <Directory $DOCROOT>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog \${APACHE_LOG_DIR}/$DOMAIN-error.log
    CustomLog \${APACHE_LOG_DIR}/$DOMAIN-access.log combined
</VirtualHost>
EOF

echo "[2/5] Configurando permisos..."
#chown -R root:www-data $WEBROOT
chown -R azureuser:www-data $WEBROOT
find $WEBROOT -type d -exec chmod 755 {} \;
find $WEBROOT -type f -exec chmod 644 {} \;
find $WEBROOT -type d -exec chmod g+s {} \;

if [ "$TYPE" = "laravel" ]; then
    echo "[3/5] Configurando permisos de Laravel..."
    [ -d "$WEBROOT/storage" ] && chown -R www-data:www-data $WEBROOT/storage && chmod -R 775 $WEBROOT/storage
    [ -d "$WEBROOT/bootstrap/cache" ] && chown -R www-data:www-data $WEBROOT/bootstrap/cache && chmod -R 775 $WEBROOT/bootstrap/cache
else
    echo "[3/5] Proyecto estático, omitiendo permisos especiales"
fi

echo "[4/5] Habilitando sitio..."
a2ensite $DOMAIN.conf > /dev/null 2>&1

echo "[5/5] Recargando Apache..."
systemctl reload apache2
if [ $? -ne 0 ]; then
    echo "Advertencia: Apache tuvo warnings"
fi

echo ""
echo "=================================="
echo "✅ VHost creado exitosamente"
echo "=================================="
echo "Dominio: $DOMAIN"
echo "URL: http://$DOMAIN"
echo "Carpeta: $WEBROOT"
echo "DocumentRoot: $DOCROOT"