简介
一说到命令行,我们真正指的是 shell
。shell
就是一个程序,它接受从键盘输入的命令, 然后把命令传递给操作系统去执行。几乎所有的 Linux
发行版都提供一个名为 bash
的 来自 GNU 项目的 shell
程序。bash
是 Bourne Again SHell
的首字母缩写, 所指的是这样一个事实,bash
是最初 Unix
上由 Steve Bourne
写成 shell
程序 sh
的增强版。
编写 shell 脚本
将下面你的 shell
脚本保存在 .sh
的文件中。放在本地虚拟机上直接运行就行了。
前提虚拟机必须是CentOS7, 并且能连上外网。
#!/bin/sh
release_file='/etc/redhat-release'
if [ -f $release_file ];then
echo $release_file
else
echo 'no file redhat-release'
exit
fi
release=`cat $release_file | awk '{print $4}'`
if [ ${release:0:1} != '7' ];then
echo 'only support centos7'
exit
fi
rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y httpd
yum install php56w php56w-pdo php56w-gd php56w-mbstring php56w-xml php56w-mysqlnd php56w-fpm php56w-mcrypt php56w-bcmath php56w-pcntl php56w-posix -y --enablerepo=webtatic
yum install mysql-server -y
systemctl enable mysqld
systemctl enable httpd
systemctl start httpd
systemctl start mysqld
cat << EOF > tmp.sql
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
grant all privileges on *.* to 'root'@'localhost' identified by '123456' with grant option;
EOF
mysql -uroot < tmp.sql
rm -f tmp.sql
cat << EOF > /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
ServerName zhejiangmeihuo.com
ServerAlias zhejiangmeihuo.com www.zhejiangmeihuo.com
DocumentRoot "/var/www/html/cltnfx"
DirectoryIndex index.php index.html
RewriteEngine on
LogLevel error
#LogLevel alert rewrite:trace3
<Directory "/var/www/html/cltnfx">
Options -Indexes +FollowSymlinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
EOF
泡杯咖啡,坐等安装完毕就行了。