(Centos7-x86)编译安装php-7.4

2023-11-20 20:35:39 浏览数 (1)

编译安装php-7.4

代码语言:javascript复制
#官网地址
https://www.php.net/downloads
#或国内网站
https://mirrors.sohu.com/php/
代码语言:javascript复制
#下载php压缩包
wget https://mirrors.sohu.com/php/php-7.4.9.tar.gz
代码语言:javascript复制
#安装依赖
yum -y install libxml2 libxml2-devel  curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel openldap openldap-devel sqlite-devel oniguruma-devel
代码语言:javascript复制
#解压,编译安装
mv php-7.4.9.tar.gz /opt/
cd /opt/
tar zxvf php-7.4.9.tar.gz
useradd -s /sbin/nologin -M php
#安装目录/usr/local/php7
cd php-7.4.9
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mhash --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --enable-bcmath  --enable-gd --with-jpeg --with-freetype  --enable-mbstring --enable-ftp --enable-sockets   --with-gettext --enable-session --with-curl   --enable-fpm --with-fpm-user=php --with-fpm-group=php   --enable-pdo -enable-tokenizer --with-zip
代码语言:javascript复制
#解决报错No package 'oniguruma' found 
yum  -y  install autoconf automake libtool
wget https://github.com/kkos/oniguruma/archive/v6.9.5_rev1.tar.gz
tar zxvf v6.9.5_rev1.tar.gz 
cd oniguruma-6.9.5_rev1/
./autogen.sh 
./configure --prefix=/usr --libdir=/lib64
make && make install
代码语言:javascript复制
#解决报错No package 'libzip' found
wget https://libzip.org/download/libzip-1.3.2.tar.gz
tar xf libzip-1.3.2.tar.gz
cd libzip-1.3.2
./configure && make && make install
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/" 
代码语言:javascript复制
#解决报错,重新编译安装php
cd php-7.4.9
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mhash --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --enable-bcmath  --enable-gd --with-jpeg --with-freetype  --enable-mbstring --enable-ftp --enable-sockets   --with-gettext --enable-session --with-curl   --enable-fpm --with-fpm-user=php --with-fpm-group=php   --enable-pdo -enable-tokenizer --with-zip
make && make install
代码语言:javascript复制
yum install net-tools -y
yum install psmisc -y
#配置文件改名
cd /usr/local/php7/etc/
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
#php命令设置软链接
ln -s /usr/local/php7/bin/* /usr/local/bin
ln -s /usr/local/php7/sbin/* /usr/local/sbin
#查看php的版本
php -v
#
php-fpm
netstat -antp | grep php-fpm
代码语言:javascript复制
#配置nginx的php网页
vim /usr/local/nginx/conf/nginx.conf

        location / {
            root   html;
            index  index.php index.html index.htm;
        }
        location ~ .php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
代码语言:javascript复制
#nginx网页目录下编写简单的php网页,验证访问nginx的php网页
vim /usr/local/nginx/html/index.php

<?php
 phpinfo();
?>
代码语言:javascript复制
#配置service nginx启动
vim /etc/init.d/nginx

#!/bin/sh
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15
 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse 
#               proxy and IMAP/POP3 proxy server
 
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid
 
# Source function library.
 
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
 
. /etc/sysconfig/network
 
# Check that networking is up.
 
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/usr/local/nginx/sbin/nginx"
 
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
 
lockfile=/var/lock/subsys/nginx
 
start() {
 
    [ -x $nginx ] || exit 5
 
    [ -f $NGINX_CONF_FILE ] || exit 6
 
    echo -n $"Starting $prog: "
 
    daemon $nginx -c $NGINX_CONF_FILE
 
    retval=$?
 
    echo
 
    [ $retval -eq 0 ] && touch $lockfile
 
    return $retval
 
}
stop() {
 
    echo -n $"Stopping $prog: "
 
    killproc $prog -QUIT
 
    retval=$?
 
    echo
 
    [ $retval -eq 0 ] && rm -f $lockfile
 
    return $retval
 
}
restart() {
 
    configtest || return $?
 
    stop
 
    start
 
}
reload() {
 
    configtest || return $?
 
    echo -n $"Reloading $prog: "
 
    killproc $nginx -HUP
 
    RETVAL=$?
 
    echo
 
}
 
force_reload() {
 
    restart
 
}
configtest() {
 
  $nginx -t -c $NGINX_CONF_FILE
 
}
rh_status() {
 
    status $prog
 
}
rh_status_q() {
 
    rh_status >/dev/null 2>&1
 
}
 
case "$1" in
 
    start)
 
        rh_status_q && exit 0
        $1
        ;;
 
    stop)
        rh_status_q || exit 0
        $1
        ;;
 
    restart|configtest)
        $1
        ;;
 
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
 
        rh_status_q || exit 0
            ;;
 
    *)
 
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
 
esac

#授权
chmod 755 /etc/init.d/nginx
service nginx restart
代码语言:javascript复制
#查看运行日记
tail -f /usr/local/php7/var/log/php-fpm.log
代码语言:javascript复制
#杀死当前php进程,重启
killall php-fpm
php-fpm
netstat -antp | grep php-fpm
tail -f /usr/local/php7/var/log/php-fpm.log
netstat -tln | grep 9000
netstat -tln | grep 80
代码语言:javascript复制
#浏览器访问
http://IP/index.php

安装ldap扩展模块

代码语言:javascript复制
#安装ldap扩展模块
cd /opt/php-7.4.9/ext/ldap
find / -name phpize
#运行phpize
/usr/local/php7/bin/phpize
#复制库文件
cp -frp /usr/lib64/libldap* /usr/lib/
#安装至/usr/local/php7/bin/php-config
./configure --with-php-config=/usr/local/php7/bin/php-config
代码语言:javascript复制
#编译安装
make && make install
代码语言:javascript复制
#修改参数
cd /opt/php-7.4.9/
cp php.ini-production /usr/local/php7/etc/php.ini
vim /usr/local/php7/etc/php.ini

extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/"
extension=ldap.so

max_execution_time = 300
post_max_size = 16M
max_input_time = 300
date.timezone = Asia/Shanghai  

PHP(PHP: Hypertext Preprocessor)即“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法学习了C语言,吸纳Java和Perl多个语言的特色发展出自己的特色语法,并根据它们的长项持续改进提升自己,例如java的面向对象编程,该语言当初创建的主要目标是让开发人员快速编写出优质的web网站。 PHP同时支持面向对象和面向过程的开发,使用上非常灵活。

我正在参与2023腾讯技术创作特训营第三期有奖征文,组队打卡瓜分大奖!

0 人点赞