linux安装配置php

安装php前需要安装很多依赖包, http://mirrors.sohu.com/php/这里有php各版本,我这里选择php-5.6.29.tar.xz
一、安装依赖包
yum install -y make gcc automake vim wget unzip curl-devel zlib-devel tk zlib-devel openssl-devel perl cpio expat-devel gettext-devel perl-ExtUtils-MakeMaker package zsh bzip2

php
yum install  -y libxml2-devel libjpeg-devel libpng-devel libgif-devel freetype-devel autoconf curl-devel

wget http://www.atomicorp.com/installers/atomic
sh ./atomic
yum -y  install  php-mcrypt  libmcrypt  libmcrypt-devel



使用iconv命令将文档的编码进行转换即可。

iconv默认情况下,是没有被安装的,下面简单介绍下iconv的安装过程:
1.  下载
http://www.gnu.org/software/libiconv/#TOCdownloading

2. 安装:
下载完成后,切换到下载目录先进行解压:
  1. $tar -xzvf libiconv-1.14.tar.gz  
然后进入解压后的文件中
  1. $cd libiconv-1.14_2  
查看其中的README文件,我们可以看到安装步骤:(当然,如果您熟悉 源码 的安装,这步完全可以省略^-^)

  1. $ ./configure --prefix=/usr/local  
  2. $ make  
  3. $ make install  
3. 命令学习
该工具安装完成后,肯定要先了解下这个命令的用法吧,这个没什么可说的:

  1. $iconv --help  
我们会看到下面的内容:

  1. Usage: iconv [OPTION...] [FILE...]  
  2. Convert encoding of given files from one encoding to another.  
  3.   
  4.  Input/Output format specification:  
  5.   -f, --from-code=NAME       encoding of original text  
  6.   -t, --to-code=NAME         encoding for output  
  7.   
  8.  Information:  
  9.   -l, --list                 list all known coded character sets  
  10.   
  11.  Output control:  
  12.   -c                         omit invalid characters from output  
  13.   -o, --output=FILE          output file  
  14.   -s, --silent               suppress warnings  
  15.       --verbose              print progress information  
  16.   
  17.   -?, --help                 Give this help list  
  18.       --usage                Give a short usage message  
  19.   -V, --version              Print program version  
  20.   
  21. Mandatory or optional arguments to long options are also mandatory or optional  
  22. for any corresponding short options.  
说的很明白,就是按照下面的格式进行转换:
iconv -f 原编码 -t 目标编码 要转换的文件

4. 编码转换:
学会了编码的转化,我们就举了例子示范一下:

  1. $iconv -f gbk -t utf8 test.txt  

  1. <span style="font-family: 宋体; font-size: 14px;">执行下面的命令:</span>  

  1. $iconv -f gbk -t utf8 test.txt > test.convert.txt  

此时我们打开这个test.convert.txt文件就会发现,原来的中文显示正常了^-^

注意:
如果不出意外的话,上面的安装步骤可没有那么顺利,在make的时候,会提示下面的错误:

  1. n file included from progname.c:26:0:  
  2. ./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)  
  3.  _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");  
  4.  ^  
  5. make[2]: *** [progname.o] Error 1  
  6. make[2]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib'  
  7. make[1]: *** [all] Error 2  
  8. make[1]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib'  
  9. make: *** [all] Error 2  
这个这个软件本身存在的一个Bug,通过Google,发现一个解决该问题的补丁,内容如下:

  1. --- srclib/stdio.in.h.orig      2011-08-07 16:42:06.000000000 +0300  
  2. +++ srclib/stdio.in.h   2013-01-10 15:53:03.000000000 +0200  
  3. @@ -695,7 +695,9 @@  
  4.  /* It is very rare that the developer ever has full control of stdin, 
  5.     so any use of gets warrants an unconditional warning.  Assume it is 
  6.     always declared, since it is required by C89.  */  
  7. -_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");  
  8. +#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)  
  9. + _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");  
  10. +#endif  
  11.  #endif  
PS:内容中的"+"表示新增的内容,"-"表示删除的内容!

那我们只要进行如下操作即可解决这个问题:
1. 切换到srclib目录下:

  1. $cd srclib  

2. 修改stdio.in.h文件:

  1. $gedit stdio.in.h  

通过搜索,定位到_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");这一行,然后在这一行的前后加上条件编译即可,修改后的内容如下:

  1. #if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)  
  2.         _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");  
  3. #endif  
3. 保存退出,然后再进行make, make install便可顺利安装^-^
 
至此,php依赖包都已经安装OK,接下来安装php

二、安装php

./configure  --prefix=/usr/local/webserver/php5.6.29 --with-config-file-path=/usr/local/webserver/php5.6.29/etc --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd  --with-mysqli --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-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --enable-ftp --disable-ipv6 --enable-mysqlnd --disable-debug

make && make install

三、配置php    注:php和nginx是相互独立的两个应用,如果通信需要php-fpm连接使用

cd /usr/local/webserver/php5.6.29/etc
cp php-fpm.conf.default php-fpm.conf
/usr/local/webserver/php5.6.29/sbin/php-fpm -t  
/usr/local/webserver/php5.6.29/sbin/php-fpm  (如果没有报错,说明启动成功,端口是9000 )

四、php-fpm的启动,关闭和重启命令

启动:/usr/local/webserver/php5.6.29/sbin/php-fpm
关闭:kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
重启:kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

也可以通过ps -ef|grep php-fpm找到进程号,然后直接kill

四、配置nginx,在nginx.conf的69行前后,需要做修改,如下代码,$document_root前是$scripts,会提示找不到路径,需要将默认scripts改成document_root
# 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;
        }

五、测试,在nginx当前目录的html文件下面新建index.php文件,如下
<?php
        echo phpinfo();
?>

输入http://ip/index.php,如果能看到页面说明正常!














  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值