我想在 Azure 中的 Ubuntu 虚拟机中部署我的 PHP 网站。我正在从 Azure blob 存储下载网站 zip 文件,并使用以下命令将其复制到 /var/www/html/。
wget https://acmesanappstor0.blob.core.windows.net/appmigration/Online_Shopping.tar.gz
tar -xzvf Online_Shopping.tar.gz
sudo mkdir /var/www/html/Online_Shopping
sudo cp -r ~/Online_Shopping/* /var/www/html/Online_Shopping
现在我必须通过命令行自动在 sudo nano /etc/apache2/apache2.conf 文件末尾添加“AddType application/x-httpd-php .html”行。我将所有命令放在一个脚本文件中,该脚本文件用于自动部署我的网站。我为我的网站部署编写了以下脚本文件。
#!/bin/bash
apt-get -y update
# set up a silent install of MySQL
dbpass=$1
export DEBIAN_FRONTEND=noninteractive
echo mysql-server-5.6 mysql-server/root_password password $dbpass | debconf-set-selections
echo mysql-server-5.6 mysql-server/root_password_again password $dbpass | debconf-set-selections
# install the LAMP stack
apt-get -y install apache2 mysql-server php5 php5-mysql
wget https://acmesanappstor0.blob.core.windows.net/appmigration/Online_Shopping.tar.gz
tar -xzvf Online_Shopping.tar.gz
sudo mkdir /var/www/html/Online_Shopping
sudo cp -r ~/Online_Shopping/* /var/www/html/Online_Shopping
sudo nano /etc/apache2/apache2.conf
****AddType application/x-httpd-php .html***
sudo /etc/init.d/apache2 restart
请帮助我,如何在自动化过程中添加该行。
答案1
正如我从该脚本中看到的那样,您使用脚本传递密码,例如,如果脚本是 script.sh,则您运行脚本的方式如下
sudo -i
./script.sh yourmysqlpassword #assuming the script is in current directory
我根据您的需要对其进行了编辑,只需添加以下行即可
#!/bin/bash
apt-get -y update
# set up a silent install of MySQL
dbpass=$1
export DEBIAN_FRONTEND=noninteractive
echo mysql-server-5.6 mysql-server/root_password password $dbpass | debconf-set-selections
echo mysql-server-5.6 mysql-server/root_password_again password $dbpass | debconf-set-selections
# install the LAMP stack
apt-get -y install apache2 mysql-server php5 php5-mysql
wget https://acmesanappstor0.blob.core.windows.net/appmigration/Online_Shopping.tar.gz
tar -xzvf Online_Shopping.tar.gz
sudo mkdir /var/www/html/Online_Shopping
sudo cp -r ~/Online_Shopping/* /var/www/html/Online_Shopping
sudo nano /etc/apache2/apache2.conf
###AddType application/x-httpd-php .html###
echo "AddType application/x-httpd-php.html" >> /etc/apache2/apache2.conf
sudo /etc/init.d/apache2 restart
以 root 身份运行脚本,这样 echo 就不会发出抱怨