#!/bin/bash
#For aliyun ECS (centos system)
#web server : nginx php-fpm mysql
#author xiaohui<xh.8326@gmail.com>
#version 1.0.0
if [ $# -lt 1 ]
then
echo "used: sh $0 site domain(as: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
NGXYUM="
[nginx]\nname=nginx repo\nbaseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/\ngpgcheck=0\nenabled=1\n
"
echo -e $NGXYUM > /etc/yum.repos.d/nginx.repo
yes | yum install nginx
# start web server
chkconfig nginx on
chkconfig mysqld on
chkconfig php-fpm on
# add site conf
NGXSERVER="
server\n
{\n
listen 80;\n
server_name ${SITENAME};\n
root ${WEBHTML}/${SITENAME};\n
index index.php index.html;\n
access_log /var/log/${SITENAME}.access.log main;\n
error_page 404 /404.html;\n
error_page 500 502 503 504 /50x.html;\n
location = /50x.html {\n
root /usr/share/nginx/html;\n
}\n
location / {\n
if (!-e \$request_filename) {\n
rewrite ^/.*\$ /index.php last;\n
}\n
}\n
location ~*\.(gif|jpg|png|js|css|ico|html|ico)$ {\n
expires 120d;\n
}\n
location ~ \.php\$ {\n
fastcgi_pass 127.0.0.1:9000;\n
fastcgi_index index.php;\n
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;\n
include fastcgi_params;\n
}\n
}\n
"
echo -e $NGXSERVER > /etc/nginx/conf.d/${SITENAME}".conf"
PHPTEST="
<?php \n
phpinfo();
"
mkdir ${WEBHTML}/${SITENAME}
echo -e ${PHPTEST} > ${WEBHTML}/${SITENAME}/index.php
/etc/init.d/mysqld start
/etc/init.d/php-fpm start
/etc/init.d/nginx start
-------------------------
集结各类场景实战经验,助你开发运维畅行无忧