乌徒帮技术范儿技术中心服务器配置 › 阿里云安装NGINX+PHP

阿里云安装NGINX+PHP

分类:服务器配置 标签:,

安装nginx

第一步:vi /etc/yum.repos.d/nginx.repo

nginx.repo本身是没有的,通过vi创建这个文件。文件 nginx.repo 的内容是:

[nginx]
name=nginx?repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

第二步:使用命令 yum install nginx ,按照提示即可安装完毕;
第三步:使用命令 /etc/init.d/nginx start? 启动nginx服务;
第四步:测试,在浏览器里输入服务器ip地址,即可出现 nginx 欢迎页面

重启nginx命令:

service nginx restart;
nginx -s reload;

安装PHP

很简单,只需要一个命令即可:

yum -y install php php-cli php-common php-fpm php-gd php-imap php-ldap php-mbstring php-snmp php-xml php-mysql

修改配置

这里主要需要修改nginx的初始配置【这里是最难的,之后的很多工作都需要你来学习】

1. 开启对PHP的支持

>vi /etc/nginx/config.d/default.conf

# 按照下方的进行修改,注意,尽可能的保持一些出现的顺序和关键性语句
server {
    listen       80;
    server_name  localhost;
    root   /usr/share/nginx/html;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    #索引
    location / {
        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$ {
        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;
    #}
}

2. 配置一个初始的虚拟主机,主要是在上面这个default.conf中修改 root 后面的文件夹地址

启动服务

>service nginx start
>service php-fpm start

设置开机自动启动

chkconfig nginx on
chkconfig php-fpm on

这样一来主机基本就配置完成了,当然了,你还需要mysql,不过阿里云已经提供了免费的数据库服务,何尝不用呢?

已有5条评论 快速评论
  1. 否子戈 #4397楼 回复给@4395楼 2014/10/27 09:52:58 回复

    其实阿里云好像有自己的一键安装包,只是我自己爱折腾。

  2. 免费部落 #4395楼 2014/10/27 07:59:26 回复

    这个不错,下次换主机用得上!

  3. dexu.xie's blog #4271楼 回复给@4270楼 2014/03/07 20:19:39 回复

    官方说明:Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “5” or “6”, for 5.x or 6.x versions, respectively.

  4. frustigor #4270楼 回复给@4269楼 2014/03/06 22:36:05 回复

    我在centos上面安装,$releasever类似环境变量吧,centos可否也用变量代替呢

  5. dexu.xie's blog #4269楼 2014/03/06 21:56:21 回复

    centos/$releasever,这个需要修改为你的系统名称和版本

填写个人信息,赶快回复吧!