php服务部署安装

php服务部署安装

 

开发给的另一个参考:https://blog.51cto.com/frankch/1746232

环境说明:

Centos7.6

安装包路径:/usr/local/src/

安装路径:/usr/local/php

 

1、版本确定7.2.21

2、依赖安装

yum -y install gcc-c++ glibc-headers openssl openssl-devel bzip2 bzip2-devel curl-devel libwebp libwebp-devel libjpeg-devel libpng  libpng-devel libXpm-devel freetype-devel gmp-devel libicu-devel readline-devel recode-devel libXpm libwebp libicu libxml2-devel libmcrypt libmcrypt-devel mcrypt mhash openldap-devel openldap postgresql-devel autoconf msodbcsql mssql-tools unixODBC-devel libxslt libxslt-devel

 

 

rpm -ivh oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm

rpm -ivh oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm

(该包存在于/usr/local/src下)

  

 

3、源码编译安装过程

tar fvxz php-7.2.21.tar.gz
cd php-7.2.21 
./configure  --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc/ --with-config-file-scan-dir=/usr/local/php/etc/ini.d/ --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-phar --with-iconv-dir=/usr/local/libiconv --with-openssl --with-pcre-regex --with-pcre-jit --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --enable-filter --enable-ftp --with-openssl-dir --with-gd --with-webp-dir --with-jpeg-dir --with-png-dir --with-xpm-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-intl --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-mysqli --enable-embedded-mysqli --enable-pcntl --with-pdo-mysql --with-readline --with-recode --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-xmlrpc --with-libxml-dir --with-iconv-dir --enable-zip --with-pcre-dir --enable-embed  --with-xsl --enable-opcache

make
make install

4、配置文件设置

cp -fr /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 -fr  /usr/local/src/php-7.2.21/php.ini-development  /usr/local/php/etc/php.ini

 

5、启动脚本设置

1)Centos6的方式:
cp -fr sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

2)Centos7的方式:
创建一个脚本,脚本如下
cat /usr/lib/systemd/system/php-fpm.service 
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=forking
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 

6、服务验证

/usr/local/php/sbin/php-fpm -t

 

7、服务启停命令

Centos6如下:
/etc/init.d/php-fpm start
/etc/init.d/php-fpm stop

Centos7如下(我们使用的是该种)
systemctl start php-fpm.service
systemctl stop php-fpm.service

 

8、增加php环境变量

cp -fr /usr/local/php/bin/* /usr/sbin/
cp -fr /usr/local/php/sbin/* /usr/sbin/

 

特殊点:

1、后续追加了pgsql、oci8模块的流程:

1)cd /usr/local/src/php-7.2.21/ext/pgsql
2)phpize 
3)./configure --with-php-config=/usr/local/php/bin/php-config 
4)make && make install
然后验证,问题消失
1)cd /usr/local/src/php-7.2.21/ext/oci8/
2)phpize
3)./configure --with-php-config=/usr/local/php/bin/php-config
4)make && make install

 

2、后续追加的mcrypt模块

1)cd /usr/local/src/
2)wget http://pecl.php.net/get/mcrypt-1.0.1.tgz 
3)tar xf mcrypt-1.0.1.tgz
4)cd mcrypt-1.0.1
5)phpize
6)./configure --with-php-config=/usr/local/php/bin/php-config
7)make  &&  make install

 

3、后续追加pdo_oci模块

1)cd /usr/local/src/php-7.2.21/ext/pdo_oci
2)phpize
3)./configure  --with-php-config=/usr/local/php/bin/php-config --with-pdo-oci=instantclient,/usr/lib/oracle/12.1/client64/lib
4)make && make install
开启pdo_oci模块功能
cat /usr/local/php/etc/ini.d/pdo_oci.ini  
extension=pdo_oci.so

 

4、后续追加的swoole模块

1)wget http://pecl.php.net/get/swoole-4.5.2.tgz
2)tar fvxz swoole-4.5.2.tgz 
3)cd swoole-4.5.2
4)  phpize  && ./configure --with-php-config=/usr/local/php/bin/php-config  && make  && make install

 

5)后续追加cphalcon3.1.2的模块

自行下载该版本包
1) tar  fvxz  cphalcon-3.1.2.tar.gz
2) cd  cphalcon/build/php7/64bits
3)  phpize  && ./configure --with-php-config=/usr/local/php/bin/php-config  && make  && make 

升级7.3的时候需要用更新的包,流程如下,东西都在/usr/local/src/cphalcon-new下面

下载git clone http://github.com/phalcon/cphalcon

解压完后

cd cphalcon-master/build

./install  --php-config /usr/local/php7.3/bin/php-config  --phpize  /usr/local/php7.3/bin/phpize 

make && make install

因为安装的是cphalcon4.0的版本,所以依赖于psr需要安装,流程如下

git clone https://github.com/jbboehr/php-psr.git

cd php-psr/

/usr/local/php7.3/bin/phpize

./configure --with-php-config=/usr/local/php7.3/bin/php-config

make && make install

6、追加zookeeper

cd /usr/local/src/
wget http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.12.tar.gz 
tar -zxvf zookeeper-3.4.12.tar.gz
cd zookeeper-3.4.12/src/c/
./configure --prefix=/usr/local/zookeeper  //指定一下安装目录
make && make install
wget http://pecl.php.net/get/zookeeper-0.6.2.tgz,然后解压
cd /usr/local/src/zookeeper-0.6.4
./configure --with-php-config=/usr/local/php/bin/php-config  --with-libzookeeper-dir=/usr/local/zookeeper
make && make install
注意:
移植到别的机器使用要自行将jenkins机器的/usr/local/zookeeper 拷贝走到后端机器即可使用

 

7、追加主数据必须的连接sqlserver的odbc模块

1)curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
2)yum -y install msodbcsql17
备注:如果还有问题,再安装后续两个,通常安装完msodbcsql17就可以了
yum -y install mssql-tools
yum -y install unixODBC-devel
参考
https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15
https://blog.csdn.net/zhaodongku/article/details/106982575
https://blog.csdn.net/weixin_33875564/article/details/91922485

 

8、追加mongodb模块

wget https://pecl.php.net/get/mongodb-1.6.0.tgz
tar fvxz mongodb-1.6.0.tgz 
cd /usr/local/src/mongodb-1.6.0
 /usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config 
make &&  make install

 

9、追加安装xsl、ldap模块

/usr/local/src/php-7.3.22/ext/xsl   
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config 
make &&  make install

cd /usr/local/src/php-7.3.22/ext/ldap
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config 
make &&  make install

10、追加安装人力需要的xlswriter 1.3.*

参考https://xlswriter-docs.viest.me/zh-cn/an-zhuang/ubuntu
cd /usr/local/src/
git clone https://github.com/viest/php-ext-excel-export
cd php-ext-excel-export/
git submodule update --init
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config  --enable-reader
make &&  make install

 

11、问题汇总

如出现启动服务时候报ldap.so.so相关问题,可以将线上老的机器下的
/opt/php72/lib/php/extensions/no-debug-non-zts-20170718/ldap.so  拷贝到新机器的
/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/路径下,再启动,即恢复正常
2、
参考文章
https://www.cnblogs.com/yangwenxin/p/6653450.html
报错参考:https://blog.csdn.net/u011608531/article/details/50756112

 

composer安装部署

php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"

php composer-setup.php

mv composer.phar /usr/local/sbin/composer

composer --version

 

redis扩展安装

wget http://pecl.php.net/get/redis-5.3.1.tgz
解压到/usr/local下
tar -zxvf redis-5.3.1.tgz
cd /usr/local/redis-5.3.1/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd /usr/local/php/etc
vi php.ini
在; extension_dir = "ext"下面增加
extension=redis.so

 

swoole-openssl扩展安装

cd /usr/local/
wget http://pecl.php.net/get/swoole-4.5.3.tgz
tar -zxvf swoole-4.5.3.tgz 
cd swoole-4.5.3
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-openssl 
make
make install
systemctl restart php-fpm

 

xlswriter扩展安装

wget https://pecl.php.net/get/xlswriter-1.3.2.tgz
tar xf xlswriter-1.3.2.tgz
cd xlswriter-1.3.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-reade 
 make && make install


这个没加[xlswriter]
extension=/www/server/php/72/lib/php/extensions/no-debug-non-zts-20170718/xlswriter.so

 

pecl扩展安装

cd /usr/local/php/bin/
wget http://pear.php.net/go-pear.phar -O go-pear.php
php go-pear.php
使用pecl插件安装插件的步骤
pecl install XXX插件
追加/usr/local/php/etc/ini.d/xxx.ini配置文件

 

php-rdkafka扩展安装

参考文档:https://segmentfault.com/a/1190000016310618
1)先安装个依赖包
 git clone https://github.com/edenhill/librdkafka.git
$ cd librdkafka
$ ./configure
$ make && make install

2)再安装主安装包
1、cd /usr/local/php/bin
2、./pecl install rdkafka
3、添加扩展
vim /usr/local/php/etc/ini.d/rdkafka.ini 
extension=rdkafka.so

 

php igbinary扩展安装

[root@nginx ~]# cd /usr/local/src/
[root@nginx src]# wget http://pecl.php.net/get/igbinary-3.1.2.tgz
[root@nginx src]# tar  -zxvf igbinary-3.1.2.tgz
[root@nginx src]# cd igbinary-3.1.2
[root@nginx igbinary-3.1.2]# /usr/local/php/bin/phpize
[root@nginx igbinary-3.1.2]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@nginx igbinary-3.1.2]# make
[root@nginx igbinary-3.1.2]# make install
[root@nginx igbinary-3.1.2]# vim /usr/local/php/etc/php.ini
;extension_dir = "./"      # 增加改成下面路径
extension_dir = "/usr/local/php-7.2.31/lib/php/extensions/no-debug-non-zts-20170718/"
extension = memcache.so
extension = redis.so
extension = igbinary.so   # 增加
 
 
# 重启php-fpm
[root@nginx ~]# systemctl restart php-fpm

 

上一篇:‘make‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件 解决方案


下一篇:make 学习笔记