帮助新手一键安装上webserver 之前发过贴,在大神们的指点下,修改了一下,看着不蛋疼
使用:
sh aliyun_ecs_install_webserver.sh www.youdaye.com
注:(www.youdomain.com是需要访问的域名)
安装后,如果你的域名指向安装服务器的IP, 就直接可以访问你的安装域名了,会输出phpinfo();
注: 一定要用root账号运行,不然不保证安装成功
。
#如果要修改web的目录,请修改:WEBHTML="/usr/share/nginx/html"
新建
aliyun_ecs_install_webserver.sh
拷贝代码
#!/bin/bash
#For aliyun ECS (centos system)
#version 1.0.0
if [ $# -lt 1 ]
then
echo "used: sh $0 youdomain.com";
exit 0;
fi
# you site domain
SITENAME=$1
# modify you domain path
# nginx default: /usr/share/nginx/html
WEBHTML="/usr/share/nginx/html"
# web server
# nginx + php-fpm + mysql
# 1 yum install mysql
yes | yum install mysql*
# 2 yum install php*
yes | yum install php*
# 3 yum install nginx
cat > /etc/yum.repos.d/nginx.repo <<EOF
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=0
enabled=1
EOF
yes | yum install nginx
# add server to chkconfig
chkconfig nginx on
chkconfig mysqld on
chkconfig php-fpm on
# add site config
cat > /etc/nginx/conf.d/${SITENAME}".conf" <<EOF
server
{
listen 80;
server_name ${SITENAME};
root ${WEBHTML}/${SITENAME};
index index.php index.html;
access_log /var/log/${SITENAME}.access.log main;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location / {
if (!-e \$request_filename) {
rewrite ^/.*$ /index.php last;
}
}
location ~*\.(gif|jpg|png|js|css|ico|html|ico)$ {
expires 120d;
}
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;
}
}
EOF
dirname=${WEBHTML}/${SITENAME}
if [ ! -d "$dirname" ];then
mkdir $dirname
fi
cat > $dirname/index.php <<EOF
<?php
phpinfo();
?>
EOF
/etc/init.d/mysqld start
/etc/init.d/php-fpm start
/etc/init.d/nginx start
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。