在centos6.5 上通过yum安装nginx和php-fpm

来源:互联网 发布:哪款理财软件好 编辑:程序博客网 时间:2024/06/08 07:11

在centos6.5 上安装php5.6

第一步:配置yum源

追加CentOS 6.5的epel及remi源。

# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

以下是CentOS 7.0的源。

# yum install epel-release# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm


使用yum list命令查看可安装的包(Packege)。

# yum list --enablerepo=remi --enablerepo=remi-php56 | grep php


第二步:

安装Nginx

输入下列命令

yum install nginx 

如果你想在系统启动时自动运行nginx,输入下列命令:

chkconfig --level 345 nginx on 


第一次启动nginx,输入下列命令:

/etc/init.d/nginx start 


第三步:

安装 php5.6 ,php-fpm

安装PHP5.6

yum源配置好了,下一步就安装PHP5.6。

# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof 


用PHP命令查看版本。

复制代码
# php --versionPHP 5.6.0 (cli) (built: Sep  3 2014 19:51:31)Copyright (c) 1997-2014 The PHP GroupZend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans



单独安装php-fpm

安装php5.6版本下的php-fpm(不考虑版本情况下安装 输入下列命令:yum --enablerepo=remi install php php-fpm )

yum install --enablerepo=remi --enablerepo=remi-php56 php php-fpm 


如果你想在系统启动时自动运行php-fpm,输入下列命令:

chkconfig --level 345 php-fpm on


PHP仅安装了核心模块,你很可能需要安装其他的模块,比如MySQL、 XML、 GD等等,你可以输入下列命令:

yum --enablerepo=remi install php-gd php-mysql php-mbstring php-xml php-mcrypt 


第一次启动php-fpm,输入下列命令:

/etc/init.d/php-fpm restart 


配置PHP-FPM和Nginx,让他们一起工作


nginx的配置文件在/usr/local/nginx/conf/nginx.conf,输入下列命令编辑这个文件:

vi /usr/local/nginx/conf/nginx.conf


 server{      listen 80;      server_name  localhost;      root /var/www/html;......location ~ \.php$ {
        #root   html;
  fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME scripts$fastcgi_script_name; include fastcgi_params; }


}
如果这个scripts导致php文件File Not Found!
 fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;

第四步:

现在在/var/www/html目录下建立下列PHP文件index.php

文件内容如下:

<?php

phpinfo();

?>


访问:localhost/index.php


0 0
原创粉丝点击