centos6.10 php-5.6.37安装
centos6.10 php-5.6.37安装
一、下载php-5.6.37.tar.gz
window下载:http://php.net/downloads.php
linux下载:wget $url
$url 怎么获取? ---> 在Windows中用浏览器打开http://php.net/downloads.php选择对应的版本下载,然后打开浏览器的下载列表,在里面查看下载的url
[root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.37.tar.gz
二、解压【到指定目录】
[root@localhost src]# tar zxvf php-5.6.37.tar.gz -C /usr/local/webserver
三、环境准备【安装相应的依赖】
[root@localhost src]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel
四、编译,安装PHP
[root@localhost src]# cd /usr/local/webserver/php-5.6.37 下面一行,红色的为必须,其他的根据需要考虑下
--prefix 指定安装目录,不写的话按默认安装
--enable-fpm 启动php-fpm [root@localhost php-5.6.37]# ./configure --prefix=/usr/local/webserver/php5637 --with-gd --with-zlib --with-mysql --enable-mbstring --enable-fpm 这是一个漫长的过程【所以过程省略了】,下面是结果 +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands
[root@localhost php-5.6.37]# make
这是一个漫长的过程,太长省略了,下面结果 Generating phar.php Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. clicommand.inc directorytreeiterator.inc invertedregexiterator.inc directorygraphiterator.inc pharcommand.inc phar.inc Build complete. Don't forget to run 'make test'.
[root@localhost php-5.6.37]# make install 过程太长省略了,下面结果 Installing shared extensions: /usr/local/webserver/php5637/lib/php/extensions/no-debug-non-zts-20131226/ Installing PHP CLI binary: /usr/local/webserver/php5637/bin/ Installing PHP CLI man page: /usr/local/webserver/php5637/php/man/man1/ Installing PHP CGI binary: /usr/local/webserver/php5637/bin/ Installing PHP CGI man page: /usr/local/webserver/php5637/php/man/man1/ Installing build environment: /usr/local/webserver/php5637/lib/php/build/ Installing header files: /usr/local/webserver/php5637/include/php/ Installing helper programs: /usr/local/webserver/php5637/bin/ program: phpize program: php-config Installing man pages: /usr/local/webserver/php5637/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/webserver/php5637/lib/php/ [PEAR] Archive_Tar - installed: 1.3.12 [PEAR] Console_Getopt - installed: 1.3.1 [PEAR] Structures_Graph- installed: 1.0.4 [PEAR] XML_Util - installed: 1.2.3 [PEAR] PEAR - installed: 1.9.5 Wrote PEAR system config file at:/usr/local/webserver/php5637/etc/pear.conf You may want to add: /usr/etc/php/lib/php to your php.ini include_path /usr/local/webserver/php5637/build/shtool install -c ext/phar/phar.phar /usr/local/webserver/php55637/bin ln -s -f phar.phar /usr/local/webserver/php5637/bin/phar Installing PDO headers:/usr/local/webserver/php5637/include/php/ext/pdo/
到此编译安装完毕,不过还需要进行相关的配置
五、配置PHP
1、从解压包中复制php.ini到php的安装目录下的etc目录下
[看你自己的情况是选择复制php.ini-development 还是 php.ini-product]
[root@localhost php-5.6.37]# pwd /usr/local/webserver/php-5.6.37 [root@localhost php-5.6.37]# ll | grep php.ini -rw-r--r--. 1 1000 1000 73654 7月 19 23:01 php.ini-development -rw-r--r--. 1 1000 1000 73685 7月 19 23:01 php.ini-production
[root@localhost php-5.6.37]# cp php.ini-development /usr/local/webserver/php5637/etc/php.ini [root@localhost php-5.6.37]# cd /usr/local/webserver/php5637/etc [root@localhost etc]# ll 总用量 100 -rw-r--r--. 1 root root 1387 8月 5 18:39 pear.conf -rw-r--r--. 1 root root 23155 8月 5 18:56 php-fpm.conf.default -rw-r--r--. 1 root root 73654 8月 5 18:58 php.ini
2、配置php-fpm,启动php-fpm服务,配置开机启动
[root@localhost etc]#pwd
/usr/local/webserver/php5637/etc
[root@localhost etc]#cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# vim php-fpm.conf ;;;;;;;;;;;;;;;;;; ; Global Options ; ;;;;;;;;;;;;;;;;;; [global] ; Pid file ; Note: the default prefix is /usr/local/webserver/php5637/var ; Default Value: none pid = run/php-fpm.pid ; will be used. ;下面的这个你可以看着配置一下 user = nobody group = nobody
[root@localhost etc]#cd /usr/local/webserver/php-5.6.37 [root@localhost php-5.6.37]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@localhost php-5.6.37]# chmod +x /etc/init.d/php-fpm [root@localhost php-5.6.37]# chkconfig --add php-fpm [root@localhost php-5.6.37]# chkconfig php-fpm on [root@localhost php-5.6.37]# service php-fpm start
3、配置 nginx 支持 php 环境
进入nginx安装目录 下的conf目录的nginx.conf文件
[root@localhost conf]# vim nginx.conf
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
进入nginx安装目录下的sbin目录下,判断nginx配置文件是否正确
[root@localhost sbin]#./nginx -t nginx: the configuration file /usr/local/webserver/ngin/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/webserver/ngin/conf/nginx.conf test is successful
;重启动nginx,使配置生效
[root@localhost sbin]#./nginx -s restart
[4、环境变量,可选配置]
CentOS系统下如何将PHP命令加入到环境变量中?
在Linux CentOS系统上 安装完php和MySQL后,为了使用方便,需要将php和mysql命令加到系统命令中,如果在没有添加到环境变量之前,执行“php -v”命令查看当前php版本信息时时,则会提示命令不存在的错误,下面我们详细介绍一下在linux下将php和mysql加入到环境变量中的方法(假 设php和mysql分别安装在/usr/local/webserver/php/和/usr/local/webserver/mysql/中)。
方法一:直接运行命令export PATH=$PATH:/usr/local/webserver/php/bin 和 export PATH=$PATH:/usr/local/webserver/mysql/bin
使用这种方法,只会对当前会话有效,也就是说每当登出或注销系统以后,PATH 设置就会失效,只是临时生效。
方法二:执行vi ~/.bash_profile修改文件中PATH一行,将/usr/local/webserver/php/bin 和 /usr/local/webserver/mysql/bin 加入到PATH=$PATH:$HOME/bin一行之后
这种方法只对当前登录用户生效
方法三:修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码
PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin
export PATH
最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。
# vim /etc/profile PATH=$PATH:/usr/local/php/bin export PATH # source /etc/profile
六、测试
略
下载