LEMP之PHP7.4编译安装

编程入门 行业动态 更新时间:2024-10-15 10:17:55

<a href=https://www.elefans.com/category/jswz/34/1254237.html style=LEMP之PHP7.4编译安装"/>

LEMP之PHP7.4编译安装

一、准备条件

安装配置好nginx,mysql服务

 

卸载已安装的rpm包   

rpm -e php php-cli php-ldap php-common php-mysql --nodeps

 

安装编译php所需的依赖包

如果想让编译的php支持mcrypt、mhash扩展和libevent,此处还需要下载如下几个rpm包并安装之:

libmcrypt-2.5.8-4.el5.centos.i386.rpm

libmcrypt-devel-2.5.8-4.el5.centos.i386.rpm

mhash-0.9.9-1.el5.centos.i386.rpm

mhash-devel-0.9.9-1.el5.centos.i386.rpm

mcrypt-2.6.8-1.el5.i386.rpm

 

最好使用升级的方式安装上面的rpm包,命令格式如下:

# rpm -Uvh 

 

使用tar方式安装:

tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt

./configure

make

make install

ln -s /usr/local/lib/libmcrypt.* /usr/local/lib

tar -zxf mhash-0.9.9.tar.gz

tar -zxf mcrypt-2.6.8  (如果配置时出现:libmcrypt was not found,运行这个命令export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH后,再配置。)

yum install -y gcc gcc-c++ make automake autoconf gd file bison patch mlocate flex diffutils 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 libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers openldap-devellibxslt-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel   recode-devel gmp-devel icu  libxslt libxslt-devel sqlite-devel

 

二、安装php解析环境,编译时添加--enable-fpm参数

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql-sock --with-mysqli --with-libxml --with-openssl  --with-mhash  --with-zlib --with-iconv --with-bz2 --with-curl --with-cdb  --enable-gd --with-openssl-dir --with-jpeg --with-zlib-dir --with-freetype --with-gettext --with-gmp --with-mhash --with-pdo-mysql --with-zlib-dir --with-readline --with-libxml --with-xsl --with-pear --enable-fpm --enable-soap --enable-bcmath --enable-calendar --enable-dom --enable-exif --enable-fileinfo --enable-filter --enable-ftp --enable-json --enable-mbstring --enable-mbregex  --disable-mbregex  --enable-pdo --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm  --enable-mysqlnd-compression-support --enable-fpm --with-apxs2=/usr/local/httpd/bin/apxs (apache)

(使用./configure --help查看可用的选项)

报错1:no package sqlite3 found

yum install sqlite-devel

报错2:no package oniguruma found

办法1.不使用mbstring的正则功能,即在“--enable-mbstring”后再添加“--disable-mbregex”参数。这样的配置将不再需要oniguruma库。

  办法2.使用yum安装oniguruma。

    命令:

yum -y install .7.1908/cloud/x86_64/openstack-queens/oniguruma-6.7.0-1.el7.x86_64.rpmyum -y install .7.1908/cloud/x86_64/openstack-queens/oniguruma-devel-6.7.0-1.el7.x86_64.rpm

报错3:

No package 'libzip' found

我不知道网上的教程是怎么回事,反正在centos7+PHP 7.4.2 环境下,网上的所有教程都不对,一个都不对
这个问题的完整报错如下:

checking for libzip >= 0.11... no

configure: error: Package requirements (libzip >= 0.11) were not met:

No package 'libzip' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you

installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBZIP_CFLAGSand LIBZIP_LIBS to avoid the need to call pkg-config.See the pkg-config man page for more details.

报错提示非常明显,配置程序没有找到libzip库,你用yum安装libzip-devel的话,安装的版本是0.10,版本达不到要求。所以,此时我们需要卸载掉yum安装的libzip然后手动安装新版。

yum remove libzip libzip-devel

wget .2.0.tar.gz

tar -zxvf libzip-1.2.0.tar.gz

cd libzip-1.2.0./configure

make && make install

在网上找到的教程到了这一步就直接让你继续在PHP源码目录里面执行configure程序继续配置了,其实你虽然已经安装了libzip1.2,但是PHP的configure程序依然找不到,不知道你安装在哪,你得告诉PHP的configure程序,我安装了libzip 1.2,并且安装在何处。以前是用ldconfig来通告系统所需动态库文件的位置,现在用pkg-config。
我刚刚提供的方法安装的libzip默认被安装到了 /usr/local/lib 在这个目录下你能看到libzip.so libzip.so.5 libzip.so.5.0.0 还有一个pkgconfig目录。
所以,真正的解决方法来了,在你configure的会话窗口直接输入如下内容:
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
上面命令的作用就是告诉configure程序,去/usr/local/lib 目录下找库文件,这样他就能找到libzip.so
此时,你继续./configure将会很顺利的看到

 

make

make install

cp /usr/src/php-5.3.6/php.ini-development /usr/local/php5/php.ini

vi /usr/local/php5/php.ini

……

default_charset = "utf-8”

file_uploads = On

upload_max_filesize = 2M

max_file_uploads = 20

post_max_size = 8M

short_open_tag = On

------------------------------------------------------------------------

添加优化模块(如果有)

root@www ~]# tar zxf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz -C /usr/src/

[root@www ~]# cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/

[root@www php-5.3.x]# cp ZendGuardLoader.so /usr/local/php5/lib/php/

[root@www php-5.3.x]# vi /usr/local/php5/php.ini

……

[Zend Guard Loader]

zend_extension="/usr/local/php5/lib/php/ZendGuardLoader.so"

zend_loader.enable=1

----------------------------------------------------------------------------

使用PHP的FPM程序

cd /usr/local/php5/etc

cp php-fpm.conf.default php-fpm.conf

vi /usr/local/php5/etc/php-fpm.conf

Cd php-fpm.d

Cp  www.conf.default  www.conf

pid = run/php-fpm.pid      确认pid文件位置

;user = nginx

;group = nginx

;pm.start_servers = 20

;pm.min_spare_servers = 5

;pm.max_spare_servers = 35

[root@localhost etc]# /usr/local/php5/sbin/php-fpm

 

将php-fpm加入到system中管理

 

# 所有system的启动脚本都在此目录下

 

/usr/lib/systemd/system

 

创建php-fpm.service文件
文件内容如下

 

[Unit]

Description=php-fpm

After=network.target

[Service]

Type=forking

PIDFile=/run/php-fpm.pid

ExecStart=/usr/local/php/sbin/php-fpm

ExecStop=/usr/bin/pkill -9 php-fpm

PrivateTmp=true

[Install]

 

 

WantedBy=multi-user.target

 

重载systemctl配置

systemctl daemon-reload

这样就可以使用systemctl命令管理php-fpm了
systemctl start php-fpm.service
systemctl stop php-fpm.service

 

 

Nginx的PHP支持配置

方式1:使用proxy_pass指定LNMP的监听地址

[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf

……

 server {

    ……

        location ~ \.php$ {

            proxy_pass   http://192.168.4.253:80;

        }

 }

方式2:使用fastcgi_pass指定php-fpm的监听地址

[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf

……

 server {

    ……

        location ~ \.php$ {

            root           /var/www/benet;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;        记得在location / {中也要包含

            include        fastcgi.conf;     加载默认的FastCGI配置

 

        }

 }……

[root@www ~]# vim /usr/local/nginx/html/index.php

<?php

Phpinfo();

 

?>

 

更多推荐

LEMP之PHP7.4编译安装

本文发布于:2024-02-24 15:42:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1695812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:LEMP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!