一、新增用户 用户组
groupadd www
useradd -g www www
二、官网下载源码:
官网下载地址:http://php.net/downloads ,在这个页面选择一个具体的版本进行下载
wget https://www.php.net/distributions/php-7.3.8.tar.gz
三、解压
tar -xzvf php-7.3.6.tar.gz
cd php-7.3.6
四、安装依赖包
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
五、编译
–with-fpm-user=www --with-fpm-group=www
这里使用www www 用户、用户组
编译出来的程序启动,就是归属这个用户、用户组
./configure --prefix=/usr/local/php --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
六、编译错误解决
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install -y libxslt-devel
configure: error: Please reinstall the libzip distribution
yum install -y libzip-devel
checking for libzip… configure: error: system libzip must be upgraded to version >= 0.11
#先删除旧版本
yum remove -y libzip
#下载编译安装
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install
configure: error: off_t undefined; check your library configuration
这是off_t undefined 报错
off_t 类型是在 头文件 unistd.h中定义的,
在32位系统 编程成 long int ,64位系统则编译成 long long int ,
在进行编译的时候 是默认查找64位的动态链接库,
但是默认情况下 centos 的动态链接库配置文件/etc/ld.so.conf里并没有加入搜索路径,
这个时候需要将 /usr/local/lib64 /usr/lib64 这些针对64位的库文件路径加进去。
#添加搜索路径到配置文件
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
#然后 更新配置
ldconfig -v
七、安装
make && make install
报错解决
/usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
成功输出
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php/lib/php/
[PEAR] Archive_Tar - installed: 1.4.7
[PEAR] Console_Getopt - installed: 1.4.2
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.3
[PEAR] PEAR - installed: 1.10.9
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/src/php-7.3.6/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
八、配置,建立目录
cp php.ini-production /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/sbin/php-fpm /usr/local/bin
cd /usr/local/php/etc/php-fpm.d
vim www.conf
[www]
listen = 127.0.0.1:9000
listen.mode = 0660
user = www #php代码目录权限 需要跟这个一致,
group = www #php代码目录权限 需要跟这个一致
pm = dynamic
pm.max_children = 128
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 10000
rlimit_files = 1024
slowlog = log/$pool.log.slow
保存、退出
九、加入 systemtl 服务
cd /usr/src/php-7.3.6/sapi/fpm/
cp php-fpm.service /usr/lib/systemd/system/
十、启动
systemctl start php-fpm
十一、查看状态
[root@fxt fpm]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2019-08-09 15:36:50 CST; 11s ago
Main PID: 31252 (php-fpm)
CGroup: /system.slice/php-fpm.service
├─31252 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
├─31253 php-fpm: pool www
├─31254 php-fpm: pool www
├─31255 php-fpm: pool www
├─31256 php-fpm: pool www
├─31257 php-fpm: pool www
├─31258 php-fpm: pool www
├─31259 php-fpm: pool www
├─31260 php-fpm: pool www
├─31261 php-fpm: pool www
├─31262 php-fpm: pool www
├─31263 php-fpm: pool www
├─31264 php-fpm: pool www
├─31265 php-fpm: pool www
├─31266 php-fpm: pool www
├─31267 php-fpm: pool www
├─31268 php-fpm: pool www
├─31269 php-fpm: pool www
├─31270 php-fpm: pool www
├─31271 php-fpm: pool www
└─31272 php-fpm: pool www
Aug 09 15:36:50 fxt systemd[1]: Started The PHP FastCGI Process Manager.
十二、把php设置为环境变量
vim /etc/profile
添加以下内容
PATH="$PATH:/usr/local/php/bin"
export PATH
立即生效:
source /etc/profile