centos下搭建nginx与php环境

yum install nginx
网页中打开自己服务器ip显示
centos下搭建nginx与php环境_第1张图片
表示成功
默认html在
cd /usr/share/nginx/html

##安装php
yum install php php-fpm
打开php
systemctl start php-fpm

##将php和mysql串联
可以通过yum install mariadh mariadb-server 安装
yum install php-gd php-mysql php-mbstring php-xml php-mcrypt php-imap php-odbc php-pear php -xmlrpc

##配置nginx与php一起工作:
Nginx+FastCGI运行原理
Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用。FastCGI接口在Linux下是socket,(这个socket可以是文件socket,也可以是ip socket)。为了调用CGI程序,还需要一个FastCGI的wrapper(wrapper可以理解为用于启动另一个程序的程序),这个wrapper绑定在某个固定socket上,如端口或者文件socket。当Nginx将CGI请求发送给这个socket的时候,通过FastCGI接口,wrapper接纳到请求,然后派生出一个新的线程,这个线程调用解释器或者外部程序处理脚本并读取返回数据;接着,wrapper再将返回的数据通过FastCGI接口,沿着固定的socket传递给Nginx;最后,Nginx将返回的数据发送给客户端,这就是Nginx+FastCGI的整个运作过程。

##nginx配置
vim /etc/nginx/nginx.conf

在http模块中添加配置:  
       location / {  
        root   /usr/share/nginx/html;  
           index  index.html index.htm index.php;  
        }  
location ~ \.php$ {  
           root           html;  
           fastcgi_pass   127.0.0.1:9000;  
           fastcgi_index  index.php;  
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  
           include        fastcgi_params;  
       }  
 

你可能感兴趣的:(默认)