Ubuntu:18.04 + php7.2 + mysql5.7 + phpinfo();
此需求源自於舊網站的開發環境的建置,一般人不會碰到。
同事回報之前弄的 Docker 環境,因為從 Macbook Intel x86 架構,換到 Mac M2 ARM 環境後,出現問題。主因是網站使用很舊的 MySQL 5.6 環境,在 macos arm64 的 Docker 環境中,無法很便利的只用官方環境建置出來,預設只能直接升級到 MySQL 8 跑,接著還要面對 MySQL 5.6 跟 MySQL 5.7 以上的 SQL 語法變化。
在此的解法是放棄 MySQL 5.6 ,頂多弄出 MySQL 5.7 環境,並追蹤有哪些 SQL 語法需要修改,SQL語法方面,主要是面對 ONLY_FULL_GROUP_BY 模式的處理。此紀錄透過 Docker 弄個 MySQL 5.7 環境出來過度,且最終只需用 ubuntu:18.04 即可搞定大部分,以下是流水帳:
原先要用 Docker - Ubuntu 24.04 arm64 環境來使用,但追蹤後發現 Ubuntu 20.04, Ubuntu 22.04, Ubuntu 24.04 預設都只提供 MySQL 8 的環境,並且依照 MySQL APT Repository 的方式安裝 mysql-apt-config_0.8.30-1_all.deb 後,確認都沒 mysql-5.7 可選,而坊間其他教學文,主要是透過舊版 mysql-apt-config_0.8.12-1_all.deb 套件,在 Ubuntu 20.04 安裝了 mysql-5.7 ,但其過程是 mysql-apt-config 套件無法偵測出 Ubuntu 環境,透過人工選擇 Ubuntu 18.04 的環境裝到 mysql-5.7 而已,以下是個例子:
% docker run -it ubuntu:24.04 /bin/bashroot@2560222cf1ee:/# apt update && apt install -y wget lsb-release gnupg dialogroot@2560222cf1ee:/# wget https://dev.mysql.com/get/mysql-apt-config_0.8.30-1_all.debroot@2560222cf1ee:/# dpkg -i ./mysql-apt-config_0.8.30-1_all.debMySQL APT Repo features MySQL Server along with a variety of MySQL components. You may select the appropriate product to choose the version that youwish to receive.Once you are satisfied with the configuration then select last option 'Ok' to save the configuration, then run 'apt-get update' to load package list.Advanced users can always change the configurations later, depending on their own needs.1. MySQL Server & Cluster (Currently selected: mysql-8.4-lts) 3. MySQL Preview Packages (Currently selected: Disabled)2. MySQL Tools & Connectors (Currently selected: Enabled) 4. OkWhich MySQL product do you wish to configure?Which server version do you wish to receive?
來試試看裝舊版 mysql-apt-config_0.8.12-1_all.deb:
root@2560222cf1ee:/# dpkg -i ./mysql-apt-config_0.8.12-1_all.debroot@bc33821f13de:/# apt updateW: GPG error: http://repo.mysql.com/apt/ubuntu cosmic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B7B3B788A8D3785CE: The repository 'http://repo.mysql.com/apt/ubuntu cosmic InRelease' is not signed.N: Updating from such a repository can't be done securely, and is therefore disabled by default.N: See apt-secure(8) manpage for repository creation and user configuration details.root@bc33821f13de:/# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785CWarning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).Executing: /tmp/apt-key-gpghome.eheHF2erjp/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785Cgpg: key B7B3B788A8D3785C: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" importedgpg: Total number processed: 1gpg: imported: 1root@bc33821f13de:/# apt updateW: http://repo.mysql.com/apt/ubuntu/dists/cosmic/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.N: Skipping acquire of configured file 'mysql-tools/binary-arm64/Packages' as repository 'http://repo.mysql.com/apt/ubuntu cosmic InRelease' doesn't support architecture 'arm64'N: Skipping acquire of configured file 'mysql-5.7/binary-arm64/Packages' as repository 'http://repo.mysql.com/apt/ubuntu cosmic InRelease' doesn't support architecture 'arm64'N: Skipping acquire of configured file 'mysql-apt-config/binary-arm64/Packages' as repository 'http://repo.mysql.com/apt/ubuntu cosmic InRelease' doesn't support architecture 'arm64'
最後就輕鬆改用 ubuntu:18.04 ,再把 phpmyadmin 擺好即可,收工。
連續動作:
# Use the official Ubuntu 18.04 as the base imageFROM ubuntu:18.04# Set non-interactive mode for APTENV DEBIAN_FRONTEND=noninteractiveENV TZ=Asia/TaipeiENV PHP_VERSION=7.2# Update the package list and install necessary packagesRUN apt-get update && \apt-get install -y tzdata && \ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && dpkg-reconfigure --frontend noninteractive tzdata && \apt-get install -y \htop \jq \vim \curl \wget \telnet \php7.2-cli \php7.2-curl \php7.2-fpm \php7.2-ldap \php7.2-mysql \php7.2-zip \phpunit \mysql-server-5.7 \ssl-cert \nginx \openssh-server && \apt-get clean && \rm -rf /var/lib/apt/lists/*EXPOSE 22 80 443 8080 8443 3306# Set up MySQLRUN service mysql start && \mysql -e "CREATE USER 'developer'@'%' IDENTIFIED BY 'developer'; GRANT ALL PRIVILEGES ON *.* TO 'developer'@'%'; CREATE DATABASE developer; FLUSH PRIVILEGES;"# Set up PHP-FPM Short Open TagRUN test -f /etc/php/$PHP_VERSION/fpm/php.ini && \sed -i 's/short_open_tag = Off/short_open_tag = On/' /etc/php/$PHP_VERSION/fpm/php.ini && \sed -i 's/max_execution_time = 30/max_execution_time = 300/' /etc/php/$PHP_VERSION/fpm/php.ini && \sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 100M/' /etc/php/$PHP_VERSION/fpm/php.ini && \sed -i 's/post_max_size = 8M/post_max_size = 100M/' /etc/php/$PHP_VERSION/fpm/php.ini# Set up phpmyadminRUN cd /tmp && \wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz && \tar xvzf phpMyAdmin-latest-all-languages.tar.gz && \mv phpMyAdmin-*-all-languages /usr/share/phpmyadmin && \mkdir -p /usr/share/phpmyadmin/tmp && \chown -R www-data:www-data /usr/share/phpmyadmin && \chmod 777 /usr/share/phpmyadmin/tmp# Copy the entrypoint scriptCOPY nginx-php7.2-fpm-phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadminCOPY nginx-php7.2-fpm-website.conf /etc/nginx/sites-enabled/defaultCOPY entrypoint.sh /usr/local/bin/RUN chmod +x /usr/local/bin/entrypoint.sh# Set the entrypointENTRYPOINT ["/usr/local/bin/entrypoint.sh"]# Start services in the foregroundCMD ["bash"]# Define a volume for mounting the local directoryVOLUME ["/var/www/my-website"]
運行:
% lsDockerfile nginx-php7.2-fpm-phpmyadmin.confREADME.md nginx-php7.2-fpm-website.confentrypoint.sh% docker build -t test .% mkdir /tmp/php% echo "<?php phpinfo();" > /tmp/php/index.php% cat /tmp/php/index.php<?php phpinfo();% docker run -p 80:80 -p 443:443 -p 8080:8080 -p 8443:8443 -v /tmp/php:/var/www/my-website -t test* Starting MySQL database server mysqld No directory, logging in with HOME=/[ OK ]* Starting OpenBSD Secure Shell server sshd [ OK ]* Starting nginx nginx [ OK ]Fri May 24 21:42:43 CST 2024
如此,就可以用 http://localhost, https://localhost/ 看到 phpinfo() 的資料,而用 http://localhost:8080, https://localhost:8443/ 則會看到 phpmyadmin 網頁服務
要關閉時,記得找一下 container id:
% docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESa1631b90d924 test "/usr/local/bin/entr…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, 22/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:8080->8080/tcp, 3306/tcp, 0.0.0.0:8443->8443/tcp thirsty_booth% docker stop a1631b90d924a1631b90d924
其他資訊:changyy/docker-study/ubuntu18.04-php7.2-mysql5.7-phpmyadmin
沒有留言:
張貼留言