Files
Epicnabbo-Catalogus-Updated…/Updated_Cms/setup_linux_nginx.sh
T

90 lines
2.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="${1:-/var/www/atomcms/app}"
SERVER_NAME="${2:-_}"
PHP_VERSION="8.5"
echo "Preparing system packages"
sudo apt-get update -y
sudo apt-get install -y software-properties-common curl gnupg2 ca-certificates lsb-release
echo "Adding PHP repository"
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update -y
echo "Installing PHP ${PHP_VERSION} and extensions"
sudo apt-get install -y "php${PHP_VERSION}-fpm" "php${PHP_VERSION}-cli" "php${PHP_VERSION}-curl" "php${PHP_VERSION}-mbstring" "php${PHP_VERSION}-gd" "php${PHP_VERSION}-intl" "php${PHP_VERSION}-mysql" "php${PHP_VERSION}-bcmath" "php${PHP_VERSION}-zip"
echo "Installing Nginx"
sudo apt-get install -y nginx
echo "Installing Composer and Yarn"
sudo apt-get install -y composer nodejs npm
sudo npm install -g yarn
echo "Ensuring application directory exists: ${ROOT_DIR}"
if [ ! -d "${ROOT_DIR}" ]; then
echo "Directory ${ROOT_DIR} does not exist. Clone the repository into this path and rerun."
exit 1
fi
cd "${ROOT_DIR}"
if [ ! -f ".env" ]; then
cp .env.example .env || true
fi
echo "Installing PHP dependencies"
composer install --no-interaction --prefer-dist --optimize-autoloader
echo "Generating app key"
php artisan key:generate || true
echo "Installing JS dependencies"
yarn install --silent
echo "Building assets (Atom theme)"
yarn run build:atom
echo "Setting permissions"
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
NGINX_CONF="/etc/nginx/sites-available/atomcms.conf"
echo "Writing Nginx server block to ${NGINX_CONF}"
sudo tee "${NGINX_CONF}" >/dev/null <<EOF
server {
listen 80;
server_name ${SERVER_NAME};
root ${ROOT_DIR}/public;
index index.php index.html;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
location / {
try_files \$uri \$uri/ /index.php?\$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php${PHP_VERSION}-fpm.sock;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
EOF
echo "Enabling Nginx site"
sudo ln -sf "${NGINX_CONF}" /etc/nginx/sites-enabled/atomcms.conf
sudo nginx -t
sudo systemctl reload nginx
sudo systemctl enable --now "php${PHP_VERSION}-fpm"
echo "Setup complete. If using a domain, update DNS. Visit http://${SERVER_NAME}/"