Docker dnmp 多版本php安装 php8.2
Laravel9 开发需要用到php8.1以上的版本,而dnmp只支持到php8.0。安装php8.2的步骤如下:
1. 从/services/php80目录复制一份出来,重命名为php82,extensions目录只保留 install.sh 和 install-php-extensions 这两个文件
2. 修改.env文件,添加php82的配置参数:
# # PHP82 # # Available PHP_EXTENSIONS: # # pdo_mysql,zip,pcntl,mysqli,mbstring,exif,bcmath,calendar, # sockets,gettext,shmop,sysvmsg,sysvsem,sysvshm,pdo_rebird, # pdo_dblib,pdo_oci,pdo_odbc,pdo_pgsql,pgsql,oci8,odbc,dba, # gd,intl,bz2,soap,xsl,xmlrpc,wddx,curl,readline,snmp,pspell, # recode,tidy,gmp,imap,ldap,imagick,sqlsrv,mcrypt,opcache, # redis,memcached,xdebug,swoole,pdo_sqlsrv,sodium,yaf,mysql, # amqp,mongodb,event,rar,ast,yac,yar,yaconf,msgpack,igbinary, # seaslog,varnish,xhprof,xlswriter,memcache,rdkafka,zookeeper, # psr,phalcon,sdebug,ssh2,yaml,protobuf,hprose # # You can let it empty to avoid installing any extensions, # or install multi plugins as: # PHP_EXTENSIONS=pdo_mysql,mysqli,gd,curl,opcache # PHP82_VERSION=8.2.6 PHP82_PHP_CONF_FILE=./services/php82/php.ini PHP82_FPM_CONF_FILE=./services/php82/php-fpm.conf PHP82_LOG_DIR=./logs/php82 # 扩展,根据实际情况增减 PHP82_EXTENSIONS=pdo_mysql,mysqli,mbstring,gd,curl,opcache,redis,mongodb,bcmath,soap
3. docker-compose.yml 文件 新增 php82 配置参数
php82: build: context: ./services/php82 args: PHP_VERSION: php:${PHP82_VERSION}-fpm-alpine CONTAINER_PACKAGE_URL: ${CONTAINER_PACKAGE_URL} PHP_EXTENSIONS: ${PHP82_EXTENSIONS} TZ: "$TZ" container_name: php82 expose: - 9501 volumes: - ${SOURCE_DIR}:/www/:rw - ${PHP82_PHP_CONF_FILE}:/usr/local/etc/php/php.ini:ro - ${PHP82_FPM_CONF_FILE}:/usr/local/etc/php-fpm.d/www.conf:rw - ${PHP82_LOG_DIR}:/var/log/php - ${DATA_DIR}/composer:/tmp/composer restart: always cap_add: - SYS_PTRACE networks: - default
4. 执行 docker-compose up 命令
大功告成。
END