From ce0f70d64857700e3b5a3dbadf2b9f73f5f4e1bc Mon Sep 17 00:00:00 2001 From: kj Date: Wed, 27 Nov 2024 15:28:36 -0400 Subject: [PATCH] Migrate to a docker-compose config with a few persistence. ./data/nginx/ for nginx host configurations. ./data/mysql/ for mysql databases. --- Dockerfile | 15 ++--------- bin/mysql_configure | 30 ++++++++++++++++++++++ build.sh | 2 -- data/nginx/sites-available/default | 40 ++++++++++++++++++++++++++++++ data/nginx/sites-enabled/default | 1 + docker-compose.yml | 14 +++++++++++ install.sh | 3 +++ uninstall.sh | 2 ++ 8 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 bin/mysql_configure delete mode 100644 build.sh create mode 100644 data/nginx/sites-available/default create mode 120000 data/nginx/sites-enabled/default create mode 100644 docker-compose.yml create mode 100755 install.sh create mode 100755 uninstall.sh diff --git a/Dockerfile b/Dockerfile index 87994c2..630f62d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,19 +6,6 @@ RUN apt-get update && \ apt-get install -y systemd systemd-sysv cron anacron nano wget curl git mariadb-server mariadb-client nginx php-fpm php-common php-gd php-mysql php-imap php-cli php-cgi libapache2-mod-fcgid apache2-suexec-pristine php-pear mcrypt imagemagick libruby libapache2-mod-python php-curl php-intl php-pspell php-sqlite3 php-tidy php-xmlrpc php-xsl memcached php-memcache php-imagick php-zip php-mbstring memcached libapache2-mod-passenger php-soap php-opcache php-apcu libapache2-reload-perl php-mcrypt && \ apt-get clean -# Instalamos phpmyadmin y definimos la contraseña de root de mariadb en blanco para @localhost. -RUN service mariadb start && \ - export DEBIAN_FRONTEND=noninteractive && \ - apt-get -yq install phpmyadmin && \ - mysql -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD(''); FLUSH PRIVILEGES;" && \ - service mariadb stop - -# Permitimos el que se pueda loguear sin contraseña para usar el usuario root de ese modo -RUN sed -i "s/ \/\/ \$cfg\['Servers'\]\[\$i\]\['AllowNoPassword'\]/ \$cfg\['Servers'\]\[\$i\]\['AllowNoPassword'\]/" /etc/phpmyadmin/config.inc.php - -# Añadimos las reglas nginx para poder ver phpmyadmin en http://localhost/phpmyadmin -RUN sed -i "s/server_name _;/server_name _;\n\nlocation \/phpmyadmin {\n root \/usr\/share\/;\n index index.php index.html index.htm;\n location ~ \^\/phpmyadmin\/\(.+\.php\)\$ {\n try_files \$uri =404;\n root \/usr\/share\/;\n fastcgi_pass unix:\/var\/run\/php\/php8.2-fpm.sock;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME \$request_filename;\n include \/etc\/nginx\/fastcgi_params;\n fastcgi_param PATH_INFO \$fastcgi_script_name;\n fastcgi_buffer_size 128k;\n fastcgi_buffers 256 4k;\n fastcgi_busy_buffers_size 256k;\n fastcgi_temp_file_write_size 256k;\n fastcgi_intercept_errors on;\n }\n location ~* \^\/phpmyadmin\/\(.+\\.\(jpg\|jpeg\|gif\|css\|png\|js\|ico\|html\|xml\|txt\)\)\$ {\n root \/usr\/share\/;\n }\n}\nlocation \/phpMyAdmin {\n rewrite \^\/* \/phpmyadmin last;\n}/g" /etc/nginx/sites-available/default - # Mostrar los errores en PHP RUN sed -i 's/display_errors = Off/display_errors = On/' /etc/php/8.2/fpm/php.ini && \ sed -i 's/error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT/error_reporting = E_ALL/' /etc/php/8.2/fpm/php.ini @@ -48,6 +35,8 @@ COPY bin/adddomain /usr/local/bin/adddomain RUN chmod +x /usr/local/bin/adddomain COPY bin/addsubdomain /usr/local/bin/addsubdomain RUN chmod +x /usr/local/bin/addsubdomain +COPY bin/mysql_configure /usr/local/bin/mysql_configure +RUN chmod +x /usr/local/bin/mysql_configure # Colocamos dentro el certificado SSL COPY ssl /etc/nginx/ssl diff --git a/bin/mysql_configure b/bin/mysql_configure new file mode 100644 index 0000000..e200668 --- /dev/null +++ b/bin/mysql_configure @@ -0,0 +1,30 @@ +#!/bin/bash + +# Verificamos si ya está todo configurado +if test -f /etc/phpmyadmin/config.inc.php; then + echo "Parece que ya está todo configurado (se hace nada)." + exit +fi + +# Definiendo una contraseña vacía para root +echo "Definiendo contraseña para root (contraseña en blanco)." +systemctl start mariadb +export DEBIAN_FRONTEND=noninteractive +apt-get update +apt-get -yq install phpmyadmin +mysql -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD(''); FLUSH PRIVILEGES;" + +# Permitimos el que se pueda loguear sin contraseña para usar el usuario root en phpmyadmin +sed -i "s/ \/\/ \$cfg\['Servers'\]\[\$i\]\['AllowNoPassword'\]/ \$cfg\['Servers'\]\[\$i\]\['AllowNoPassword'\]/" /etc/phpmyadmin/config.inc.php + +# Añadimos las reglas nginx para poder ver phpmyadmin en http://localhost/phpmyadmin +if grep -e "phpmyadmin" /etc/nginx/sites-available/default >/dev/null +then + echo "Se detectó que nginx ya tiene una configuración para PHPmyadmin (se hace nada)" +else + echo "Configurando Nginx..." + sed -i "s/server_name _;/server_name _;\n\nlocation \/phpmyadmin {\n root \/usr\/share\/;\n index index.php index.html index.htm;\n location ~ \^\/phpmyadmin\/\(.+\.php\)\$ {\n try_files \$uri =404;\n root \/usr\/share\/;\n fastcgi_pass unix:\/var\/run\/php\/php8.2-fpm.sock;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME \$request_filename;\n include \/etc\/nginx\/fastcgi_params;\n fastcgi_param PATH_INFO \$fastcgi_script_name;\n fastcgi_buffer_size 128k;\n fastcgi_buffers 256 4k;\n fastcgi_busy_buffers_size 256k;\n fastcgi_temp_file_write_size 256k;\n fastcgi_intercept_errors on;\n }\n location ~* \^\/phpmyadmin\/\(.+\\.\(jpg\|jpeg\|gif\|css\|png\|js\|ico\|html\|xml\|txt\)\)\$ {\n root \/usr\/share\/;\n }\n}\nlocation \/phpMyAdmin {\n rewrite \^\/* \/phpmyadmin last;\n}/g" /etc/nginx/sites-available/default +fi + + +echo "Finalizado :)." diff --git a/build.sh b/build.sh deleted file mode 100644 index f97033e..0000000 --- a/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -podman image build -t localhost/nginx-dev:latest . diff --git a/data/nginx/sites-available/default b/data/nginx/sites-available/default new file mode 100644 index 0000000..002ab55 --- /dev/null +++ b/data/nginx/sites-available/default @@ -0,0 +1,40 @@ +server { + listen 80 default_server; + listen [::]:80 default_server; + + root /var/www/html; + + index index.html index.htm index.nginx-debian.html; + + server_name _; + + location /phpmyadmin { + root /usr/share/; + index index.php index.html index.htm; + location ~ ^/phpmyadmin/(.+.php)$ { + try_files $uri =404; + root /usr/share/; + fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $request_filename; + include /etc/nginx/fastcgi_params; + fastcgi_param PATH_INFO $fastcgi_script_name; + fastcgi_buffer_size 128k; + fastcgi_buffers 256 4k; + fastcgi_busy_buffers_size 256k; + fastcgi_temp_file_write_size 256k; + fastcgi_intercept_errors on; + } + location ~* ^/phpmyadmin/(.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { + root /usr/share/; + } + } + + location /phpMyAdmin { + rewrite ^/* /phpmyadmin last; + } + + location / { + try_files $uri $uri/ =404; + } +} diff --git a/data/nginx/sites-enabled/default b/data/nginx/sites-enabled/default new file mode 120000 index 0000000..ad35b83 --- /dev/null +++ b/data/nginx/sites-enabled/default @@ -0,0 +1 @@ +/etc/nginx/sites-available/default \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..05a6069 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3' + +services: + nginx: + image: nginx-dev + network_mode: host + build: . + container_name: nginx + hostname: nginx + volumes: + - ~/.mnt/Nginx:/var/www:Z + - ./data/nginx/sites-available:/etc/nginx/sites-available:Z + - ./data/nginx/sites-enabled:/etc/nginx/sites-enabled:Z + - ./data/mysql/data:/var/lib/mysql/data:Z diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..908ed4b --- /dev/null +++ b/install.sh @@ -0,0 +1,3 @@ +#!/bin/bash +podman-compose up -d +podman exec -it nginx /usr/local/bin/mysql_configure diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..3639e4d --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,2 @@ +#!/bin/bash +podman-compose down