centos下部署php7

centos源码编译php7

下载

$ wget -O php-7.0.5.tar.gz http://cn2.php.net/get/php-7.0.5.tar.gz/from/this/mirror

安装开发包和依赖库

安装development tools

$ yum groupinstall development tools

安装yum扩展

$ rpm -ivh http://mirrors.sohu.com/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
$ yum update

安装PHP支持库

yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel php-mcrypt

编译PHP7.0

$ './configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--enable-mbregex' '--enable-mbstring' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--enable-fileinfo' '--enable-opcache'

$ make && make install

配置PHP-FPM

增加用户&用户组

$ groupadd www
$ useradd -g www www

拷贝php-fpm.conf文件

$ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

拷贝php-fpm include文件

$ cp /usr/local/php/etc/php-fpm.d/www.conf.default www.conf

拷贝php.ini

php.ini-production文件在解压tar包的目录下

$ cp php.ini-production /usr/local/php/etc/php.ini

将php加入环境变量

$ vi /etc/profile
# 以下内容写入

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

# 重置一下
$ source /etc/profile

php-fpm自启动

1.拷贝
$ cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
2.加入系统启动项
$ chkconfig php-fpm on

重启php

$ service php-fpm restart

php-fpm指定配置文件启动

// 检测php.ini和php-fpm.conf是否正确
/usr/local/php53/sbin/php-fpm -c /usr/local/php53/etc/php.ini -y /usr/local/php53/etc/php-fpm.conf -t
//指定php.ini和php-fpm.conf启动php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf

检查是否监听到端口

yum install lsof
lsof -i tcp:9053
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 14413 root    7u  IPv4  98484      0t0  TCP localhost:9053 (LISTEN)
php-fpm 14414  www    0u  IPv4  98484      0t0  TCP localhost:9053 (LISTEN)
php-fpm 14415  www    0u  IPv4  98484      0t0  TCP localhost:9053 (LISTEN)

参考文献

centos yum安装php

yum安装可能版本那啥的,装不到最新..不过没关系.方便.....

配置yum源

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

安装yum管理和设置php默认版本

这样设置之后就可以不用待版本号了. 以前: yum install php71w-gd 现在:yum install php-gd

yum install yum-utils
yum-config-manager --enable remi-php73

安装

yum install php php-mbstring php-xm php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo php-redis php-fpm php-opcache

如果有需要就安装pecl

yum install php-pear php-devel -y

启动php-fpm

$ systemctl start php-fpm.service

创建www用户和www组

因为yum安装的php-fpm运行用户和组都是apache,但是我们这里统一下.web服务都用www:www来运行

# 增加
$ groupadd www
$ useradd -g www www

修改php-fpm配置

主配置是在/etc/php-fpm.conf

这里include了
include=/etc/php-fpm.d/*.conf
修改/etc/php-fpm.d/www.conf
user = www
group = www

重启服务

$ systemctl restart php-fpm

查看服务

$ ps -ef | grep php-fpm

file

插播一句

如果你是laravel框架的话..赋予storage权限

$ chown -R www:www storage/*

提供yum 安装php的几个命令

service php-fpm start
service php-fpm stop
service php-fpm reload

yum 搜索php模块

yum search php71w-mbstring
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * rpmforge: mirrors.tuna.tsinghua.edu.cn
 * webtatic: uk.repo.webtatic.com
============================================================================= N/S matched: php71w-mbstring ==============================================================================
php71w-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
yum install php71w-mbstring -y

错误

Illuminate\Database\QueryException with message 'could not find driver

需要装pdo_mysql扩展
yum install php71w-mysql -y

Use of undefined constant MCRYPT_RIJNDAEL_128

*596 FastCGI sent in stderr: "PHP message: PHP Notice: Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128'

yum install php71w-mcrypt

类似yum编码编译扩展

我个人是比较推荐这种安装方式的, 简单明了

安装依赖

yum -y install gcc gcc-c++ autoconf automake make

下载包并且编译

cd /usr/locac/src
wget https://github.com/swoole/swoole-src/archive/v4.0.0.tar.gz
tar -zxvf v4.0.0.tar.gz
cd swoole-src-4.0.0/
phpize
./configure
make -j2

编译完成后 swoole.so文件就在/usr/local/src/swoole-src-4.0.0/modules

Libraries have been installed in:
   /usr/local/src/swoole-src-4.0.0/modules
............

移动swoole.so文件,并创建.ini配置

mkdir -p /usr/local/lib/php/extensions
mv /usr/local/src/swoole-src-4.0.0/modules/swoole.so /usr/local/lib/php/extensions/swoole.so
vim /etc/php.d/ext-swoole.ini
[swoole]
extension="/usr/local/lib/php/extensions/swoole.so"
systemctl restart php-fpm
php -m | grep swoole

参考文献