PHP + Nginx


Nginx

文件准备

cd /usr/local/

tar zxvf nginx-x.x.x.tar.gz

cd nginx-x.x.x

简单安装

./configure

make

make install

启动 

nginx

其他

nginx -h


PHP

获取并解压 PHP 源代码

tar zxf php-x.x.x


配置并构建 PHP

在此步骤您可以使用很多选项自定义 PHP,例如启用某些扩展等。 运行 ./configure --help 命令来获得完整的可用选项清单。 在本示例中,我们仅进行包含 PHP-FPM 和 MySQL 支持的简单配置。

cd ../php-x.x.x
./configure --enable-fpm --with-mysql
make
sudo make install


创建配置文件,并将其复制到正确的位置

cp php.ini-development /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf


修改 php-fpm.conf 配置文件

在启动服务之前,需要修改 php-fpm.conf 配置文件,确保 php-fpm 模块使用 www-data 用户和 www-data 用户组的身份运行。

vim /usr/local/etc/php-fpm.conf

找到以下内容并修改:

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = www-data
group = www-data

然后启动 php-fpm 服务:

php-fpm

本文档未涵盖对 php-fpm 进行进一步配置的信息,如果您需要更多信息,请查阅相关文档。


配置 Nginx 使其支持 PHP 应用

vim /usr/local/nginx/conf/nginx.conf

修改默认的 location 块,使其支持 .php 文件:

location / {
    root   html;
    index  index.php index.html index.htm;
}

下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改为下面的内容:

location ~* \.php$ {
    fastcgi_index   index.php;
    fastcgi_pass    127.0.0.1:9000;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
}


重启 Nginx

sudo nginx -s stop
sudo nginx

测试

rm /usr/local/nginx/html/index.html
echo "<?php phpinfo(); ?>" >> /usr/local/nginx/html/index.php

打开浏览器,访问 http://localhost


其他

wordpress忘记登陆密码

1. 先检车 wp_users 数据库表中是否有用户,没有则添加,ID一般为 1 。

2. 编辑 wp-includes/user.php 找到 wp_check_password ,把if条件判断相关几行注释掉。登陆之后修改密码,再打开注释。


wordpress 删除修改插件需要FTP

在 wp-config.php 最后新增 下面的代码

if(is_admin()) {
        add_filter('filesystem_method', create_function('$a','return "direct";' ));
        define('FS_CHMOD_DIR', 0751);
}


官方文档

本文对PHP的安装部分稍有省略,详见官网文档。

PHP + Nginx 官方安装:http://php.net/manual/zh/install.unix.nginx.php

你可能感兴趣的:(PHP + Nginx)