前端之家收集整理的这篇文章主要介绍了
ubuntu下php7+nginx+swoole+yaf,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
环境
ubuntu: 14.04
PHP: 7.0.10
Nginx: 1.10.1
swoole:1.8.9
MysqL: 5.7.13
redis: 3.2.1
yaf: 3.0.2
编译环境
更新ubuntu:
apt-get update
apt-get upgrade
编译PHP所需编译工具以及依赖包:
sudo apt-get install build-essential gcc g++ autoconf libiconv-hook-dev libmcrypt-dev libxml2-dev libMysqLclient-dev libcurl4-openssl-dev libjpeg8-dev libpng12-dev libfreetype6-dev libXpm-dev libpcre3 libpcre3-dev
安装PHP 7.0.10
1. wget http://cn2.PHP.net/distributions/PHP-7.0.10.tar.gz
2. tar -zxvf PHP-7.0.10.tar.gz
4. cd PHP-7.0.10
5. ./configure --prefix=/usr/local/PHP \
--with-config-file-path=/etc/PHP \
--enable-fpm \
--enable-pcntl \
--enable-MysqLnd \
--enable-opcache \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-shmop \
--enable-zip \
--enable-soap \
--enable-xml \
--enable-mbstring \
--disable-rpath \
--disable-debug \
--disable-fileinfo \
--with-MysqLi=MysqLnd \
--with-pdo-MysqL=MysqLnd \
--with-pcre-regex \
--with-iconv \
--with-zlib \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-png \
--with-zlib-dir \
--with-ttf \
--with-jpeg-dir \
--with-freetype-dir \
--with-xpm-dir \
--with-openssl \
--with-mhash \
--with-xmlrpc \
--with-curl \
--with-imap-ssl
6. sudo make
7. sudo make install
8. sudo mkdir /etc/PHP
9. sudo cp PHP.ini-development /etc/PHP/PHP.ini
10. vim ~/.bashrc 在末尾加上两行
export PATH=/usr/local/PHP/bin:$PATH
export PATH=/usr/local/PHP/sbin:$PATH
保存后执行:
source ~/.bashrc
10. PHP -v 即可看到版本
mac:
./configure --prefix=/usr/local/PHP --with-apxs2=/usr/sbin/apxs --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-MysqLi --with-pdo-MysqL --with-iconv-dir --with-freetype-dir --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 --without-pear --with-gettext=/usr/local/opt/gettext/ --disable-fileinfo --enable-maintainer-zts
安装 swoole1.8.9
1. wget https://github.com/swoole/swoole-src/archive/1.8.9-stable.tar.gz
2. tar -zxvf 1.8.9-stable.tar.gz
3. cd swoole-src-1.8.9-stable/
4. PHPize
5. ./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config
./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config --enable-swoole-debug --enable-sockets --enable-http2 --enable-async-redis --enable-jemalloc --enable-openssl --with-openssl=/usr/local/openssl
./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config --enable-sockets --enable-http2 --enable-async-redis --enable-jemalloc --enable-openssl --with-openssl=/usr/local/openssl
6. sudo make && make install
5. sudo vim /etc/PHP/PHP.ini 最后添加
extension=swoole.so
PHP.ini开启 proc_open
配置PHP.ini
编译安装成功后,修改PHP.ini加入
extension=swoole.so
通过PHP -m或PHPinfo()来查看是否成功加载了swoole,如果没有可能是PHP.ini的路径不对,可以使用PHP -i |grep PHP.ini来定位到PHP.ini的绝对路径。
1. wget http://Nginx.org/download/Nginx-1.10.1.tar.gz
2. tar -zxvf Nginx-1.10.1.tar.gz
3. cd Nginx-1.10.1/
4 . /configure make && make install
5. cp /usr/local/Nginx/sbin/Nginx /usr/local/bin/Nginx
2. vim /etc/Nginx/sites-enabled/default
index index.html index.htm index.PHP;
location ~ \.PHP$ {
try_files $uri =404;
fastcgi_param SCRIPT_FILENAME /path$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
include fastcgi_params;
}
3. sudo Nginx 启动
sudo Nginx -s reload
1. cd /usr/local/PHP/etc/
sudo cp PHP-fpm.conf.default PHP-fpm.conf
2. cd /usr/local/PHP/etc/PHP-fpm.d/
sudo mv www.conf.default www.conf
3. cd /usr/local/PHP/var/log/
sudo chmod -R 777 PHP-fpm.log
sudo /usr/local/PHP/sbin/PHP-fmp 启动PHP-fpm
1. wget http://dev.MysqL.com/get/MysqL-apt-config_0.6.0-1_all.debsudo
2. dpkg -i MysqL-apt-config_0.6.0-1_all.deb
3. sudo apt-get update
4. sudo apt-get install MysqL-server-5.7
安装 Redis 3.2.1
1. wget http://download.redis.io/releases/redis-3.2.1.tar.gz
2. tar xzf redis-3.2.1.tar.gz
3. cd redis-3.2.1
4. make
5. make install
PHP7 安装redis扩展
1. wget -c https://github.com/PHPredis/PHPredis/archive/PHP7.zip
2. unzip PHP7.zip
3. cd PHPredis-PHP7
4. /usr/local/PHP/bin/PHPize
5. ./configure --with-PHP-config=/usr/local/PHP7/bin/PHP-config
6. make
7. make install
8. sudo vim /usr/local/PHP7/etc/PHP.ini
中加入extension=redis.so并重启PHP-fpm
@H_
502_56@
yaf 安装
1. wget http://pecl.PHP.net/get/yaf-3.0.2.tgz
2. tar -zxvf yaf-3.0.2.tgz
3. cd yaf-3.0.2/
4. /usr/local/PHP/bin/PHPize
5. ./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config
6. make
7. make test
8. sudo make install
9. sudo vim /usr/local/PHP7/etc/PHP.ini
中加入extension=yaf.so并重启PHP-fpm