diff --git a/Dockerfile b/Dockerfile index 7d1b4a9..5523fb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,16 @@ -FROM almalinux/8-base:latest +FROM almalinux/9-base 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 install -y memcached httpd mod_ssl wget procps +#RUN dnf update -y && dnf upgrade -y +RUN dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -y +RUN dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm +#RUN dnf update -y && dnf upgrade -y +RUN dnf install -y httpd mod_ssl wget procps 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 /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 @@ -20,4 +20,4 @@ COPY ./configs/phpinfo.php /var/www/html/ COPY ./configs/mariadb.repo /etc/yum.repos.d/ COPY ./configs/index.php /var/www/html/ RUN yum clean all -ENTRYPOINT [ "/scripts/entrypoint.sh" ] \ No newline at end of file +ENTRYPOINT [ "/scripts/entrypoint.sh" ] diff --git a/README.md b/README.md index 1d78364..df62b94 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,29 @@ # Cloud Apache Container # -This is the base container for running PHP based applications. Select the PHP version with the tags +This is the base container for running PHP based applications. Select the PHP version environment variables. PHP Version Defaults to PHP 8.1 *__You mush have docker or compatable containerization software running.__* __You can pull this image locally by running:__ ```console -docker pull registry.dnspegasus.net/cac:81 +docker pull public.ecr.aws/s1f6k4w4/cac:latest ``` -__You can then run a development version of the server by running the following commands:__ +__You can then run a development version of the server by running the following commands:__ +*Note this is an example, you can modify the command(s) to fit your needs.* ```console mkdir -p local-development/domain.tld cd local-development/domain.tld -mkdir web -mkdir db -docker run -it --rm -p 80:80 -p 443:443 -e environment=DEV --mount type=bind,source="$(pwd)"/web,target=/home/myuser/public_html --mount type=bind,source="$(pwd)"/db,target=/var/lib/mysql -e uid=30001 -e user=myuser -e domain=domain.tld -e serveralias=www.domain.tld --name local-dev cac:81 +mkdir {web,db} +docker run -it -p 80:80 -p 443:443 -e PHPVER=81 -e environment=DEV --mount type=bind,source="$(pwd)"/web,target=/home/myuser/public_html --mount type=bind,source="$(pwd)"/db,target=/var/lib/mysql -e uid=30001 -e user=myuser -e domain=domain.tld -e serveralias=www.domain.tld --name local-dev cac:latest ``` *This will start the processes needed to run sites locally.* -__If you need to get into the container you can run from another terminal:__ +The first time you start the container, it will take some time as it is installing all the required software to run the dev instance. + +__If you need to get into the container you can run:__ ```console docker exec -it local-dev /bin/bash @@ -40,7 +42,7 @@ You should be able to then go into your browser and go to https://localhost (ac The database credentials are shown in the /var/lib/mysql/creds file, which we had *cat* in the commands above. -### Tags ### +### PHPVER ### *74* - PHP 7.4 *80* - PHP 8.0 *81* - PHP 8.1 @@ -54,4 +56,16 @@ __Required Tags__ __Optional Tags__ *environment* - Set to DEV to start memcached and mysql locally for development purposes -*serveralias* - Set to allow alternative hostnames for a site. \ No newline at end of file +*serveralias* - Set to allow alternative hostnames for a site. +*PHPVER* - Set to use a different version of PHP [refer to versions here.](#phpver) + +### Helpful Notes ### + +* On your first creation of a dev instance, you will be dumped to the logs output. Hit ```ctrl + c``` to exit the running process. +* If you want to restart the instance again, run ```docker start {name-of-your-container}``` in the example, *name-of-your-cintainer* is *local-dev* +* To stop a restarted instance, run ```docker stop {name-of-your-container}``` +* To view log stream from container, run ```docker logs -f {name-of-your-container}``` +* To delete a container, run ```docker rm {name-of-your-container}``` *__Note:__ this does not delete the files in public_html or database, as those are store in your system* +* To view running containers, run ```docker ps``` +* To view all created containers, run ```docker ps --all`` +* To view all container images downloaded on your system, run ```docker images``` \ No newline at end of file diff --git a/scripts/create-php-config.sh b/scripts/create-php-config.sh index cbd8621..60a7490 100644 --- a/scripts/create-php-config.sh +++ b/scripts/create-php-config.sh @@ -13,8 +13,8 @@ listen.owner = apache listen.group = apache pm = static -pm.max_children = 25 -pm.max_requests = 1000 +pm.max_children = 10 +pm.max_requests = 150 slowlog = /etc/httpd/logs/error_log request_slowlog_timeout = 3s diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index 49409c0..5c21d8e 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -1,5 +1,9 @@ #!/bin/bash +if [ -z "$PHPVER" ]; then + PHPVER="81"; +fi + adduser -u $uid $user mkdir -p /home/$user/public_html @@ -7,6 +11,8 @@ mkdir -p /home/$user/public_html chown -R $user:$user /home/$user chmod -R 755 /home/$user +/scripts/install-php$PHPVER.sh + /scripts/create-vhost.sh /scripts/create-php-config.sh @@ -15,7 +21,7 @@ chmod -R 755 /home/$user if [[ $environment == 'DEV' ]]; then echo "Starting Dev Deployment" - yum install -y MariaDB-server MariaDB-client + dnf install -y MariaDB-server MariaDB-client memcached nohup mysqld -umysql & if [ ! -f /var/lib/mysql/creds ]; then echo "Give MySQL a chance to finish starting..."