网站运维:centos7.5编译安装php7.3.6

新增用户 用户组

groupadd www
useradd -g www www

另外需要安装 httpd-devel,如果没有 httpd-devel ,在安装 PHP 时不会生成libphp7.so文件:

 yum -y install httpd-devel

安装依赖库包

安装 php 7.3 需要的一些依赖库包和一些其他依赖的扩展库:

yum install -y autoconf automake libtool re2c libxml* openssl* BZip2* libcurl* libjpeg* libpng* libXpm* libzip* zlib* freetype* pcre* flex bison tar get

……………………处理错误…………………………

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install -y libxslt-devel
configure: error: Please reinstall the BZip2 distribution

yum install -y bzip2-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

vim /etc/ld.so.conf 
#添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64 
#保存退出
:wq
ldconfig -v # 使之生效
make: *** [ext/zip/php_zip.lo] Error 1


在安装完新版的 libzip 时可能会出现打不到 zipconf.h,
手动复制一下 cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
当配置PHP时出现  make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1 时

是因为服务器内存不足1G。

只需要在配置命令中添加 --disable-fileinfo即可 
Disable fileinfo support 禁用 fileinfo,搞定

…………………………错误处理……………………………

1、下载安装包

https://www.php.net/distributions/php-7.3.6.tar.gz

下载
php-7.3.6.tar.gz

2、用winscp上传到服务器

在这里插入图片描述

3、解压

tar -zxvf php-7.3.6.tar.gz

4、进入php-7.3.6文件夹

cd ./php-7.3.6

5、查看编译参数(可选)

./configure --help

6、配置参数,编译安装

直接输入

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-fpm-user=www \
--with-fpm-group=www \
--with-zlib-dir \
--with-freetype-dir \
--with-zlib-dir=DIR \
--with-pcre-dir \
--with-libzip=DIR \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--with-gd \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--enable-opcache \
--disable-fileinfo

make && make install

即可安装
网站运维:centos7.5编译安装php7.3.6_第1张图片

9、配置php:

9.1、到之前编译的源码包中将 php.ini-production 复制到 /etc/php.ini

php-ini:
源码包里面有配置文件:
php.ini-development 测试开发环境
php.ini-production 生产环境

复制一份到指定的目录下
(根据自己的情况选用,自己可以对比下这两个文件的差异):

cd /home/php-7.3.6
cp php.ini-production /usr/local/php/etc/php.ini

9.2、复制php-fpm.conf 、www.conf

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

9.2.1、修改www.conf

[www]
listen = 127.0.0.1:9080   
listen.mode = 0666     
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

9.3、添加软连接

ln -s /usr/local/php/sbin/php-fpm /usr/local/bin

9…4、复制php-fpm.service

加入 systemtl 服务
cp /home/php-7.3.6/sapi/fpm/php-fpm.service /usr/lib/systemd/system/

10、启动

systemctl start php-fpm
#查看状态
systemctl status php-fpm

10.1、显示状态

● 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 Sat 2019-06-22 15:39:06 CST; 7s ago
 Main PID: 15563 (php-fpm)
   CGroup: /system.slice/php-fpm.service
           ├─15563 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
           ├─15564 php-fpm: pool www
           ├─15565 php-fpm: pool www
           ├─15566 php-fpm: pool www
           ├─15567 php-fpm: pool www
           ├─15568 php-fpm: pool www
           ├─15569 php-fpm: pool www
           ├─15570 php-fpm: pool www
           ├─15571 php-fpm: pool www
           ├─15572 php-fpm: pool www
           ├─15573 php-fpm: pool www
           ├─15574 php-fpm: pool www
           ├─15575 php-fpm: pool www
           ├─15576 php-fpm: pool www
           ├─15577 php-fpm: pool www
           ├─15578 php-fpm: pool www
           ├─15579 php-fpm: pool www
           ├─15580 php-fpm: pool www
           ├─15581 php-fpm: pool www
           ├─15582 php-fpm: pool www
           └─15583 php-fpm: pool www

Jun 22 15:39:06 VM_0_17_centos systemd[1]: Started The PHP FastCGI Process M....
Jun 22 15:39:06 VM_0_17_centos systemd[1]: Starting The PHP FastCGI Process ....
Hint: Some lines were ellipsized, use -l to show in full.

11、设置环境变量:php 命令环境

11.1、在/etc/profile里新增内容为

export PATH=$PATH:/usr/local/php/bin

11.2、更新环境变量

source /etc/profile

11.3、查看php-v

在这里插入图片描述

你可能感兴趣的:(网站运维,PHP)