Finished Cloud Apache Container

This commit is contained in:
Josh Knapp 2023-04-05 07:53:20 -07:00
parent 65f98084d6
commit 95b9397067
14 changed files with 1778 additions and 7 deletions

View File

@ -1,13 +1,23 @@
FROM almalinux/8-base:latest
ARG PHPVER=81
RUN dnf update -y && dnf upgrade -y
RUN dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
RUN dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
RUN dnf update -y && dnf upgrade -y
RUN dnf module reset php -y
RUN dnf module enable php:remi-8.1
RUN dnf install -y httpd wget php php-fpm php-mysqlnd php-xml php-pecl-zip php-sodium php-soap php-pecl-xmlrpc \
php-pecl-redis5 php-pecl-memcached php-pecl-memcache php-pecl-ip2location php-pecl-imagick php-pecl-geoip \
php-mysqlnd php-mbstring php-ioncube-loader php-intl php-gd libzip php-cli
RUN yum clean all
RUN dnf install -y memcached httpd mod_ssl wget
RUN openssl req -newkey rsa:2048 -nodes -keyout /etc/pki/tls/private/localhost.key -x509 -days 3650 -subj "/CN=localhost" -out /etc/pki/tls/certs/localhost.crt
RUN mkdir /run/php-fpm/
RUN mkdir /scripts
COPY ./scripts/* /scripts/
RUN chmod +x /scripts/*
RUN /scripts/install-php$PHPVER.sh
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
RUN chmod +x wp-cli.phar
RUN mv wp-cli.phar /usr/local/bin/wp
COPY ./configs/default-index.conf /etc/httpd/conf.d/
COPY ./configs/prod-php.ini /etc/php.ini
COPY ./configs/phpinfo.php /var/www/html/index.php
COPY ./configs/mariadb.repo /etc/yum.repos.d/
RUN yum clean all
ENTRYPOINT [ "/scripts/entrypoint.sh" ]

View File

@ -0,0 +1 @@
//ToDO

View File

@ -0,0 +1 @@
DirectoryIndex index.html index.htm index.php

11
configs/mariadb.repo Normal file
View File

@ -0,0 +1,11 @@
# MariaDB 10.11 CentOS repository list - created 2023-04-03 23:52 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
# rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# baseurl = https://rpm.mariadb.org/10.11/centos/$releasever/$basearch
baseurl = https://mirrors.xtom.com/mariadb/yum/10.11/centos/$releasever/$basearch
module_hotfixes = 1
# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgkey = https://mirrors.xtom.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

13
configs/phpinfo.php Normal file
View File

@ -0,0 +1,13 @@
<?php
session_start();
echo shell_exec("whoami");
if ( !isset($_SESSION["number"]) ) {
$_SESSION["number"] = 1;
echo "New Session";
echo $_SESSION["number"];
}else {
$_SESSION["number"] = $_SESSION["number"] + 1;
echo $_SESSION["number"];
}
phpinfo();
?>

1525
configs/prod-php.ini Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,53 @@
<Directory "/home/~~user~~">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/home/~~user~~/public_html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options All MultiViews
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
<VirtualHost _default_:*>
ServerName "~~domain~~"
DocumentRoot "/home/~~user~~/public_html"
RewriteEngine on
RewriteCond %{SERVER_NAME} =~~domain~~
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName "~~domain~~"
DocumentRoot "/home/~~user~~/public_html"
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
</VirtualHost>
</IfModule>

View File

@ -0,0 +1,32 @@
#!/bin/bash
rm /etc/php-fpm.d/www.conf
cat <<EOF > /etc/php-fpm.d/$user.conf
[$user]
user = $user
group = $user
listen = /run/php-fpm/www.sock
listen.owner = apache
listen.group = apache
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.process_idle_timeout = 15s;
pm.max_requests = 500
slowlog = /var/log/php-fpm/www-slow.log
request_slowlog_timeout = 6s
php_admin_value[error_log] = /etc/httpd/logs/error_log
php_admin_flag[log_errors] = on
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache
EOF
exit 0

49
scripts/create-vhost.sh Normal file
View File

@ -0,0 +1,49 @@
#!/bin/bash
alias_block=''
#Create Server Alias Block
if [ ! -z $serveralias ]; then
for alias in $(echo $serveralias | tr ',' ' ')
do
alias_block=$alias_block"ServerAlias $alias
"
done
fi
cat <<EOF > /etc/httpd/conf.d/$domain.conf
<Directory "/home/$user">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/home/$user/public_html">
Options All MultiViews
AllowOverride All
Require all granted
</Directory>
<VirtualHost _default_:*>
ServerName "$domain"
$alias_block
DocumentRoot "/home/$user/public_html"
RewriteEngine on
RewriteCond %{SERVER_NAME} =$domain
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName "$domain"
$alias_block
DocumentRoot "/home/$user/public_html"
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
</VirtualHost>
</IfModule>
EOF

40
scripts/entrypoint.sh Normal file
View File

@ -0,0 +1,40 @@
#!/bin/bash
adduser -u $uid $user
mkdir -p /home/$user/public_html
chown -R $user:$user /home/$user
chmod -R 755 /home/$user
/scripts/create-vhost.sh
/scripts/create-php-config.sh
/usr/sbin/httpd -k start
/usr/sbin/php-fpm -y /etc/php-fpm.conf
if [ $environment == 'DEV' ]; then
echo "Starting Dev Deployment"
yum install -y MariaDB-server MariaDB-client
nohup mysqld -umysql &
if [ ! -f /var/lib/mysql/creds ]; then
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;"
echo "MySQL User: "$mysql_user > /var/lib/mysql/creds
echo "MySQL Password: "$mysql_password >> /var/lib/mysql/creds
echo "MySQL Database: devdb_"$mysql_db >> /var/lib/mysql/creds
cat /var/lib/mysql/creds
fi
/usr/bin/memcached -d -u $user
fi
tail -f /etc/httpd/logs/*
exit 0

9
scripts/install-php74.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
dnf module enable php:remi-7.4 -y
dnf install -y php php-fpm php-mysqlnd php-xml php-pecl-zip php-sodium php-soap php-xmlrpc \
php-pecl-redis5 php-pecl-memcached php-pecl-memcache php-pecl-ip2location php-pecl-imagick php-pecl-geoip \
php-mysqlnd php-mbstring php-ioncube-loader php-intl php-gd libzip php-cli
sed -i 's/^php_value\[session\.save_handler\] = files$/;php_value[session.save_handler] = files/' /etc/php-fpm.d/www.conf
sed -i 's/^php_value\[session\.save_path\] *= *\/*var\/lib\/php\/session$/;php_value[session.save_path] = \/var\/lib\/php\/session/' /etc/php-fpm.d/www.conf
exit 0

9
scripts/install-php80.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
dnf module enable php:remi-8.0 -y
dnf install -y php php-fpm php-mysqlnd php-xml php-pecl-zip php-sodium php-soap php-pecl-xmlrpc \
php-pecl-redis5 php-pecl-memcached php-pecl-memcache php-pecl-ip2location php-pecl-imagick php-pecl-geoip \
php-mysqlnd php-mbstring php-ioncube-loader php-intl php-gd libzip php-cli
sed -i 's/^php_value\[session\.save_handler\] = files$/;php_value[session.save_handler] = files/' /etc/php-fpm.d/www.conf
sed -i 's/^php_value\[session\.save_path\] *= *\/*var\/lib\/php\/session$/;php_value[session.save_path] = \/var\/lib\/php\/session/' /etc/php-fpm.d/www.conf
exit 0

9
scripts/install-php81.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
dnf module enable php:remi-8.1 -y
dnf install -y php php-fpm php-mysqlnd php-xml php-pecl-zip php-sodium php-soap php-pecl-xmlrpc \
php-pecl-redis5 php-pecl-memcached php-pecl-memcache php-pecl-ip2location php-pecl-imagick php-pecl-geoip \
php-mysqlnd php-mbstring php-ioncube-loader php-intl php-gd libzip php-cli
sed -i 's/^php_value\[session\.save_handler\] = files$/;php_value[session.save_handler] = files/' /etc/php-fpm.d/www.conf
sed -i 's/^php_value\[session\.save_path\] *= *\/*var\/lib\/php\/session$/;php_value[session.save_path] = \/var\/lib\/php\/session/' /etc/php-fpm.d/www.conf
exit 0

9
scripts/install-php82.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
dnf module enable php:remi-8.2 -y
dnf install -y php php-fpm php-mysqlnd php-xml php-pecl-zip php-sodium php-soap php-pecl-xmlrpc \
php-pecl-redis5 php-pecl-memcached php-pecl-memcache php-pecl-ip2location php-pecl-imagick php-pecl-geoip \
php-mysqlnd php-mbstring php-intl php-gd libzip php-cli
sed -i 's/^php_value\[session\.save_handler\] = files$/;php_value[session.save_handler] = files/' /etc/php-fpm.d/www.conf
sed -i 's/^php_value\[session\.save_path\] *= *\/*var\/lib\/php\/session$/;php_value[session.save_path] = \/var\/lib\/php\/session/' /etc/php-fpm.d/www.conf
exit 0