安装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,不过阿里云已经提供了免费的数据库服务,何尝不用呢?
其实阿里云好像有自己的一键安装包,只是我自己爱折腾。
这个不错,下次换主机用得上!
官方说明: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.
我在centos上面安装,$releasever类似环境变量吧,centos可否也用变量代替呢
centos/$releasever,这个需要修改为你的系统名称和版本