0


PHP8.3安装(编译)

1、下载php安装包

# php下载地址
https://www.php.net/downloads.php

2、安装php

# 1、创建php用户wwwwuseradd-M-s /sbin/nologin www

# 2、安装依赖包
yum install-y gcc libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel libXpm-devel freetype-devel libmcrypt-devel make autoconf ImageMagick-devel libssh2-devel gcc-c++ cyrus-sasl-devel sqlite-devel oniguruma-devel openldap-devel sqlite-devel libcurl-devel

# 3、上传php包,并解压tar-xf php-8.3.10.tar.gz

# 4、安装phpcd php-8.3.10
## 配置编译参数CPPFLAGS="-I/usr/include"\LDFLAGS="-L/usr/lib64 -L/usr/lib64 -lldap -llber"\
./configure \--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-config-file-scan-dir=/usr/local/php/etc/php.d \
--disable-ipv6 \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp \
--enable-gd \
--with-external-gd \
--with-jpeg \
--with-freetype \
--with-xpm \
--with-webp \
--enable-mbregex \
--enable-mbstring \
--enable-mysqlnd \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-static \
--enable-sysvsem \
--enable-xml \
--with-curl \
--with-gettext \
--with-iconv \
--with-mhash \
--with-mysqli \
--with-pdo-mysql \
--with-pear \
--with-openssl \
--with-zlib \
--with-ldap \
--with-ldap-sasl \
--disable-debug \
--disable-phpdbg
# 编译make-j$(nproc)# 安装makeinstall

3、配置PHP

# 1、配置环境变量cat>> /etc/profile <<EOF
#### php ####
export PATH=$PATH:/usr/local/php/bin
EOFsource /etc/profile

# 2、拷贝配置文件cp /root/php-8.3.10/php.ini-production /usr/local/php/etc/php.ini
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
cp /usr/local/php/sbin/php-fpm /usr/local/bin/
cp /usr/local/php/bin/php /usr/local/bin/

4、编译遇到的问题

# 找不到 ldap 的依赖库# 指定/usr/lib64依赖库后仍找不到
configure: error: Cannot find ldap libraries in /usr/lib.
# 解决## 查看是否存在ls /usr/lib64 |grep libldap*
## 生成软连接ln-s /usr/lib64/libldap* /usr/lib/
## 重新编译

5、配置启动文件

# vim /lib/systemd/system/php-fpm.service [Unit]Description=The PHP FastCGI Process Manager
After=network.target

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

6、验证PHP

# 创建php infomkdir-p /var/www/html/
echo"<?php phpinfo();?>"> /var/www/html/index.php

# 配置nginx server部分
    server {
    listen 8001;
    server_name _;
     root /var/www/html/;
     index index.html index.htm index.php;
     location ~ [^/]\.php(/|$){
         fastcgi_pass 127.0.0.1:9000;#fastcgi_pass unix:/dev/shm/php-cgi.sock;
              index index.php;
         fastcgi_index index.php;
         include fastcgi.conf;}}

在这里插入图片描述

7、install.sh

#!/bin/bashinstall_php(){user=www

echo"##### 检测网络 #####"if!ping-c1-W1 www.baidu.com &> /dev/null
thenecho"网络不可以用, 请检查网络"exit1fiecho"##### 创建php用户 #####"id$user&> /dev/null

if[$?-eq0];thenecho"$user 已存在"elseuseradd-M-s /sbin/nologin $user&> /dev/null
        echo"$user 创建成功"fi# 1.安装依赖echo"##### 安装依赖 #####"packages=(gcc libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel libXpm-devel freetype-devel libmcrypt-devel make autoconf ImageMagick-devel libssh2-devel gcc-c++ cyrus-sasl-devel sqlite-devel oniguruma-devel openldap-devel sqlite-devel libcurl-devel)forpkgin$(echo ${packages[*]})do
    yum install-y${pkg}>/dev/null 2>&1if[$?-ne0]thenecho"error:install "$pkg"  error,try again."exit2fidone# 2.下载安装echo"##### 下载php #####"# wget https://www.php.net/distributions/php-7.0.33.tar.gz >/dev/null 2>&1if[$?-ne0]thenecho-e"\033[31m 下载 'php' 失败\033[0m"exit3fitar-xf php-8.3.10.tar.gz
if[$?-ne0]thenecho-e"\033[31m error: tar xvf 'php' failed\033[0m"exit4fiecho"##### 安装php #####"cd php-8.3.10
if[$?-ne0]thenecho-e"\033[31m error:cd 'php' failed\033[0m"exit5fiCPPFLAGS="-I/usr/include"\LDFLAGS="-L/usr/lib64 -L/usr/lib64 -lldap -llber"\
./configure \--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-config-file-scan-dir=/usr/local/php/etc/php.d \
--disable-ipv6 \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp \
--enable-gd \
--with-external-gd \
--with-jpeg \
--with-freetype \
--with-xpm \
--with-webp \
--enable-mbregex \
--enable-mbstring \
--enable-mysqlnd \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-static \
--enable-sysvsem \
--enable-xml \
--with-curl \
--with-gettext \
--with-iconv \
--with-mhash \
--with-mysqli \
--with-pdo-mysql \
--with-pear \
--with-openssl \
--with-zlib \
--with-ldap \
--with-ldap-sasl \
--disable-debug \
--disable-phpdbg  >> /dev/null 2>> stderr.log

if[$?-ne0]thenecho-e"\033[31m error:./configure 'php' failed\033[0m"exit6fimake-j$(nproc)>> /dev/null 2>> stderr.log
if[$?-ne0]thenecho-e"\033[31m make 'php' failed\033[0m"exit7fimakeinstall>/dev/null 2>&1if[$?-ne0]thenecho-e"\033[31m error:make install 'php' failed\033[0m"exit8fi# 3.添加环境变量echo"##### 配置环境变量 #####"cat>> /etc/profile <<EOF
#### php ####
export PATH=$PATH:/usr/local/php/bin
EOFsource /etc/profile >/dev/null 2>&1# 4.配置phpcp /root/php-8.3.10/php.ini-production /usr/local/php/etc/php.ini
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
cp /usr/local/php/sbin/php-fpm /usr/local/bin/
cp /usr/local/php/bin/php /usr/local/bin/
}

install_php
标签: android

本文转载自: https://blog.csdn.net/qq_56189058/article/details/141930794
版权归原作者 ———————896 所有, 如有侵权,请联系我们删除。

“PHP8.3安装(编译)”的评论:

还没有评论