search
Homephp教程php手册centos+nginx+php配置简介

centos+nginx+php配置简介

Jun 06, 2016 pm 07:49 PM
nginxIntroductionConfiguration

nginx默认是不能解析PHP的,要解析PHP需要修改nginx的配置文件。 打开nginx.conf, 找到location / 修改如下: location / { root /var/www; index index.php index.html index.htm; } 找到location ~ .php$,修改如下: location ~ .php$ { root /var/www;

nginx默认是不能解析PHP的,要解析PHP需要修改nginx的配置文件。

打开nginx.conf,

找到location / 修改如下:

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

找到location ~ .php$,修改如下:

location ~ .php$ {
root           /var/www;
fastcgi_pass   127.0.0.1:9001;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
include        fastcgi_params;
}

root:设置PHP脚本的根目录

fastcgi_pass:处理PHP脚本的端口,这里监听9001

fastcgi_index :索引文件

fastcgi_param:php脚本路径

设置完之后,还需要配置php-fpm.conf,进入你的php安装目录下的etc文件夹,将php-fpm.conf.default重命名为php-fpm.conf,双击打开,修改listen为9001。
启动终端,cd进入php安装目录的sbin文件夹,使用./php-fpm命令启动fpm,如果启动报错,打开php-fpm.conf,去掉如下语句前的注视,然后重启php-fpm
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500

配置nginx和php-fpm开机自启动:

打开/etc/rc.local,在末尾添加

ulimit -SHn 65535
/var/web/php/sbin/php-fpm
/var/web/nginx/sbin/nginx

保存文件,重启。

注意把/var/web/php和/var/web/nginx修改成你自己的php/nginx安装目录。

在var/www目录下新建index.php,写入代码:

phpinfo();

?>

访问:http://localhost,出现php配置信息界面,大功告成!
PS:手动启动nginx,打开终端,cd进入nginx的sbin目录,使用./nginx命令启动nginx

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.