需求
为了衔接Nginx和MySQL数据库,我们需要安装php
Nginx没有内在支持php,故而,我们需要PHP-FPM (“fastCGI process manager”)来驱动它
部署实施
更新包清单
apt update
安装
apt install php-fpm
// Ubuntu 20.04.4 LTS 安装的日志记录 2022-3-1 The following additional packages will be installed: php-common php7.4-cli php7.4-common php7.4-fpm php7.4-json php7.4-opcache php7.4-readline Suggested packages: php-pear The following NEW packages will be installed: php-common php-fpm php7.4-cli php7.4-common php7.4-fpm php7.4-json php7.4-opcache php7.4-readline 0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded. Need to get 4,080 kB of archives. After this operation, 18.1 MB of additional disk space will be used. Do you want to continue? [Y/n] Y ... Setting up php-fpm (2:7.4+75) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for systemd (245.4-4ubuntu3.15) ... Processing triggers for php7.4-cli (7.4.3-4ubuntu2.9) ... Processing triggers for php7.4-fpm (7.4.3-4ubuntu2.9) ...
查看服务的状态
systemctl status php7.4-fpm
增加修改对于Nginx的衔接
server { # . . . other code location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; } }
重启服务
systemctl restart nginx
安装扩展模块,比如MySQL支持的模块
apt install php-mysql
安装扩展模块,比如图片的模块
GD is an open source code library for the dynamic creation of images. GD is used for creating PNG, JPEG and GIF images and is commonly used to generate charts, graphics, thumbnails on the fly.
apt install php-gd
创建一个临时的PHP INFO测试文件,测试通的之后,记得删除
一般的路径为 /var/www/html/info.php
<? phpinfo(); ?>
备注1, 一般推荐安装这个php 7.4的版本,不推荐安装旧的版本了。