注:使用的是 mac
1、阿里云服务器 centos6.0+ 系统
2、安装 php + php-fpm
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64
yum install php56w-fpm
php -v # 查看 php 版本
service php-fpm status # 查看 php-fpm 状态
能成功显示相应信息则为成功:
3、安装 Nginx
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum -y install nginx
service nginx status # 查看 nginx 状态
能成功显示相应信息则为成功
注:可以设置 nginx php-fpm 开机启动
chkconfig php-fpm on
chkconfig nginx on
4、启动 nginx + php-fpm
service nginx start
service php-fpm start
find / -name nginx.conf # 找到 nginx 的配置文件
vi /etc/nginx/nginx.conf # 打开配置文件
可以看到,下面引入了其他的配置文件:
:q! # 退出查看
cd /etc/nginx/conf.d/ # 进入配置文件夹
ls # 查看目录下的所有文件,发现有一个默认配置文件
vi default.conf # 查看文件
注意:
1、服务器根目录地址:/usr/share/nginx/html
2、默认读取 index.html index.htm;
改为:index.html index.htm index.php;
3、放开 php 解析的的注释 : 去掉前面的 # 号
4、修改 php 地址为服务器地址 : html 改为 /usr/share/nginx/html
5、修改php 的解析地址: /scripts 改为 $document_root
i # 进入编辑模式
『进行修改』
按 esc
:wq # 保存并退出
下面为改好的文件内容:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
service nginx restart # 重启nginx
上面有查看到服务器根目录,进入:
cd /usr/share/nginx/html
vi test.php # 创建test.php 文件
i # 进入编辑模式
输入下面代码:
<?php phpinfo(); ?>
按esc # 退出编辑模式
:wq # 保存退出
访问域名/test.php,能看到php的相关信息则为成功
做为在线git仓库