PHP(Hypertxt Preprocessor,超文本预处理器)是一种通用的开源脚本语言,发明于1995年,它吸取了C语言、Java语言及Perl语言的很多优点,具有开源、免费、快捷、跨平台性强、效率高等优良特性,是目前Web开发领域最常用的语言之一。本书的配套站点就是基于PHP语言编写的。

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

 

 

使用源码包的方式编译安装PHP语言环境其实并不复杂,难点在于解决PHP的程序包和其他软件的依赖关系。为此需要先安装部署将近十个用于搭建网站页面的软件程序包,然后才能正式安装PHP程序。

 

PHP官网:https://www.php.net/

创建用户、用户组

groupadd www

useradd -g www www  # 指定www用户是属于组群www的成员

下载PHP

wget -c https://www.php.net/distributions/php-7.3.4.tar.gz

解压:

tar -zxvf php-7.3.4.tar.gz

cd php-7.3.4/

编译

--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

编译错误,解决依赖

LNMP CentOS7.4 安装 php7.3.4 nginx1.4 部署 并安装wordpress 随笔 第1张

yum install openssl-devel openssl

 

configure: error: libxml2 not found. Please check your libxml2 installation.

yum install -y  libxml2-devel

 

configure: error: Please reinstall the BZip2 distribution

yum install -y  bzip2-devel

 

configure: error: cURL version 7.15.5 or later is required to compile php with cURL support

yum install -y  curl-devel

 

configure: error: jpeglib.h not found.

yum install -y  libjpeg-devel

 

configure: error: png.h not found.

yum install -y libpng-devel     # libpng源码包是用于提供png图片格式支持函数库的服务程序

 

configure: error: freetype-config not found.

yum install -y freetype-devel    # freetype源码包是用于提供字体支持引擎的服务程序

 

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

 

off_t undefined 报错

LNMP CentOS7.4 安装 php7.3.4 nginx1.4 部署 并安装wordpress 随笔 第2张

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

 

再次编译

LNMP CentOS7.4 安装 php7.3.4 nginx1.4 部署 并安装wordpress 随笔 第3张

安装:make && make install

报错:

LNMP CentOS7.4 安装 php7.3.4 nginx1.4 部署 并安装wordpress 随笔 第4张

解决方法:cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

 

再次安装 make && make install

成功输出

LNMP CentOS7.4 安装 php7.3.4 nginx1.4 部署 并安装wordpress 随笔 第5张

 

配置,建立目录:

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: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

 

加入systemctl服务

LNMP CentOS7.4 安装 php7.3.4 nginx1.4 部署 并安装wordpress 随笔 第6张

cd /opt/installation-package/php-7.3.4/sapi/fpm/

cp php-fpm.service /usr/lib/systemd/system/

 

启动:systemctl start php-fpm

查看状态:systemctl status php-fpm

LNMP CentOS7.4 安装 php7.3.4 nginx1.4 部署 并安装wordpress 随笔 第7张

MySQL扩展:

(PHP7.2不再支持mysql,而是用mysqli取代。)

由于需要和MySQL进行通信,所以需要特别查看PHP7安装后的lib扩展库目录 cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/ 下是否有mysqli.so  pdo_mysql.so

LNMP CentOS7.4 安装 php7.3.4 nginx1.4 部署 并安装wordpress 随笔 第8张

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄