三:安装php 7
1.安装扩展包:
#安装libiconv 依赖 [root@aliyun pro]#tar zxvf libiconv-1.14.tar.gz [root@aliyun pro]#patch -d libiconv-1.14 -p0 < libiconv-glibc-2.16.patch [root@aliyun pro]#cd libiconv-1.14/ [root@aliyun libiconv-1.14]#./configure --prefix=/usr/local [root@aliyun libiconv-1.14]#make && make install #安装curl [root@aliyun pro]#tar zxvf curl-7.50.3.tar.gz [root@aliyun pro]#cd curl-7.50.3 [root@aliyun curl-7.50.3]#./configure --prefix=/usr/local [root@aliyun curl-7.50.3]#make && make install #安装libmcrypt [root@aliyun pro]#tar zxvf libmcrypt-2.5.8.tar.gz [root@aliyun pro]#cd libmcrypt-2.5.8 [root@aliyun libmcrypt-2.5.8]#./configure [root@aliyun libmcrypt-2.5.8]#make && make install [root@aliyun libmcrypt-2.5.8]#ldconfig [root@aliyun libmcrypt-2.5.8]#cd libltdl [root@aliyun libltdl]#./configure --enable-ltdl-install [root@aliyun libltdl]#make && make install #安装 mhash [root@aliyun pro]#tar xzf mhash-0.9.9.9.tar.gz [root@aliyun pro]#cd mhash-0.9.9.9 [root@aliyun mhash-0.9.9.9]#./configure [root@aliyun mhash-0.9.9.9]#make && make install [root@aliyun pro]#echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf [root@aliyun pro]#ldconfig #安装 mcrypt [root@aliyun pro]#tar xzf mcrypt-2.6.8.tar.gz [root@aliyun pro]#cd mcrypt-2.6.8/ [root@aliyun mcrypt-2.6.8]#./configure [root@aliyun mcrypt-2.6.8]#make && make install [root@aliyun mcrypt-2.6.8]#ldconfig
2. php 5.6 就已经集成了zendopcache 做为缓存加速服务,如果要开启opcache 缓存加速,则加参数–enable-opcache 否则–disable-opcache (建议加上)
[root@aliyun pro]#useradd -M -s /sbin/nologin www [root@aliyun pro]# tar xxvf php-7.0.11.tar.gz [root@aliyun pro]# cd php-7.0.11/ [root@aliyun php-7.0.11]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc \ --with-config-file-scan-dir=/usr/local/php/etc/php.d \ --with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-opcache --disable-fileinfo \ --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \ --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \ --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif \ --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local --enable-mbregex \ --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl \ --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-intl --with-xsl \ --with-gettext --enable-zip --enable-soap --disable-ipv6 --disable-debug
#直接make 会出现报错:ext/xmlrpc/libxmlrpc/.libs/encodings.o: In function `convert': #需要在make的时候加上参数: ZEND_EXTRA_LIBS='-liconv' [root@aliyun php-7.0.11]#make ZEND_EXTRA_LIBS='-liconv' [root@aliyun php-7.0.11]#mdke install
3.添加服务脚本,设置php.ini
[root@aliyun php-7.0.11]#cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@aliyun php-7.0.11]#chkconfig --add php-fpm [root@aliyun php-7.0.11]#chkconfig php-fpm on [root@aliyun php-7.0.11]#cp php.ini-production /usr/local/php/etc/php.ini sed -i "s@^memory_limit.*@memory_limit = 128M@" /usr/local/php/etc/php.ini sed -i 's@^output_buffering =@output_buffering = On\noutput_buffering =@' /usr/local/php/etc/php.ini sed -i 's@^;cgi.fix_pathinfo.*@cgi.fix_pathinfo=0@' /usr/local/php/etc/php.ini sed -i 's@^short_open_tag = Off@short_open_tag = On@' /usr/local/php/etc/php.ini sed -i 's@^expose_php = On@expose_php = Off@' /usr/local/php/etc/php.ini sed -i 's@^request_order.*@request_order = "CGP"@' /usr/local/php/etc/php.ini sed -i 's@^;date.timezone.*@date.timezone = Asia/Shanghai@' /usr/local/php/etc/php.ini sed -i 's@^post_max_size.*@post_max_size = 100M@' /usr/local/php/etc/php.ini sed -i 's@^upload_max_filesize.*@upload_max_filesize = 50M@' /usr/local/php/etc/php.ini sed -i 's@^max_execution_time.*@max_execution_time = 600@' /usr/local/php/etc/php.ini sed -i 's@^;realpath_cache_size.*@realpath_cache_size = 2M@' /usr/local/php/etc/php.ini sed -i 's@^disable_functions.*@disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen@' /usr/local/php/etc/php.ini EOF
4.开启opcache 缓存
同样是在php.ini 中开启即可
[root@aliyun php-7.0.11]#vim /usr/local/php/etc/php.ini 找到[opcache]添加zend_extension 的路径 zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/opcache.so :wq 下面一些配置可以sed进行替换 sed -i 's@^;opcache.enable=0.*@opcache.enable=1@' /usr/local/php/etc/php.ini sed -i 's@^;opcache.enable_cli.*@opcache.enable_cli=1@' /usr/local/php/etc/php.ini sed -i 's@^;opcache.memory_consumption.*@opcache.memory_consumption=128@' /usr/local/php/etc/php.ini sed -i 's@^;opcache.interned_strings_buffer.*@opcache.interned_strings_buffer=8@' /usr/local/php/etc/php.ini sed -i 's@^;opcache.max_accelerated_files.*@opcache.max_accelerated_files=100000@' /usr/local/php/etc/php.ini sed -i 's@^;opcache.use_cwd.*@opcache.use_cwd=1@' /usr/local/php/etc/php.ini sed -i 's@^;opcache.validate_timestamps.*@opcache.validate_timestamps=1@' /usr/local/php/etc/php.ini sed -i 's@^;opcache.revalidate_freq.*@opcache.revalidate_freq=60@' /usr/local/php/etc/php.ini sed -i 's@^;opcache.save_comments.*@opcache.save_comments=0@' /usr/local/php/etc/php.ini sed -i 's@^;opcache.fast_shutdown.*@opcache.fast_shutdown=1@' /usr/local/php/etc/php.ini sed -i 's@^;opcache.consistency_checks.*@opcache.consistency_checks=0@' /usr/local/php/etc/php.ini
5.配置php-fpm.conf
配置文件有些长,就不贴上来了,请移步:https://github.com/cnyunwei/Linux/blob/master/conf/php-fpm.conf
6.启动php-fpm 服务,安装nginx
[root@aliyun php-7.0.11]#service php-fpm start [root@aliyun253 pro]# ll /dev/shm/ total 0 srw-rw-rw- 1 www www 0 Oct 16 22:10 php-cgi.sock
nginx的安装和设置相对较少,openssl 和pcre都是不需要单独安装的,配置nginx的时候指定对应的路径即可
[root@aliyun pro]#tar xzf pcre-8.39.tar.gz [root@aliyun pro]#tar xzf nginx-1.10.1.tar.gz [root@aliyun pro]#tar xzf openssl-1.0.2j.tar.gz [root@aliyun pro]#cd nginx-1.10.1 #说明,由于已经安装了tcmalloc 内存优化工具,所以在配置的时候加上--with-google_perftools_module 参数 [root@aliyun nginx-1.10.1]#./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module \ --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module \ --with-http_realip_module --with-http_flv_module --with-openssl=../openssl-1.0.2j \ --with-pcre=../pcre-8.39 --with-pcre-jit --with-google_perftools_module [root@aliyun nginx-1.10.1]#make && make install echo "export PATH=/usr/local/nginx/sbin:\$PATH" >> /etc/profile . /etc/profile
nginx系统服务文件可查看:https://github.com/cnyunwei/Linux/blob/master/Script/nginx_init
[root@aliyun pro]#chkconfig --add nginx [root@aliyun pro]#chkconfig nginx on
7.nginx 配置以及设置sock 方式调用php
nginx.conf 的配置文件有些长,就不贴上来了,请移步:https://github.com/cnyunwei/Linux/blob/master/conf/nginx.conf
...... location ~ [^/]\.php(/|$) { #fastcgi_pass remote_php_ip:9000; fastcgi_pass unix:/dev/shm/php-cgi.sock; #这里代表通过sock 方式连接php fastcgi_index index.php; include fastcgi.conf; } .......
配置完成可以使用命令进行检查,如果检查无误即可启动服务测试
[root@aliyun pro]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@aliyun pro]#service nginx start
测试opcache 缓存是否生效可以将该文件放到站点目录下,通过浏览器访问测试:
opc.php :https://github.com/cnyunwei/Linux/blob/master/conf/ocp.php
到此nginx+php7+MariaDB 10.1 就完成了,MariaDB的操作和MySQL几乎没什么区别,但性能上测试确实比MySQL更强。
更多nginx的设置等信息可以查看《nginx 配置反向代理》