1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
#下载地址 http://www.php.net/downloads.php #如果编译不通过,可以安装以下工具(选择性安装) sudo yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel \ libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \ glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel\ e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel \ openldap openldap-devel nss_ldap openldap-clients openldap-servers \ php-mysqlnd libmcrypt-devel libtidy libtidy-devel recode recode-devel libxpm-devel #编译参数 ./configure \ --prefix=/usr/local/php7 \ --with-config-file-path=/usr/local/php7/etc \ --enable-mbstring \ --enable-zip \ --enable-bcmath \ --enable-pcntl \ --enable-ftp \ --enable-exif \ --enable-calendar \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-opcache \ --enable-fpm \ --enable-session \ --enable-sockets \ --enable-mbregex \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-wddx \ --with-curl \ --with-mcrypt \ --with-iconv \ --with-gd \ --with-jpeg-dir=/usr \ --with-png-dir=/usr \ --with-zlib-dir=/usr \ --with-freetype-dir=/usr \ --enable-gd-native-ttf \ --enable-gd-jis-conv \ --with-openssl \ --with-pdo-mysql=mysqlnd \ --with-gettext=/usr \ --with-zlib=/usr \ --with-bz2=/usr \ --with-recode=/usr \ --with-xmlrpc \ --with-mysqli=mysqlnd #配置文件 sudo cp php.ini-production /usr/local/php7/etc/php.ini sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm sudo cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf sudo cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf #增加启动脚本的权限 sudo chmod +x /etc/init.d/php7-fpm #做一些软链 ln -s /usr/local/php7/bin/php /usr/bin/php7 ln -s /usr/local/php7/bin/php-config /usr/bin/php7-config ln -s /usr/local/php7/bin/phpize /usr/bin/php7ize ln -s /usr/local/php7/sbin/php-fpm /usr/sbin/php7-fpm #nginx中找到fastcgi_pass的位置 fastcgi_pass unix:/tmp/php-cgi.sock; #复制php5的php-fpm.conf [global] pid = /usr/local/php/var/run/php-fpm.pid error_log = /usr/local/php/var/log/php-fpm.log log_level = notice [www] listen = /tmp/php-cgi.sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = dynamic pm.max_children = 40 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 6 request_terminate_timeout = 100 request_slowlog_timeout = 0 slowlog = var/log/slow.log catch_workers_output = yes |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#1.使用GCC 4.8以上编译器 #GCC 4.8以上PHP才会开启Global Register for opline and execute_data支持, 这个会带来5%左右的性能提升 #2.开启opcache zend_extension=opcache.so opcache.enable=1 opcache.enable_cli=1 #3.开启HugePages #在系统中开启HugePages sysctl vm.nr_hugepages=512 /proc/meminfo | grep Huge #然后开启Opcache的huge_code_pages opcache.huge_code_pages=1 #4.开启Opcache File Cache(实验性) #通过开启这个, 我们可以让Opcache把opcode缓存缓存到外部文件中, 对于一些脚本, 会有很明显的性能提升 opcache.file_cache=/tmp #这样PHP就会在/tmp目录下Cache一些Opcode的二进制导出文件, 可以跨PHP生命周期存在 #5.开启PGO针对性优化(可选) #以wordpress 4.1为优化场景.. 首先在编译PHP的时候首先 make prof-gen #然后用你的项目训练PHP, 比如对于Wordpress sapi/cgi/php-cgi -T 100 /home/huixinchen/local/www/htdocs/wordpress/index.php >/dev/null #也就是让php-cgi跑100遍wordpress的首页, 从而生成一些在这个过程中的profile信息,最后: make prof-clean make prof-use && make install |