首页 > 开发 > php > 正文

分享一个在mac下启动php环境的脚本

2016-05-18 18:39:36  来源:慕课网

  在mac上虽然搭建好了PHP环境,但发现启动灰常麻烦,所以就自己写了一个shell脚本,错误之处,麻烦大家给予指出。

#!/bin/sh
userID=$(id -u);
apc=$(pgrep httpd | wc -l);
msql=$(pgrep mysqld | wc -l);
if [[ $userID == 0 ]]; then
    case "$1" in
        "0" )
        if [[ $msql -eq 0 && $apc -eq 0 ]]; then
            apachectl start
            echo "Starting apache ...OK";
            echo $(/usr/local/mysql/support-files/mysql.server start) >> null;
            echo "Starting MySQL ...OK";
        else
            if [[ $apc -ne 0 ]]; then
                echo "apache已运行。。。";
            fi
            if [[ $msql -ne 0 ]]; then
                echo "MySQL已运行。。。";
            fi
        fi
        ;;
        "1" )
            if [[ $apc -ne 0 ]]; then
                apachectl stop
            fi
            if [[ $msql -ne 0 ]]; then
                /usr/local/mysql/support-files/mysql.server stop
            fi      
        ;;
        *)
        echo "参数不正确,0为启动,1为关闭";
    esac
else
    echo "请以ROOT运行脚本!";

fi   欢迎关注小忆的博客:http://www.smallyi.com