一、php7安装:
CentOS/RHEL 7.x:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
CentOS/RHEL 6.x:
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
我拿了两台6.x的测试,另外一台安装提示:Package: php70w-mcrypt-7.0.12-1.w6.x86_64 (webtatic) Requires: libmcrypt.so()64的错误
多安装:rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
然后运行:
yum install php70w php70w-bcmath php70w-cli php70w-common php70w-fpm php70w-mcrypt php70w-mysqli php70w-pear php70w-devel php70w-mbstring php70w-gd php70w-opcache
以上参考:http://blog.csdn.net/dxywx/article/details/50609137
二、redis安装:
服务:
请查看历史博文 http://www.webyang.net/Html/web/article_174.html
扩展:
cd /opt
git clone https://github.com/phpredis/phpredis.git
/usr/bin/phpize
./configure –with-php-config=/usr/bin/php-config
make && make install
三、memcache安装:
服务:
yum install memcached
扩展:
cd /opt
git clone https://github.com/websupport-sk/pecl-memcache.git
(介绍页:https://github.com/websupport-sk/pecl-memcache,很多人memcache扩展找不到)
/usr/bin/phpize
./configure –with-php-config=/usr/bin/php-config
make && make install
四、mongodb安装:
服务:
查看历史博文:http://www.webyang.net/Html/web/article_274.html
不过有台机器启动的时候报了个错:error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory。
解决方法:先执行yum whatprovides libstdc++.so.6(查看哪个安装包包含该库),打印如下:
[root@BJ-YZ-S-23106 bin]# yum whatprovides libstdc++.so.6
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: mirrors.btte.net
* updates: mirror.neu.edu.cn
libstdc++-4.4.7-16.el6.i686 : GNU Standard C++ Library
Repo : base
Matched from:
Other : libstdc++.so.6
然后再执行:yum install libstdc++-4.4.7-16.el6.i686
此处参考:https://my.oschina.net/xiaohai945/blog/491211
扩展:
https://pecl.php.net/package/mongodb(最新的1.2.2没装上去,1.1.9试了可以)
cd /opt
wget https://pecl.php.net/get/mongodb-1.1.9.tgz
tar -xzvf mongodb-1.1.9.tgz
cd mongodb-1.1.9
/usr/bin/phpize
./configure –with-php-config=/usr/bin/php-config
make && make install
另外需要注意:php5.x的mongodb扩展可以是mongo、mongodb(我试了mongodb装不上,mongo可以),php7的mongodb扩展只支持mongodb,而且mongo扩展被抛弃,不提供更新,但是历史版本仍然可用。
五、其他:
vi /etc/php.ini
添加
extension=redis.so
extension=memcache.so
extension=mongodb.so
正常编译安装的都在 /usr/local/php底下,但是yum安装的则相对比较分散(这是我不太喜欢yum安装的一个原因)。
编译安装的php5.x:
/usr/local/php/sbin/php-fpm
/usr/local/php/etc/php-fpm.conf
/usr/local/php/bin/php
yum安装的php7:
/usr/sbin/php-fpm
/etc/php-fpm.conf
/etc/php-fpm.d/www.conf
/usr/bin/php
扩展:
/usr/lib64/php/modules/
php-fpm启动脚本:
vim /etc/init.d/php-fpm7
#!/bin/bash # # Startup script for the PHP-FPM server. # # chkconfig: 345 85 15 # description: PHP is an HTML-embedded scripting language # processname: php-fpm # config: /usr/local/php/etc/php.ini # Source function library. . /etc/rc.d/init.d/functions DESC="php-fpm daemon" NAME=php-fpm # php-fpm路径 DAEMON=/usr/sbin/$NAME # 配置文件路径 CONFIGFILE=/etc/php-fpm.conf # PID文件路径(在php-fpm.conf设置) PIDFILE=/var/run/$NAME/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME # Gracefully exit if the package has been removed. test -x $DAEMON || exit 0 rh_start() { $DAEMON -y $CONFIGFILE || echo -n " already running" } rh_stop() { kill -QUIT `cat $PIDFILE` || echo -n " not running" } rh_reload() { kill -HUP `cat $PIDFILE` || echo -n " can't reload" } case "$1" in start) echo -n "Starting $DESC: $NAME" rh_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" rh_stop echo "." ;; reload) echo -n "Reloading $DESC configuration..." rh_reload echo "reloaded." ;; restart) echo -n "Restarting $DESC: $NAME" rh_stop sleep 1 rh_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2 exit 3 ;; esac exit 0
因为两个项目需要不同的php版本,所以我在一台服务器上装了两个php,一个编译的5.x,一个yum的7.0,php-fpm的一个监听端口改为9001,nginx也需要小调整下fastcgi_pass的解析,其他没变。
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/98488.html