ZiiyunChan的博客
关于
归档
友链
后台
切换模式
返回顶部
首页
默认分类
硬件杂谈
说说
ZiiyunChan的博客
首页
默认分类
硬件杂谈
说说
关于
归档
友链
后台
【随笔】Docker升级PHP
默认分类
·
2023-10-29
·
609 人浏览
Colico
> 本博客使用的Docker搭建,PHP为7.3.29-fpm,无法使用一些插件,为了更好的使用某些插件,故升级PHP版本。 > 注:由于对这方面了解不多,走了不少弯路,本文仅作参考。 ---- 首先在`Dockerfile`文件中修改 ```Dockerfile FROM php:7.3.29-fpm #修改为指定版本,这里我选择的是7.4.33 RUN apt-get update \ && docker-php-ext-install pdo_mysql \ && echo "output_buffering = 4096" > /usr/local/etc/php/conf.d/php.ini \ && echo "date.timezone = PRC" >> /usr/local/etc/php/conf.d/php.ini ``` 这里我是直接在Docker拉取了一个镜像 ```bash docker pull php:7.4-fpm docker run -d -v $(pwd):/var/www/html --name typecho_php_1 php74-app #创建一个新的 PHP 7.4 容器 docker exec -it NAME php -v #NAME为容器名称。查询php版本 ``` 在`docker-compose.yml`文件中修改对应的名称 ```yml services: nginx: image: nginx ports: - "8989:80" restart: always environment: - TZ=Asia/Shanghai volumes: - ./typecho:/var/www/html - ./nginx:/etc/nginx/conf.d - ./logs:/var/log/nginx depends_on: - php74 #修改为对应的容器 networks: - web php74: #修改为对应的容器 build: php restart: always expose: - "9000" volumes: - ./typecho:/var/www/html environment: - TZ=Asia/Shanghai depends_on: - mysql networks: - web ``` 在Nginx的conf文件中修改 ```conf server { listen 80 default_server; root /var/www/html; index index.php; access_log /var/log/nginx/typecho_access.log main; if (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; } location / { index index.html index.htm index.php; if (!-e $request_filename) { rewrite . /index.php last; } } location ~ \.php(.*)$ { fastcgi_pass php:9000; #php为对应的容器 fastcgi_index index.php; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ``` 可能会有些问题需要重新启动一下。~~例如直接502 Bad Gateway~~ ```bash docker-compose down docker-compose up -d ``` 最后成功升级版本为7.4.33,并且启用了之前无法使用的插件:D
Typecho
Docker
Php
取消回复
提交评论
Colico
『流水很清楚,惜花這個責任,真的身份不過送運。這趟旅行若算開心 亦是無負這一生』
摸鱼
拖延症
游戏玩家
热门文章
欢迎使用 Typecho
小白折腾NAS记录
【随笔】Docker升级PHP
Musicfox食用
最新评论
Typecho: 欢迎加入 Typecho 大家族
热门标签
NAS
Typecho
Docker
Php
关于站长
钦州
联系邮箱
自由从业
Steam主页
Theme
Jasmine
by
Kent Liao