源码编译安装php7.4 + nginx配置
1. 下载解压PHP7.4
- php源码包下载地址 各版本源码包 https://www.php.net/releases/
- 解压缩 tar -zxvf 命令
tar -zxvf php-7.4.33.tar.gz
2. 安装PHP + FPM
-
进入解压后的 PHP源码 目录 php-7.4.33
cd php-7.4.33
-
执行./configure 指令
./configure --with-config-file-path=/usr/local/etc --with-openssl --with-curl --with-pear --with-mysqli --with-pdo_mysql --with-sqlite3 \ --with-zip --with-zlib --enable-bcmath --enable-ctype --enable-gd -enable-calendar --enable-fileinfo --enable-gd --enable-json --enable-mbstring --enable-pdo \ --enable-filter --enable-session --enable-simplexml --enable-sockets --enable-xml --enable-xmlreader \ --enable-pcntl --enable-fpm
-
其中可能会不通过 需要安装相应的开发包
apt install libpng-dev libzip-dev libonig-dev libsqlite3-dev libcurl4-gnutls-dev libevent-dev
-
再次执行 第二步操作
-
执行make安装命令
需要在 root 用户环境下执行
,完成安装make && make install
-
拷贝 配置文件
cp php-7.4.33/php.ini-development /usr/local/etc/php.ini cd /usr/local/etc cp php-fpm.conf.default php-fpm.conf cp php-fpm.d/www.conf.default php-fpm.d/www.conf
-
配置 www.conf
user www-data
group www-data
-
安装redis扩展
# 下载phpredis源码 git clone https://gitee.com/mirrors/phpredis.git cd phpredis # 切换仓库分支 git checkout release/5.3.7 # 执行php扩展命令 phpize # 执行配置命令 作为php扩展 ./configure --with-php-config=/usr/local/bin/php-config # 执行编译安装命令 make && make install # 添加 redis.io 扩展 vim /usr/local/etc/php.ini # 添加一行代码 extension=redis.so
-
Call to undefined function think\captcha\imagettftext错误
# 下载freetype2源码包 https://download.savannah.gnu.org/releases/freetype/ # 解压进入源码目录 ./configure make && make install # 默认 freetype2 安装目录为 /usr/include/freetype2 # 重新编译安装 php ./configure --with-config-file-path=/usr/local/etc --with-openssl --with-curl --with-pear --with-mysqli --with-pdo_mysql --with-sqlite3 \ --with-zip --with-zlib --enable-bcmath --enable-ctype --enable-gd -enable-calendar --enable-fileinfo --enable-gd --enable-json --enable-mbstring --enable-pdo \ --enable-filter --enable-session --enable-simplexml --enable-sockets --enable-xml --enable-xmlreader \ --enable-pcntl --enable-fpm --with-freetype=/usr/include/freetype2 make && make install
3. Nginx 1.14配置
server_name xxx.cc;
root /xxx/fastadmin/public;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9000;
}