cat /etc/yum.repos.d/nginx.repo
添加或编辑nginx.repo
vi /etc/yum.repos.d/nginx.repo
[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/7/$basearch/gpgcheck=0enabled=1登入後複製
安装nginx
yum install epel-releaseyum install nginx
防火墙开启80端口
firewall-cmd --permanent --add-service=httpfirewall-cmd --permanent --zone=trusted --add-port=80/tcpfirewall-cmd --reload
安装必备的依赖
yum install -y \gcc-c++ autoconf \libjpeg libjpeg-devel libpng \libpng-devel freetype freetype-devel \libpng libpng-devel libxml2 libxml2-devel \zlib zlib-devel glibc glibc-devel \glib2 glib2-devel bzip2 bzip2-devel \ncurses curl openssl-devel \gdbm-devel db4-devel libXpm-devel \libX11-devel gd-devel gmp-devel \readline-devel libxslt-devel \expat-devel xmlrpc-c xmlrpc-c-devel \libicu-devel libmcrypt-devel \libmemcached-devel
下载php-7.0.7
cd /usr/src/wget http://cn2.php.net/distributions/php-7.0.7.tar.bz2tar -xjf php-7.0.7.tar.bz2mv php-7.0.7 php7cd /usr/src/php7
编译php
# 视情况增删参数,以下为一些常用的./configure --prefix=/usr/local/php7 \--with-mysql-sock --with-mysqli \--enable-fpm --enable-soap \--with-libxml-dir --with-openssl \--with-mcrypt --with-mhash \--with-pcre-regex --with-zlib \--enable-bcmath --with-iconv \--with-bz2 --enable-calendar \--with-curl --with-cdb --enable-dom \--enable-exif --enable-fileinfo \--enable-filter --with-pcre-dir \--enable-ftp --with-gd \--with-openssl-dir --with-jpeg-dir \--with-png-dir --with-zlib-dir \--with-freetype-dir \--enable-gd-native-ttf \--enable-gd-jis-conv --with-gettext \--with-gmp --with-mhash \--enable-json --enable-mbstring \--enable-mbregex \--enable-mbregex-backtrack \--with-libmbfl --with-onig \--enable-pdo --with-pdo-mysql \--with-zlib-dir --with-readline \--enable-session --enable-shmop \--enable-simplexml --enable-sockets \--enable-sysvmsg --enable-sysvsem \--enable-sysvshm --enable-wddx \--with-libxml-dir --with-xsl \--enable-zip \--enable-mysqlnd-compression-support \--with-pear --enable-intl --enable-pcntl
安装php
makemake install
测试是否安装成功
/usr/local/php7/bin/php -v
做软链,以便直接用php运行
ln -sf /usr/local/php7/bin/php /usr/local/bin/php
验证
php -v
复制配置文件
cp /usr/src/php7/php.ini-development /usr/local/php7/lib/php.ini
配置php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.confcp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.confcp /usr/src/php7/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod +x /etc/init.d/php-fpm
启动php-fpm
service php-fpm start
配置nginx
vi /etc/nginx/nginx.conf
在/etc/nginx/nginx.conf 的server块里面添加下面的配置,注意:server 中需添加root 配置,否则$document_root无效
root /www/;location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}登入後複製
重启nginx
service nginx restart
在web目录下新建一个php文件
echo '<?php phpinfo();' > /usr/share/nginx/html/info.php
浏览器访问验证
http://127.0.0.1/info.php
下载php-memcached,从github上下载,记住一定要选择对应的php7分支
cd /usr/srcgit clone https://github.com/php-memcached-dev/php-memcached.gitcd php-memcached/git checkout php7/usr/local/php7/bin/phpize./configure --with-php-config=/usr/local/php7/bin/php-configmakemake install
修改php.ini
vi /usr/local/php7/lib/php.ini#在最下面加上extension=memcached.so
保存并退出,重启php-fpm
service php-fpm start
再次访问info.php,就可以看到memcached已经安装成功了。
如有其它问题,请在下方留言^_^