frederichchen

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1. 首先安装nginx apache php php-apache php-fpm php-cgi php-gd php-mcrypt php-pgsql php-sqlite等软件包。

2. 编辑apache的配置文件/etc/httpd/conf/httpd.conf,将
    LoadModule mpm_event_module modules/mod_mpm_event.so   一行替换成 
    LoadModule mpm_prefork_module modules/mod_mpm_prefork.so ,否则apache启动会报如下的错:
    Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.  You need to recompile PHP.
    然后在LoadModule dir_module modules/mod_dir.so之后的任意一行加入
    LoadModule php5_module modules/libphp5.so,如果需要是用php-fpm则不做这步;
    最后在Include的最后面加入 Include conf/extra/php5_module.conf 。
3. 编辑/etc/php/php.ini,首先设置 date.timezone=Asia/Chongqing ,然后设置 open_basedir= 一行,把自己想要的目录加进去(比如我的apache根目录/srv/http以及nginx的根目录/srv/nginx,最后把一些需要的extension前面的分号去掉。
4. 编辑/etc/httpd/conf/extra/php5_module.conf,加入在DirectoryIndex一行中加入index.phtml,例如:
    DirectoryIndex index.php index.phtml index.html 
5. 按照上面的设置已经可以让apache解析PHP了,如果要使用php-fpm的话,删除刚才加入的 LoadModule php5_module modules/libphp5.so ,在/etc/httpd/conf/httpd.conf的末尾加入:
<FilesMatch \.php$>
    SetHandler "proxy:unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

    然后 systemctl restart httpd.service php-fpm.service 重启服务即可。

6. 编辑/etc/nginx/nginx.conf,首先把user一行改成 user http http ,然后修改server一栏如下:

server {
    listen       80;
    server_name  localhost;
    root /srv/nginx;
    location / {
        index  index.html index.htm index.php;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
}    

    然后 systemctl restart nginx.service php-fpm.service 重启服务即可。

posted on 2015-05-22 15:01  frederichchen  阅读(1807)  评论(0编辑  收藏  举报