Files

81 lines
2.7 KiB
Plaintext
Raw Permalink Normal View History

2025-10-09 19:17:45 -07:00
#!/bin/bash -x
2025-10-09 18:42:33 -07:00
2025-10-09 18:44:07 -07:00
# Load env variables
source .env
2025-10-09 19:08:53 -07:00
# Get the script's directory
SCRIPT_PATH=$(dirname "$(realpath "${BASH_SOURCE[0]}")")
2025-10-09 18:42:33 -07:00
# Enable nginx to start with system
sudo systemctl enable --now nginx
# Setup nginx
sudo rm /etc/nginx/sites-enabled/default
2025-10-09 21:00:10 -07:00
sudo cp $SCRIPT_PATH/nginx/wordpress /etc/nginx/sites-available
2025-10-09 21:52:46 -07:00
sudo sed -i "s|example\.com|$WP_DOMAIN_NAME|g" /etc/nginx/sites-available/wordpress
2025-10-09 19:08:53 -07:00
sudo ln -fs /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
2025-10-09 18:42:33 -07:00
# Check for error
sudo nginx -t
# Restart nginx after loading wordpress config
sudo systemctl restart nginx
# PHP
sudo systemctl enable --now php8.4-fpm
2025-10-09 18:52:19 -07:00
# Set limit to post size and upload file size
2025-10-09 18:46:49 -07:00
sudo sed -i "s/^post_max_size = 8M/post_max_size = $POST_MAX_SIZE/g" /etc/php/8.4/fpm/php.ini
2025-10-10 08:20:51 -07:00
sudo sed -i "s/^upload_max_filesize = 2M/upload_max_filesize = $UPLOAD_MAX_FILE_SIZE/g" /etc/php/8.4/fpm/php.ini
2025-10-09 18:42:33 -07:00
2025-10-09 18:52:19 -07:00
# Set max processing children for php
2025-10-09 18:42:33 -07:00
sudo sed -i "s/^pm = dynamic/pm = ondemand/g" /etc/php/8.4/fpm/pool.d/www.conf
2025-10-09 18:51:08 -07:00
sudo sed -i "s/^pm.max_children = 5/pm.max_children = $PM_MAX_CHILDREN/g" /etc/php/8.4/fpm/pool.d/www.conf
2025-10-09 18:42:33 -07:00
# Start php-fpm
sudo systemctl restart php8.4-fpm
# MariaDB
sudo systemctl enable --now mariadb
# Secure MariaDB
2025-10-09 20:44:04 -07:00
printf "$DB_PASSWORD\nn\nY\n$DB_PASSWORD\n$DB_PASSWORD\nY\nY\nY\nY\n" | sudo mariadb-secure-installation
2025-10-09 18:42:33 -07:00
2025-10-10 07:04:30 -07:00
sudo systemctl restart mariadb
2025-10-09 20:27:02 -07:00
sudo mysql <<EOF
2025-10-10 07:09:38 -07:00
DROP DATABASE $DB_NAME;
2025-10-09 20:44:46 -07:00
CREATE DATABASE $DB_NAME;
2025-10-10 07:07:44 -07:00
DROP USER '$DB_USER'@'$DB_HOST';
CREATE USER '$DB_USER'@'$DB_HOST' IDENTIFIED BY '$DB_PASSWORD';
2025-10-10 07:00:04 -07:00
GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'$DB_HOST';
2025-10-09 20:27:02 -07:00
EOF
2025-10-09 20:06:01 -07:00
# WordPress
2025-10-09 20:19:31 -07:00
2025-10-09 20:49:22 -07:00
# Composer installation
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'ed0feb545ba87161262f2d45a633e34f591ebb3381f2e0063c345ebea4d228dd0043083717770234ec00c5a9f9593792') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
2025-10-10 06:41:50 -07:00
cd /home/debian
2025-10-09 21:45:38 -07:00
composer create-project roots/bedrock $WP_DOMAIN_NAME
2025-10-10 06:41:50 -07:00
cd /home/debian/$WP_DOMAIN_NAME
2025-10-10 06:51:43 -07:00
cp $SCRIPT_PATH/.env .env
2025-10-10 06:41:50 -07:00
composer install
sudo su <<EOF
2025-10-10 06:53:34 -07:00
rm -r /var/www/*
2025-10-10 06:41:50 -07:00
usermod -a -G www-data debian
mv /home/debian/$WP_DOMAIN_NAME /var/www
chown www-data:www-data -R /var/www
2025-10-10 07:31:11 -07:00
chmod -R g+w /var/www/$WP_DOMAIN_NAME
2025-10-10 06:41:50 -07:00
find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;
2025-10-10 10:31:26 -06:00
EOF
# Cloudflared
curl --location --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb && sudo dpkg -i cloudflared.deb
sudo systemctl restart cloudflared.service