1.安装php
安装包:php-5.6.20.tar.bz2
[root@server1 ~]#tar jxf php-5.6.20.tar.bz2 ##解压
2.进行源码编译:
[root@server1 ~]#cd php-5.6.20/ ##进入php源码包目录
[root@server1 ~]#./configure --prefix=/usr/local/lnmp/php--with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp--with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir--with-jpeg-dir --with-freetype-dir --with-gmp --with-gettext--enable-inline-optimization --enable-soap --enable-ftp --enable-sockets--enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash
php在安装过程中有很多依赖性,只要根据提示信息,把需要的依赖包逐个安装,最后即可成功编译。
下面这些依赖包是我在编译过程中安装的:
yum install libxml2-devel -y
yum install -y curl-devel
yum install -y freetype-devel
yum installlibmcrypt-devel-2.5.8-9.el6.x86_64.rpm libmcrypt-2.5.8-9.el6.x86_64.rpm -y
yum install -y net-snmp-devel
yum install -y bison
yum install -y re2c-0.13.5-1.el6.x86_64.rpm
如果实在是不知道需要装的包名可以用命令查找:yum provides */X ##x表示报错信息提示
yum install libxml2-devel -y
yum install -y curl-devel
yum install -y freetype-devel
yum installlibmcrypt-devel-2.5.8-9.el6.x86_64.rpm libmcrypt-2.5.8-9.el6.x86_64.rpm
yum install -y net-snmp-devel
yum install -y bison
yum install -y re2c-0.13.5-1.el6.x86_64.rpm
[root@server1 ~]#cd php-5.6.20 ##进入php目录下
cp php.ini-production /usr/local/lnmp/php/etc/php.ini ##拷贝文件
##设置php-fpm开机启动
cd sapi/fpm/
cp init.d.php-fpm /etc/init.d/php-fpm ##更改php的启动文件为/etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm ##给php-fpm的执行权
[root@server1 ~]# cd /usr/local/lnmp/php/etc/ ##进入etc目录下
[root@server1 ~]# vim php.ini ##编辑配置文件
做如下修改:
924 [Date]
925 ; Defines the default timezone used by the date functions
926 ; http://php.NET/date.timezone
927 date.timezone = Asia/Shanghai ##更改时区为Asia/Shanghai
[root@server1 ~]# cp php-fpm.conf.default php-fpm.conf ##更改php的配置文件名为php-fpm.conf
vim php-fpm.conf
25 pid = run/php-fpm.pid ##取消此行前面原来的分号
/etc/init.d/php-fpm start ##启动php服务
[root@server1 ~]# cd /usr/local/lnmp/php/
vim ~/.bash_profile ##把php服务加入系统环境变量
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin
source ~/.bash_profile ##使配置立即生效
[root@server1 ~]# cd /usr/local/lnmp/nginx/conf/
vim nginx.conf
51 location / {
52 root html;
53 index index.php index.html index.htm;---->加入php默认发布页面
54 }
80 location ~ \.php$ {
81 root html;
82 fastcgi_pass 127.0.0.1:9000;
83 fastcgi_index index.php;
84 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
85 include fastcgi.conf;--->更改路径
86 }
nginx -t
nginx
cd /usr/local/lnmp/nginx/html/
vim index.php
<?php
phpinfo()
?>
访问:172.25.90.1
可以看到php的首页。