#!/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
集结各类场景实战经验,助你开发运维畅行无忧