2024-10-14 12:15:11 -07:00
|
|
|
#!/usr/bin/env bash
|
2023-04-05 07:53:20 -07:00
|
|
|
|
2023-05-27 11:13:18 -07:00
|
|
|
if [ -z "$PHPVER" ]; then
|
2025-07-16 05:56:33 -07:00
|
|
|
PHPVER="83";
|
2023-05-27 11:13:18 -07:00
|
|
|
fi
|
|
|
|
|
|
2025-07-20 12:06:15 -07:00
|
|
|
if [ -z "$environment" ]; then
|
|
|
|
|
environment="PROD"
|
|
|
|
|
fi
|
|
|
|
|
|
2023-04-05 07:53:20 -07:00
|
|
|
adduser -u $uid $user
|
|
|
|
|
|
|
|
|
|
mkdir -p /home/$user/public_html
|
2024-10-14 19:30:51 -07:00
|
|
|
mkdir -p /home/$user/logs/{apache,php-fpm}
|
2023-04-05 07:53:20 -07:00
|
|
|
|
2024-10-14 19:30:51 -07:00
|
|
|
mv /var/log/httpd /var/log/httpd.bak
|
|
|
|
|
|
|
|
|
|
ln -s /home/$user/logs/apache /var/log/httpd
|
|
|
|
|
ln -s /home/$user/logs/php-fpm /var/log/php-fpm
|
2023-04-05 07:53:20 -07:00
|
|
|
|
2024-12-17 21:44:09 -08:00
|
|
|
rm -f /etc/httpd/conf.d/userdir.conf
|
|
|
|
|
docker_network=$(ip addr show |grep eth0 |grep inet |awk -F " " {'print $2'})
|
|
|
|
|
echo "RemoteIPInternalProxy $docker_network" >> /etc/httpd/conf.d/remoteip.conf
|
2025-07-16 07:55:03 -07:00
|
|
|
# /scripts/install-php$PHPVER.sh
|
2023-05-27 11:13:18 -07:00
|
|
|
|
2026-02-25 18:52:15 -08:00
|
|
|
source /scripts/detect-memory.sh
|
|
|
|
|
echo "Container memory: ${CONTAINER_MEMORY_MB}MB | PHP-FPM pm=${PHP_FPM_PM} max_children=${PHP_FPM_MAX_CHILDREN} | Apache workers=${APACHE_MAX_REQUEST_WORKERS}"
|
|
|
|
|
|
2023-04-05 07:53:20 -07:00
|
|
|
/scripts/create-vhost.sh
|
|
|
|
|
/scripts/create-php-config.sh
|
2026-02-25 18:52:15 -08:00
|
|
|
/scripts/create-apache-mpm-config.sh
|
2023-04-05 07:53:20 -07:00
|
|
|
|
2024-10-14 19:30:51 -07:00
|
|
|
if [ -f /etc/httpd/conf.d/ssl.conf ]; then
|
|
|
|
|
mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.bak
|
|
|
|
|
fi
|
2024-10-14 12:15:11 -07:00
|
|
|
|
2023-04-05 07:53:20 -07:00
|
|
|
/usr/sbin/httpd -k start
|
|
|
|
|
/usr/sbin/php-fpm -y /etc/php-fpm.conf
|
2024-10-14 19:30:51 -07:00
|
|
|
chown -R $user:$user /home/$user
|
2026-10-20 12:33:29 -07:00
|
|
|
# Do NOT `chmod -R 755` the docroot here. /home/$user is the customer's
|
|
|
|
|
# bind-mounted site directory; a recursive 755 on every start made every file
|
|
|
|
|
# (wp-config.php included) world-readable AND executable, and reverted any
|
|
|
|
|
# tighter permissions the customer had set. Apache (shared-httpd, or the
|
|
|
|
|
# bundled httpd) runs as `apache`, not the customer, so it only needs to
|
|
|
|
|
# traverse directories to serve static files. Normalise that and nothing else:
|
|
|
|
|
# open the docroot itself, and add o+x to directories that lack it. Regular
|
|
|
|
|
# files are never touched, so execute is never added and wp-config.php is
|
|
|
|
|
# never loosened.
|
|
|
|
|
chmod 755 /home/$user
|
|
|
|
|
find /home/$user -type d ! -perm -o=x -exec chmod o+x {} +
|
2023-04-05 07:53:20 -07:00
|
|
|
|
2023-04-06 17:27:02 -07:00
|
|
|
if [[ $environment == 'DEV' ]]; then
|
2023-04-05 07:53:20 -07:00
|
|
|
echo "Starting Dev Deployment"
|
2024-10-14 19:30:51 -07:00
|
|
|
mkdir -p /home/$user/_db_backups
|
2025-07-16 07:55:03 -07:00
|
|
|
# Ensure microdnf is available for installing MariaDB and memcached in DEV mode
|
|
|
|
|
if ! command -v microdnf &> /dev/null; then
|
|
|
|
|
echo "microdnf not found, installing with dnf..."
|
|
|
|
|
dnf install -y microdnf && dnf clean all
|
|
|
|
|
fi
|
2025-07-16 05:56:33 -07:00
|
|
|
microdnf install -y MariaDB-server MariaDB-client memcached
|
2025-07-20 12:06:15 -07:00
|
|
|
sed -r -i 's/session.save_path="memcache:11211/session.save_path="localhost:11211/' /etc/php.ini
|
2023-04-05 07:53:20 -07:00
|
|
|
nohup mysqld -umysql &
|
2024-10-14 12:15:11 -07:00
|
|
|
if [ ! -f /home/$user/mysql_creds ]; then
|
2023-04-05 07:53:20 -07:00
|
|
|
echo "Give MySQL a chance to finish starting..."
|
|
|
|
|
sleep 10
|
|
|
|
|
mysql_user=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13 ; echo '')
|
|
|
|
|
mysql_password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 18 ; echo '')
|
|
|
|
|
mysql_db=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 6 ; echo '')
|
|
|
|
|
mysql -e "CREATE DATABASE devdb_"$mysql_db";"
|
|
|
|
|
mysql -e "CREATE USER '"$mysql_user"'@'localhost' IDENTIFIED BY '"$mysql_password"';"
|
|
|
|
|
mysql -e "GRANT ALL PRIVILEGES ON *.* TO '"$mysql_user"'@'localhost' WITH GRANT OPTION;"
|
|
|
|
|
mysql -e "FLUSH PRIVILEGES;"
|
2025-08-13 07:36:35 -07:00
|
|
|
# Create user crontab with MySQL backup job
|
|
|
|
|
echo "# User crontab for $user" > /home/$user/crontab
|
|
|
|
|
echo "*/15 * * * * /scripts/mysql-backup.sh $user devdb_$mysql_db" >> /home/$user/crontab
|
|
|
|
|
chown $user:$user /home/$user/crontab
|
2024-10-14 12:15:11 -07:00
|
|
|
echo "MySQL User: "$mysql_user > /home/$user/mysql_creds
|
|
|
|
|
echo "MySQL Password: "$mysql_password >> /home/$user/mysql_creds
|
|
|
|
|
echo "MySQL Database: devdb_"$mysql_db >> /home/$user/mysql_creds
|
|
|
|
|
cat /home/$user/mysql_creds
|
2024-10-02 13:21:49 -07:00
|
|
|
|
2023-04-05 07:53:20 -07:00
|
|
|
fi
|
|
|
|
|
/usr/bin/memcached -d -u $user
|
2024-10-02 13:21:49 -07:00
|
|
|
|
2023-04-05 07:53:20 -07:00
|
|
|
fi
|
2024-08-12 21:20:00 -04:00
|
|
|
|
|
|
|
|
if [[ $environment == 'PROD' ]]; then
|
|
|
|
|
sed -r -i 's/;session.save_path="localhost:11211/session.save_path="memcache:11211/' /etc/php.d/50-memcached.ini
|
|
|
|
|
fi
|
2025-08-13 07:36:35 -07:00
|
|
|
|
|
|
|
|
# Set up user crontab
|
|
|
|
|
if [ ! -f /home/$user/crontab ]; then
|
|
|
|
|
echo "# User crontab for $user" > /home/$user/crontab
|
|
|
|
|
echo "# Add your cron jobs here" >> /home/$user/crontab
|
|
|
|
|
echo "# Example: */5 * * * * /home/$user/scripts/my-script.sh" >> /home/$user/crontab
|
|
|
|
|
chown $user:$user /home/$user/crontab
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Load user crontab
|
|
|
|
|
crontab -u $user /home/$user/crontab
|
|
|
|
|
|
2024-10-14 12:15:11 -07:00
|
|
|
/usr/sbin/crond
|
2024-10-14 19:30:51 -07:00
|
|
|
tail -f /var/log/httpd/*
|
2023-04-05 07:53:20 -07:00
|
|
|
|
|
|
|
|
exit 0
|
2024-08-12 21:20:00 -04:00
|
|
|
|