介绍Linux环境下PHP7.0安装
PHP7和HHVM比较
PHP7的在真实场景的性能确实已经和HHVM相当, 在一些场景甚至超过了HHVM。HHVM的运维复杂, 是多线程模型, 这就代表着如果一个线程导致crash了, 那么整个服务就挂了, 并且它不会自动重启。另外它采用JIT, 那么意味着, 重启以后要预热, 没有预热的情况下, 性能较为糟糕。并且多线程模型调试困难, 这对于追求稳定来说的Web服务来说, 是非常不适合的。
Nginx以及PHP7.0之前的版本可以参考此文:Linux环境Nginx安装与调试以及PHP安装
PHP7.0正式版已经在2015年11月份左右发布,目前是PHP7.0.2版本,本人最早是从2015年8月php7的第一个测试版跟起,现在正式版发布。
linux版本:64位CentOS 6.6
Nginx版本:nginx1.8.0
php版本:php-7.0.2
推荐(免费):PHP7
下载
wget http://php.net/get/php-7.0.2.tar.gz/from/a/mirror
建议安装之前先看看安装帮助文件INSTALL
解压安装
tar zxvf php-7.0.2.tar.gz
cd php-7.0.2
首先查看安装帮助
./configure --help
./configure --prefix=/usr/local/php
–with-curl
–with-freetype-dir
–with-gd
–with-gettext
–with-iconv-dir
–with-kerberos
–with-libdir=lib64
–with-libxml-dir
–with-mysqli
–with-openssl
–with-pcre-regex
–with-pdo-mysql
–with-pdo-sqlite
–with-pear
–with-png-dir
–with-xmlrpc
–with-xsl
–with-zlib
–enable-fpm
–enable-bcmath
–enable-libxml
–enable-inline-optimization
–enable-gd-native-ttf
–enable-mbregex
–enable-mbstring
–enable-opcache
–enable-pcntl
–enable-shmop
–enable-soap
–enable-sockets
–enable-sysvsem
–enable-xml
–enable-zip
如果配置错误,需要安装需要的模块,直接yum一并安装依赖库
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel
注意:安装php7beta3的时候有几处配置不过去,需要yum一下,现在php-7.0.2已经不用这样了。
yum -y install curl-devel
yum -y install libxslt-devel
编译安装
make && make install
配置文件
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
需要注意的是php7中www.conf这个配置文件配置phpfpm的端口号等信息,如果你修改默认的9000端口号需在这里改,再改nginx的配置
启动
/etc/init.d/php-fpm
查看phpinfo()
php7和php5性能分析比较
生成一个 60 万元素的数组,通过查找key 的方式,来确定key是否存在。
PHP 5.4.44 版
[root@localhost www5.4.44]# time /usr/local/php5.4.44/bin/php search_by_key.php
real 0m0.351s
user 0m0.300s
sys 0m0.050s
PHP 5.5.28 版
[root@localhost www]# time /usr/local/php/bin/php search_by_key.php
real 0m0.361s
user 0m0.304s
sys 0m0.057s
PHP 7.0.0 版
[root@localhost www7]# time /usr/local/php7/bin/php search_by_key.php
real 0m0.114s
user 0m0.097s
sys 0m0.017s
很明显php7的性能是php5的3倍!
配置opcache
官网地址:http://php.net/opcache
使用下列推荐设置来获得较好的 性能:
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
你也可以禁用 opcache.save_comments 并且启用 opcache.enable_file_override。 需要提醒的是,在生产环境中使用上述配置之前,必须经过严格测试。 因为上述配置存在一个已知问题,它会引发一些框架和应用的异常, 尤其是在存在文档使用了备注注解的时候。
vim /usr/local/php7/etc/php.ini
加入
zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20141001/opcache.so
重启
killall php-fpm
/etc/init.d/php-fpm
Opcache 状态测试代码(https://gist.github.com/ck-on/4959032)进行演示:
<?php /* OCP - Opcache Control Panel (aka Zend Optimizer+ Control Panel for PHP) Author: _ck_ (with contributions by GK, stasilok) Version: 0.1.6 Free for any kind of use or modification, I am not responsible for anything, please share your improvements * revision history 0.1.6 2013-04-12 moved meta to footer so graphs can be higher and reduce clutter 0.1.5 2013-04-12 added graphs to visualize cache state, please report any browser/style bugs 0.1.4 2013-04-09 added "recheck" to update files when using large revalidate_freq (or validate_timestamps=Off) 0.1.3 2013-03-30 show host and php version, can bookmark with hashtag ie. #statistics - needs new layout asap 0.1.2 2013-03-25 show optimization levels, number formatting, support for start_time in 7.0.2 0.1.1 2013-03-18 today Zend completely renamed Optimizer+ to OPcache, adjusted OCP to keep working 0.1.0 2013-03-17 added group/sort indicators, replaced "accelerator_" functions with "opcache_" 0.0.6 2013-03-16 transition support as Zend renames product and functions for PHP 5.5 (stasilok) 0.0.5 2013-03-10 added refresh button (GK) 0.0.4 2013-02-18 added file grouping and sorting (click on headers) - code needs cleanup but gets the job done 0.0.2 2013-02-14 first public release * known problems/limitations: Unlike APC, the Zend OPcache API - cannot determine when a file was put into the cache - cannot change settings on the fly - cannot protect opcache functions by restricting execution to only specific scripts/paths * todo: Extract variables for prefered ordering and better layout instead of just dumping into tables File list filter */ // ini_set('display_errors',1); error_reporting(-1); if ( count(get_included_files())>1 || php_sapi_name()=='cli' || empty($_SERVER['REMOTE_ADDR']) ) { die; } // weak block against indirect access $time=time(); define('CACHEPREFIX',function_exists('opcache_reset')?'opcache_':(function_exists('accelerator_reset')?'accelerator_':'')); if ( !empty($_GET['RESET']) ) { if ( function_exists(CACHEPREFIX.'reset') ) { call_user_func(CACHEPREFIX.'reset'); } header( 'Location: '.str_replace('?'.$_SERVER['QUERY_STRING'],'',$_SERVER['REQUEST_URI']) ); exit; } if ( !empty($_GET['RECHECK']) ) { if ( function_exists(CACHEPREFIX.'invalidate') ) { $recheck=trim($_GET['RECHECK']); $files=call_user_func(CACHEPREFIX.'get_status'); if (!empty($files['scripts'])) { foreach ($files['scripts'] as $file=>$value) { if ( $recheck==='1' || strpos($file,$recheck)===0 ) call_user_func(CACHEPREFIX.'invalidate',$file); } } header( 'Location: '.str_replace('?'.$_SERVER['QUERY_STRING'],'',$_SERVER['REQUEST_URI']) ); } else { echo 'Sorry, this feature requires Zend Opcache newer than April 8th 2013'; } exit; } ?>nbsp;html>
<p> </p><h1 id="a-Opcache-Control-Panel-a"><a>Opcache Control Panel</a></h1> <p> <a>Details</a> <a>Files</a> <a>Reset</a> <?php if ( function_exists(CACHEPREFIX.'invalidate') ) { ?> <a>Recheck</a> <?php } ?> <a>Refresh</a> </p> <?php if ( !function_exists(CACHEPREFIX.'get_status') ) { echo '<h2>Opcache not detected?'; die; } if ( !empty($_GET['FILES']) ) { echo '<h2 id="files-cached">files cached</h2>'; files_display(); echo '
以上是介绍Linux环境下PHP7.0安装的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

要打开 web.xml 文件,可以使用以下方法:使用文本编辑器(如记事本或 TextEdit)使用集成开发环境(如 Eclipse 或 NetBeans)使用命令行编辑命令(Windows:notepad web.xml;Mac/Linux:open -a TextEdit web.xml)

语言多线程可以大大提升程序效率,C 语言中多线程的实现方式主要有四种:创建独立进程:创建多个独立运行的进程,每个进程拥有自己的内存空间。伪多线程:在一个进程中创建多个执行流,这些执行流共享同一内存空间,并交替执行。多线程库:使用pthreads等多线程库创建和管理线程,提供了丰富的线程操作函数。协程:一种轻量级的多线程实现,将任务划分成小的子任务,轮流执行。

无法以 root 身份登录 MySQL 的原因主要在于权限问题、配置文件错误、密码不符、socket 文件问题或防火墙拦截。解决方法包括:检查配置文件中 bind-address 参数是否正确配置。查看 root 用户权限是否被修改或删除,并进行重置。验证密码是否准确无误,包括大小写和特殊字符。检查 socket 文件权限设置和路径。检查防火墙是否阻止了 MySQL 服务器的连接。

我开发了一个名为Lua-Libuv的项目,并乐于分享我的经验。项目初衷是探索如何利用Libuv(一个用C语言编写的异步I/O库)构建简单的HTTP服务器,而无需深入掌握C语言。借助ChatGPT的辅助,我完成了HTTP.C的基础代码。在处理持久连接时,我成功实现了在适当的时机关闭连接并释放资源。起初,我尝试创建一个简单的服务器,通过关闭连接来结束主程序,但遇到了一些问题。我尝试过使用流式传输发送数据块,虽然有效,但这会阻塞主线程。最终,我决定放弃这个方法,因为我的目标并非深入学习C语言。最终,我

C语言条件编译是一种根据编译时条件选择性编译代码块的机制,入门方法有:使用#if和#else指令根据条件选择代码块。常用条件表达式包括STDC、_WIN32和linux。实战案例:根据操作系统打印不同消息。根据系统位数使用不同的数据类型。根据编译器支持不同的头文件。条件编译增强了代码的可移植性和灵活性,使其适应编译器、操作系统和CPU架构变化。

1.0.1前言这个项目(包括代码和注释)是在我自学Rust的过程中记录的。可能有不准确或表述不清的地方,还请大家谅解。如果您从中受益,那就更好了。1.0.2为什么使用RustRust可靠且高效。Rust可以取代C和C,性能相似但安全性更高,并且不需要像C和C那样频繁重新编译来检查错误。主要优点包括:内存安全(防止空指针取消引用、悬空指针和数据争用)。线程安全(确保多线程代码在执行前是安全的)。避免未定义的行为(例如,数组越界、未初始化的变量或访问已释放的内存)。Rust提供现代语言功能(例如泛型

MySQL启动失败的原因有多种,可以通过检查错误日志进行诊断。常见原因包括端口冲突(检查端口占用情况并修改配置)、权限问题(检查服务运行用户权限)、配置文件错误(检查参数设置)、数据目录损坏(恢复数据或重建表空间)、InnoDB表空间问题(检查ibdata1文件)、插件加载失败(检查错误日志)。解决问题时应根据错误日志进行分析,找到问题的根源,并养成定期备份数据的习惯,以预防和解决问题。

C语言函数库是一个包含各种函数的工具箱,这些函数被组织在不同的库文件中。添加函数库需要通过编译器的命令行选项来指定,例如 GCC 编译器使用 -l 选项,后跟库名的缩写。如果库文件不在默认搜索路径下,则需要使用 -L 选项指定库文件路径。库有静态库和动态库之分,静态库在编译时直接链接到程序中,而动态库在运行时被加载。
