ubuntu16.04编译安装PHP7.0.9,Nginx1.10,Phalcon3.1扩展
==================== PHP 7.0 编译安装 ==================
1. 下载PHP7.0.9
wget http://cn2.php.net/get/php-7.0.9.tar.bz2/from/this/mirror -- 下载php镜像
tar xvf mirror -- 解压镜像
cd php-7.0.9/ -- 进入安装目录
sudo apt-get update -- 更新阿里云库
2. 安装PHP7.0.9
检查配置文件: ./configure --prefix=/opt/php-7.0.9 --with-config-file-path=/opt/php-7.0.9/etc --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --with-mcrypt --with-zlib --with-gd --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-pdo-mysql --with-mysqli --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --enable-ftp --with-imap --with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --without-pear --disable-phar
检查配置文件成功后出现的界面:成功通过
sudo apt-get install libkrb5-dev libc-client2007e libc-client2007e-dev libcurl4-openssl-dev libbz2-dev libjpeg-dev libmcrypt-dev libxslt1-dev libxslt1.1 libpq-dev libpng12-dev libfreetype6-dev build-essential git
php 的编译时,出现的PEAR package PHP_Archive not installed问题:编译使用参数 --without-pear 将pear 屏蔽掉编译安装后,再进行安装;同时因为phar 属于pear的一个库 ,所以不将phar关闭掉,同时还会报这个错误,
同时需要使用 --disable-phar 编译参数,./configure --without-pear --disable-phar
这三项必须打开:
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
make -- 编译 或者根据你当前正在编译机器cpu核数调参数加速编译,比如2核 make -j2 就可以同时跑2个job加速编译
make install --安装
/opt/php-7.0.9/bin/php -i -- 基本配置信息
PHP Version =》 7.0.9
/opt/php-7.0.9/bin/php -v -- 注意这里是查看的php-cli 的版本
PHP 7.0.9 (cli)(built: Mar 13 2017 21:42:35)
运行php-fpm服务前:要配置php的配置文件
sudo mv /opt/php-7.0.9/etc/php-fpm.conf.default /opt/php-7.0.9/etc/php-fpm.conf
sudo mv /opt/php-7.0.9/etc/php-fpm.d/www.conf.default /opt/php-7.0.9/etc/php-fpm.d/www.conf
sudo cp ./php.ini-production /opt/php-7.0.9/etc/php.ini
修改fpm的监听端口:
sudo vi /opt/php-7.0.9/etc/php-fpm.d/www.conf
;listen = 127.0.0.1:9000 -- 默认是打开的,在前面加; 注释掉
listen = /var/run/php7.0.9-fpm.sock -- 添加这一行
启动fpm服务:
sudo /opt/php-7.0.9/sbin/php-fpm -- 启动 php-fpm 服务 |
如果提示错误信息:
2017/03/23 20:07:53 [crit] 18683#0: *1 connect() to unix:/var/run/php7.0.9-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, |
解决办法:修改www.conf文件
listen.owner = www-data
listen.group = www-data
;listen.mode = 0660
修改为:(去掉listen.mode前面的“;”)
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
继续重启fpm服务,查看fpm服务是否启动,可用命令:ps -aux | grep 'php-fpm',若fpm启动成功,则显示有一个主进程fpm和若干个fpm子进程;
浏览器查看:
最后安装pear:
wget http://pear.php.net/go-pear.phar
/usr/local/bin/php go-pear.phar;
==================== Nginx1.10 编译安装 ==================
1. 下载并解压缩Nginx
wget http://nginx.org/download/nginx-1.10.3.tar.gz
tar -zxvf nginx-1.10.3.tar.gz
2. 安装Nginx
2.1 检查nginx的配置
./configure --prefix=/usr/local/nginx --with-debug --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --user=www-data --group=www-data
错误提示:
./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using --without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE library
解决办法:
apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make build-essential curl
2.2 重载nginx
sudo /usr/local/nginx/sbin/nginx -s reload
报错信息:
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
解决办法:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf:使用nginx -c的参数指定nginx.conf文件的位置
==================== 安装Phalcon扩展 ==================
通过zephir安装Phalcon扩展
1. 下载安装zephir
git clone https://github.com/phalcon/zephir
php编译安装扩展需要使用到phpize命令:该命令在php编译安装时就安装了,建立一个软连接即可使用:sudo ln -s /opt/php-7.0.9/bin/phpize /usr/bin/phpize
1.1 安装zephir:
sudo apt-get update
sudo apt-get install git gcc make re2c php5 php5-json php5-dev libpcre3-dev
参考链接:https://blog.csdn.net/u011142688/article/details/51619811
1.2 安装phalcon扩展:
安装好zephir之后,git clone --depth=1 "git://github.com/phalcon/cphalcon.git"
进入cphalcon/build/php7/64bit目录,执行
sudo phpize,(此时可能会出现:Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.的问题)
./configure -with-php-config=Path(php配置文件的位置)
Sudo make
Sudo make install
然后 找到phalcon.so的路径: sudo find / -name phalcon.so
然后sudo vim /opt/php-7.0.9/etc/php.ini将phalcon.so扩展安装到php中,修改配置文件:
Extension=/opt/php-7.0.9/lib/php/extensions/no-debug-non-zts-20151012/phalcon.so
1.3 重启php-fpm
先kill掉原来的进程,重启即可
phpinfo();文件输出
则phalcon扩展安装成功
安装参考:https://www.cnblogs.com/tinywan/p/6607395.html