编译安装PHP7.4, 7.3

2019-10-11  本文已影响0人  TerryLaravel

1、安装依赖

yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libXpm libXpm-devel gmp gmp-devel libzip sqlite sqlite-devel oniguruma automake libtool recode recode-devel
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel gcc pkgconfig bzip2-devel libXpm-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode recode-devel mod-ssl zlib zlib-devel sqlite sqlite-devel oniguruma
2、下载源码包

wget http://cn2.php.net/get/php-7.3.2.tar.gz/from/this/mirror

根据自己需求,下载相应的版本,这里选择7.3.2版本

3、解压源码包

tar -xzvf php-7.3.2.tar.gz

进入解压后的目录

cd php-7.3.2

4、预编译
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --bindir=/usr/local/php/bin --sbindir=/usr/local/php/sbin --includedir=/usr/local/php/include --libdir=/usr/local/php/lib/php --mandir=/usr/local/php/php/man --enable-mbstring --enable-bcmath --enable-pcntl --enable-ftp --enable-exif --enable-calendar --enable-maintainer-zts --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-curl --with-iconv --with-gmp --with-pspell --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr --with-freetype-dir=/usr --enable-gd-native-ttf --with-openssl --enable-fpm --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-gettext=/usr/bin --with-bz2=/usr/bin --with-recode=/usr/bin --with-mysqli=mysqlnd --with-apxs3 --enable-zip --with-zlib --with-pear

编译参数可以自己设置,比如这里我指定/usr/local/php为安装目录,安装mysqli pdo-mysql gd库等模块。

对于php7.0 可以使用下面的配置
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip

(1).关于zip报错处理:
需要安装高版本的 libzip,安装libzip时需要cmake来编译,所以先要安装cmake

https://www.cnblogs.com/gyfluck/p/10478386.html

https://blog.csdn.net/ijijni/article/details/89913738

hash -r //用于处理cmake ..错误
cmake ..

(2). error: off_t undefined; check your library configuration

添加搜索路径到配置文件

echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf

更新配置

ldconfig -v

(3)找不到oniguruma解决办法
要下载源码安装,yum install oniguruma是可以装,但不能解决 php安装的错误问题:wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz

下载oniguruma-6.9.4
tar -zxvf oniguruma-6.9.4.tar.gz
./autogen.sh && ./configure --prefix=/usr
make && make install

5、编译并安装

make clean &&make && make install

6、拷贝php配置文件

cp php.ini-production /usr/local/php/etc/php.ini

根据需要开启相应的的扩展, 即去掉扩展前的分号,如下示例, 也可以不改

extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=interbase
;extension=ldap
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=odbc
;extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=shmop

;extension=soap
;extension=sockets
;extension=sodium
;extension=sqlite3
;extension=tidy
;extension=xmlrpc
;extension=xsl

拷贝php-fpm服务并赋予执行权限

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
systemctl start php-fpm

7、拷贝php-fpm进程服务的配置文件和扩展配置文件

cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

8、设置php环境变量

vi /etc/profile.d/php.sh 
export PATH=$PATH:/usr/local/php/bin/:/usr/local/php/sbin/ 
source /etc/profile.d/php.sh

9、启动php-fpm

service php-fpm start

查看端口使用情况

netstat -lnt|grep 9000

10、设置php-fpm开机启动

chkconfig php-fpm on

11、配置nginx支持php

编辑php-fpm.conf,翻到php-fpm.conf最后一行,include的路径要对应于自己的安装目录

/usr/local/php/etc/php-fpm.d/www.conf 的user、group和nginx配置文件nginx.conf的user要对应

配置nginx的nginx.conf , 这两处地方修改为

l
server {
         listen 80;
         #listen       [::]:443 ssl http2 default_server;
         server_name  iots.com;
         root         /www/html/public;
         autoindex off;
         index index.html index.htm index.php;

         # Load configuration files for the default server block.
         #include /etc/nginx/default.d/ .conf;
        access_log /www/logs/iots.com_access.log;
        error_log  /www/logs/iots.com_error.log;

         location / {
                try_files $uri $uri/ /index.php?$query_string;
                root /www/html/public;
                index index.php index.html index.htm;
         }
         location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include       fastcgi_params;
        }

         error_page 404 /404.html;
             location = /40x.html {
         }

         error_page 500 502 503 504 /50x.html;
             location = /50x.html {
         }
     }

上一篇下一篇

猜你喜欢

热点阅读