开发者社区> 问答> 正文

云服务器(centos)安装webserver一步搞定

今天在群里发现一些用户不会安装centos 服务器的 WEB SERVER。

就随手写了一个脚本,一步搞定,由于时间关系没有做webserver性能上的优化,后面如果有其它的需求,我们在更新这个脚本。

安装上的webserver: nginx  php-fpm   mysql

使用:   sh aliyun_ecs_install_webserver.sh www.youdomain.com  
注:(www.youdomain.com是需要访问的域名)

安装后,如果你的域名指向安装服务器的IP,  就直接可以访问你的安装域名了,会输出phpinfo;

注: 一定要用root账号运行,不然不保证安装成功

sh 文件下载:   

广告一下啊,我的项目 邮大爷 https://www.youdaye.com

这是源代码:

#如果要修改web的目录,请修改:WEBHTML="/usr/share/nginx/html"

#!/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





展开
收起
ap8761d1w 2013-08-09 19:24:03 16256 0
8 条回答
写回答
取消 提交回答
  • 吸取积极的价值,增加自己的信任值。

    二十五史资源多多,曹雪芹立书的王熙凤的下场一样凄凉封建颠覆体系的结果!我曾用尽全力,所以不会遗憾。塑造区块链溯源二十五史工程项目资源研究:https://mp.weixin.qq.com/s/7x1MwwpLWUgR6t3V59qeAw

    2021-12-12 13:02:09
    赞同 展开评论 打赏
  • 必须加分  感谢分享
    2013-08-10 01:02:55
    赞同 展开评论 打赏
  • 回5楼好好的的帖子
    源代码都给你了,你还问安全吗。。。。

    -------------------------

    回4楼服务器之家的帖子
    sh 写的少,,第二次写,,麻烦牛人改下
    2013-08-09 21:10:51
    赞同 展开评论 打赏
  • 安全吗?
    2013-08-09 20:30:49
    赞同 展开评论 打赏
  • 看的真蛋疼


    多行文本写法

    cat >>/path/file<<EOF
    line1
    line2
    line3
    ... ...
    EOF
    2013-08-09 20:05:14
    赞同 展开评论 打赏
  • 感谢分享!
    2013-08-09 20:03:29
    赞同 展开评论 打赏
  • 多谢分享
    2013-08-09 19:28:36
    赞同 展开评论 打赏
  • 感谢分享
    2013-08-09 19:26:05
    赞同 展开评论 打赏
滑动查看更多
问答排行榜
最热
最新

相关电子书

更多
ECS成熟度评估&洞察 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载