From 63107790b30bf4a692f1f1f14ce8f4e5fcc5be63 Mon Sep 17 00:00:00 2001 From: Daniel Dolezal Date: Sun, 4 Dec 2022 03:42:24 +0100 Subject: [PATCH] add nginx with phpMyAdmin --- Dockerfile | 32 +++- build.sh | 2 + myteleport.cnf => configs/myteleport.cnf | 0 configs/nginx.conf | 30 ++++ configs/phpmyadmin.config.php | 160 ++++++++++++++++++ .../docker-entrypoint.sh | 16 +- 6 files changed, 233 insertions(+), 7 deletions(-) rename myteleport.cnf => configs/myteleport.cnf (100%) create mode 100644 configs/nginx.conf create mode 100644 configs/phpmyadmin.config.php rename docker-entrypoint.sh => scripts/docker-entrypoint.sh (97%) diff --git a/Dockerfile b/Dockerfile index 95b7321..0e95328 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,44 @@ FROM mariadb:latest +ARG phpmyadmin_version="5.2.0" +ARG ubuntu_codename="jammy" + ENV TZ=Europe/Vienna RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -COPY docker-entrypoint.sh /usr/local/bin/ -COPY myteleport.cnf /etc/mysql/mariadb.conf.d/z-custom-for-teleport.cnf +COPY scripts/docker-entrypoint.sh /usr/local/bin/ +COPY configs/myteleport.cnf /etc/mysql/mariadb.conf.d/z-custom-for-teleport.cnf RUN apt-get update && apt-get install -y curl RUN curl https://apt.releases.teleport.dev/gpg \ -o /usr/share/keyrings/teleport-archive-keyring.asc - -RUN export VERSION_CODENAME=jammy && echo "deb [signed-by=/usr/share/keyrings/teleport-archive-keyring.asc] \ +RUN export VERSION_CODENAME=$ubuntu_codename && echo "deb [signed-by=/usr/share/keyrings/teleport-archive-keyring.asc] \ https://apt.releases.teleport.dev/ubuntu ${VERSION_CODENAME?} stable/v11" \ | tee /etc/apt/sources.list.d/teleport.list > /dev/null -RUN apt-get update && apt-get install -y teleport +RUN apt-get update && apt-get install -y teleport nginx wget unzip +RUN apt-get install -y php-imagick php-phpseclib php-php-gettext php8.1-common php8.1-mysql php8.1-gd php8.1-imap php8.1-curl php8.1-zip php8.1-xml php8.1-mbstring php8.1-bz2 php8.1-intl php8.1-gmp php8.1-fpm + +# Nginx Config +COPY configs/nginx.conf /etc/nginx/sites-available/default + +# Install phpmyadmin +RUN wget https://files.phpmyadmin.net/phpMyAdmin/$phpmyadmin_version/phpMyAdmin-$phpmyadmin_version-all-languages.zip +RUN unzip phpMyAdmin-$phpmyadmin_version-all-languages.zip + +RUN mkdir -p /var/www/phpmyadmin +RUN mv phpMyAdmin-$phpmyadmin_version-all-languages/* /var/www/phpmyadmin +RUN rm -rf phpMyAdmin-$phpmyadmin_version-all-languages.zip + +COPY --chown=www-data:www-data configs/phpmyadmin.config.php /var/www/phpmyadmin/config.inc.php +RUN chown -R www-data:www-data /var/www/phpmyadmin +RUN chmod 777 /var/www/phpmyadmin + +RUN rm -rf /phpMyAdmin-$phpmyadmin_version-all-languages VOLUME /var/lib/mysql ENTRYPOINT ["docker-entrypoint.sh"] -EXPOSE 3306 +EXPOSE 80 3306 CMD ["mariadbd"] diff --git a/build.sh b/build.sh index 627f6f7..d9d3213 100755 --- a/build.sh +++ b/build.sh @@ -14,8 +14,10 @@ run_docker_container() { echo "Running..." docker run -d \ -p 3306:3306 \ + -p 8080:80 \ -e TZ="Europe/Vienna" \ -e MARIADB_ALLOW_EMPTY_ROOT_PASSWORD="true" \ + -e RUN_WEBSERVER="yes" \ "$DOCKER_IMAGE_NAME":"$GIT_BRANCH" } diff --git a/myteleport.cnf b/configs/myteleport.cnf similarity index 100% rename from myteleport.cnf rename to configs/myteleport.cnf diff --git a/configs/nginx.conf b/configs/nginx.conf new file mode 100644 index 0000000..a195e8b --- /dev/null +++ b/configs/nginx.conf @@ -0,0 +1,30 @@ +server { + listen 80; + listen [::]:80; + root /var/www/phpmyadmin/; + index index.php index.html index.htm index.nginx-debian.html; + + server_name _; + + access_log /var/log/nginx/phpmyadmin_access.log; + error_log /var/log/nginx/phpmyadmin_error.log; + + location / { + try_files $uri $uri/ /index.php; + } + + location ~ ^/(doc|sql|setup)/ { + deny all; + } + + location ~ \.php$ { + fastcgi_pass unix:/run/php/php8.1-fpm.sock; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + include snippets/fastcgi-php.conf; + } + + location ~ /\.ht { + deny all; + } +} \ No newline at end of file diff --git a/configs/phpmyadmin.config.php b/configs/phpmyadmin.config.php new file mode 100644 index 0000000..21be5b6 --- /dev/null +++ b/configs/phpmyadmin.config.php @@ -0,0 +1,160 @@ +. + */ + +declare(strict_types=1); + +/** + * Servers configuration + */ +$i = 0; + +/** + * First server + */ +$i++; +/* Authentication type */ +$cfg['Servers'][$i]['auth_type'] = 'cookie'; +/* Server parameters */ +$cfg['Servers'][$i]['host'] = 'localhost'; +$cfg['Servers'][$i]['compress'] = true; +$cfg['Servers'][$i]['AllowNoPassword'] = true; + +/** + * phpMyAdmin configuration storage settings. + */ + +/* User used to manipulate with storage */ +// $cfg['Servers'][$i]['controlhost'] = ''; +// $cfg['Servers'][$i]['controlport'] = ''; +// $cfg['Servers'][$i]['controluser'] = 'pma'; +// $cfg['Servers'][$i]['controlpass'] = 'pmapass'; + +/* Storage database and tables */ +// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; +// $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark'; +// $cfg['Servers'][$i]['relation'] = 'pma__relation'; +// $cfg['Servers'][$i]['table_info'] = 'pma__table_info'; +// $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords'; +// $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages'; +// $cfg['Servers'][$i]['column_info'] = 'pma__column_info'; +// $cfg['Servers'][$i]['history'] = 'pma__history'; +// $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs'; +// $cfg['Servers'][$i]['tracking'] = 'pma__tracking'; +// $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; +// $cfg['Servers'][$i]['recent'] = 'pma__recent'; +// $cfg['Servers'][$i]['favorite'] = 'pma__favorite'; +// $cfg['Servers'][$i]['users'] = 'pma__users'; +// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups'; +// $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding'; +// $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches'; +// $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns'; +// $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings'; +// $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates'; + +/** + * End of servers configuration + */ + +/** + * Directories for saving/loading files from server + */ +$cfg['UploadDir'] = ''; +$cfg['SaveDir'] = ''; + +/** + * Whether to display icons or text or both icons and text in table row + * action segment. Value can be either of 'icons', 'text' or 'both'. + * default = 'both' + */ +//$cfg['RowActionType'] = 'icons'; + +/** + * Defines whether a user should be displayed a "show all (records)" + * button in browse mode or not. + * default = false + */ +//$cfg['ShowAll'] = true; + +/** + * Number of rows displayed when browsing a result set. If the result + * set contains more rows, "Previous" and "Next". + * Possible values: 25, 50, 100, 250, 500 + * default = 25 + */ +//$cfg['MaxRows'] = 50; + +/** + * Disallow editing of binary fields + * valid values are: + * false allow editing + * 'blob' allow editing except for BLOB fields + * 'noblob' disallow editing except for BLOB fields + * 'all' disallow editing + * default = 'blob' + */ +//$cfg['ProtectBinary'] = false; + +/** + * Default language to use, if not browser-defined or user-defined + * (you find all languages in the locale folder) + * uncomment the desired line: + * default = 'en' + */ +//$cfg['DefaultLang'] = 'en'; +//$cfg['DefaultLang'] = 'de'; + +/** + * How many columns should be used for table display of a database? + * (a value larger than 1 results in some information being hidden) + * default = 1 + */ +//$cfg['PropertiesNumColumns'] = 2; + +/** + * Set to true if you want DB-based query history.If false, this utilizes + * JS-routines to display query history (lost by window close) + * + * This requires configuration storage enabled, see above. + * default = false + */ +//$cfg['QueryHistoryDB'] = true; + +/** + * When using DB-based query history, how many entries should be kept? + * default = 25 + */ +//$cfg['QueryHistoryMax'] = 100; + +/** + * Whether or not to query the user before sending the error report to + * the phpMyAdmin team when a JavaScript error occurs + * + * Available options + * ('ask' | 'always' | 'never') + * default = 'ask' + */ +//$cfg['SendErrorReports'] = 'always'; + +/** + * 'URLQueryEncryption' defines whether phpMyAdmin will encrypt sensitive data from the URL query string. + * 'URLQueryEncryptionSecretKey' is a 32 bytes long secret key used to encrypt/decrypt the URL query string. + */ +//$cfg['URLQueryEncryption'] = true; +//$cfg['URLQueryEncryptionSecretKey'] = ''; + +/** + * You can find more configuration options in the documentation + * in the doc/ folder or at . + */ +$cfg['ShowStats'] = true; + +/** + * This is needed for cookie based authentication to encrypt password in + * cookie. Needs to be 32 chars long. + */ diff --git a/docker-entrypoint.sh b/scripts/docker-entrypoint.sh similarity index 97% rename from docker-entrypoint.sh rename to scripts/docker-entrypoint.sh index fdca99b..abe1ae2 100755 --- a/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -544,8 +544,22 @@ _check_to_run_teleport() { fi } +_run_web_server() { + if [ ! -z "$RUN_WEBSERVER" ]; then + if [ ! -f "/var/www/phpmyadmin/.installed" ]; then + export SECRET=`php -r 'echo base64_encode(random_bytes(24));'` + echo "\$cfg['blowfish_secret'] = '$SECRET';" >> /var/www/phpmyadmin/config.inc.php + chown www-data:www-data /var/www/phpmyadmin/config.inc.php + touch "/var/www/phpmyadmin/.installed" + fi + php-fpm8.1 & + nginx & + fi +} + # If we are sourced from elsewhere, don't perform any further actions if ! _is_sourced; then _check_to_run_teleport + _run_web_server _main "$@" -fi \ No newline at end of file +fi