您所在的位置:首页 - PHP - 正文PHP

PHP7.4.0 源码编译安装

萧何-Vincent 萧何-Vincent 2021-11-09 【PHP】 1076人已围观

1. 下载安装编译工具

yum groupinstall 'Development Tools'


2.安装依赖包

yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel


3. 下载并解压PHP7.4.0

wget http://mirrors.sohu.com/php/php-7.4.0.tar.gz 

# 解压 tar -zxvf php-7.4.0.tar.gz  

cd php-7.4.0


4. 新增用户和用户组

groupadd www

useradd -g www www


5. 生成编译文件

./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-fpm-user=www --with-fpm-group=www --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-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm


6. 编译安装make  && make install -j 2

  -j 指定执行的进程数


7.安装成功之后,设置环境变量


vim /etc/profile

添加
PATH=$PATH:/usr/lcoal/php74/bin
export PATH

立即生效
source  /etc/profile



8. 测试查看PHP版本



php -v


创建php-fpm软链接
ln -s /usr/local/php74/sbin/php-fpm  /usr/local/php74/bin/php-fpm

php-fpm -v


9.配置



#将源码中的配置文件复制到PHP的配置文件中
cp php.ini-production /usr/local/php74/etc/php.ini


#将PHP目录中的php-fpm配置文件进行修改
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/


10.添加php-fpm启动项


#将PHP源码中的php-fpm启动文件加入到服务自启动文件中
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

#赋予执行权限
chmod +x /etc/init.d/php-fpm

#启动php-fpm
/etc/init.d/php-fpm  start


11.php-fpm服务化

 centos7 已经使用systemctl来进行服务的管理,这里我们也使用systemctl来对php-fpm进行管理

修改php-fpm.conf文件
打开pid=/var/run/php-fpm.pid

cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm74.service

ln -s /usr/lib/systemd/system/php-fpm74.service /usr/lib/systemd/system/php-fpm.service

systemctl daemon-reload

systemctl enable php-fpm

php-fpm.service文件内容:


[Unit]
Description=The PHP FastCGI Process Manager
After=network.target

[Service]
Type=simple
PIDFile=/usr/local/php74/var/run/php-fpm.pid
ExecStart=/usr/local/php74/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php74/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

PrivateTmp=true
[Install]
WantedBy=multi-user.target


停止之前启动的php-fpm, 使用systemctl启动php-fpm

systemctl start php-fpm.service



12.在使用的时候发现zip扩展没有安装,现在需要添加扩展

在PHP源代码包中,我的源码路径:/mnt/php-7.4.0/, 需要进去到zip扩展包中cd  /mnt/php-7.4.0/ext/zip

#生成配置文件
phpize

./configure --with-php-config=/usr/local/php74/bin/php-config --with-zip

make && make install在配置文件中开启扩展即可 php.ini


常见错误:

1. error: Package requirements (sqlite3 > 3.7.4) were not met

yum install libsqlite3x-devel -y


2.error: Package requirements (oniguruma) were not met

yum install oniguruma-devel -y


3. 访问nginx无法解析PHP文件



server {
        listen       8081;
        server_name  localhost; 
        index        index.html index.php;
        root         /data/www;
        
        access_log  /data/logs/www.access.log  main;
        error_log   /data/logs/www.error.log;
        location / {
            if (!-e $request_filename) {
                rewrite ^/(.*) /index.php last;
            }
        }
        
        location ~ .*\.(php|php5)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  # 这里注意需要进行修改
            include        fastcgi_params;
        }
        
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


4. configure: error: Package requirements (libzip >= 0.11) were not met: No package 'libzip'

libzip  版本太低了
编译安装,指定PKG_CONFIG_PATH,上面报错中其实有提示信息,让我们考虑调整PKG_CONFIG_PATH环境变量。
下面是详细步骤:

 # 先卸载已有
yum remove libzip
# 然后安装
wget https://libzip.org/download/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install

装完了之后找一下/usr/local/lib下有没有pkgconfig目录,有的话执行命令export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"指定PKG_CONFIG_PATH。
到这里问题解决!


5. 安装扩展的时候

Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment


安装autoconf

yum install -y autoconf



Tags: PHP

文章评论 (暂无评论,1076人围观)

我的名片

网名:Vincent

职业:IT

现居:SZ

Email:53126692@qq.com

站长寄语:技术分享,支持原创!

站点信息

  • 文章总数:65
  • 页面总数:1
  • 分类总数:5
  • 标签总数:12
  • 评论总数:24
  • 浏览总数:82970
取消
微信二维码
支付宝二维码

目录[+]