代码拉取完成,页面将自动刷新
#!/bin/bash
# 安装相关软件包
yum -y install mariadb mariadb-devel mariadb-server \
php php-fpm php-mysql &> /dev/null
if [ `echo $?` -ne 0 ];then
echo -e "\033[5;31m请检查yum仓库是否配置正确!!\033[0m" && exit
fi
systemctl start php-fpm
systemctl start mariadb
ss -antulp | grep 3306 &> /dev/null
if [ $(echo $?) != 0 ];then
echo -e "\033[5;31m请检查mariadb服务!!\033[0m" && exit
fi
ss -antulp | grep php-fpm &> /dev/null
if test `echo $?` -ne 0;then
echo -e "\033[5;31m请检查php-fpm!!\033[0m" && exit
fi
# 创建动态测试页面
echo "<html>
<body>
This is HTML message
</br>
<?php
\$c = 12;
\$d = 2;
if(\$c > \$d){echo 'c is bigger';}
else{ echo 'd is bigger';}
?>
</body>
</html>" > /usr/local/nginx/html/test.php
cd /usr/local/nginx
# 重置配置文件
\cp conf/nginx.conf.default conf/nginx.conf
# 开启动态页面配置
sed -i '65,68s/#//' conf/nginx.conf
sed -i '70,71s/#//' conf/nginx.conf
sed -i '70s/_params/.conf/' conf/nginx.conf
ss -antulp | grep nginx &> /dev/null
if [ `echo $?` -ne 0 ];then
user=`ss -antulp | grep 80 | awk -F\" 'NR==1{print $2}'`
killall $user &> /dev/null
sleep 1 # 防止进程没被终止完全 启服务报错
sbin/nginx
else
sbin/nginx -s reload # 重新加载配置文件
fi
sleep 1
echo -e "\033[32m==============================================\033[0m"
curl http://127.0.0.1/test.php
echo -e "\033[32m==============================================\033[0m"
echo -e "\033[32mnginx已经支持php静态页面!!\033[0m"
# 测试有数据库的动态页面
echo '<?php
$mysqli = new mysqli("localhost","root","","mysql");
if (mysqli_connect_errno()){
die("Unable to connect!"). mysqli_connect_error();
}
$sql = "select * from user";
$result = $mysqli->query($sql);
while($row = $result->fetch_array()){
printf("Host:%s",$row[0]);
printf("</br>");
printf("Name:%s",$row[1]);
printf("</br>");
}
?>' > html/mysql.php
mysql -e "create user dcc@localhost identified by '123'" # 创建测试账户
curl http://127.0.0.1/mysql.php
echo ""
sleep 0.5
echo -e "\033[32m==============================================\033[0m"
echo -e "\033[32mnginx已经支持php动态页面!!\033[0m"
sleep 1
echo -e "\033[32mnginx已实现动静分离!!\033[0m"
# 注意 更好的效果请用浏览器访问 http://虚拟机IP/test.php http://虚拟机IP/mysql.php
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。