0

I want to deploy my PHP website in Ubuntu Virtual Machine in Azure. I am downloading the website zip file from Azure blob storage and copying it to /var/www/html/ using below command.

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

Now I have to add "AddType application/x-httpd-php .html" line at the end of sudo nano /etc/apache2/apache2.conf file automatic through command line. I am putting all the command in one script file and that script file is used to deploy my website automatically. I have written the below script file for my website deployment.

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

Please help me, how I will add the line in an automated process.

5
  • 1
    as you running your script with sudo allready adding the line echo "AddType application/x-httpd-php .html" >> /etc/apache2/apache2.conf to end of your script should be enough... Feb 29, 2016 at 15:41
  • @IvanTemchenko I would suggest making that into an answer so that you can get rep :P
    – user323419
    Feb 29, 2016 at 15:51
  • I'm not sure if it will help :P Feb 29, 2016 at 16:03
  • Thanks a lot for your help. I am successfully deployed my PHP website in Azure Ubuntu VM. Now I need one more help from you. I have to connect my website DB with Azure MySQL DB. So I have to edit the config.php file through command, not manually. My file is present in /var/www/html/temp/ folder. I am using the below syntax to edit the file. "echo "hostname us-cdbr-azure-west-c.cloudapp.net" >> /var/www/html/temp/config-sample.php" Mar 4, 2016 at 5:32
  • But it's adding the whole line at the end of the file. Please advice me some command, so that I will edit my file through command line Mar 4, 2016 at 5:42

1 Answer 1

0

as i see from this script your passing the password with the script like if the script is script.sh your running the script as

 sudo -i
./script.sh yourmysqlpassword #assuming the script is in current directory

i edited it to your needs just appending the line will do the job

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

run the script as root so echo doesn't complain

4
  • Thanks a lot for your help. I am successfully deployed my PHP website in Azure Ubuntu VM. Now I need one more help from you. I have to connect my website DB with Azure MySQL DB. So I have to edit the config.php file through command, not manually. My file is present in /var/www/html/temp/ folder. I am using the below syntax to edit the file. "echo "hostname us-cdbr-azure-west-c.cloudapp.net", "dbuser sandy" dbpassword hsjdj@1234" >> /var/www/html/temp/config-sample.php". But it's adding the whole line at the end of config file. Mar 4, 2016 at 5:38
  • Please advice me some command, so that I will edit my file through command line. Mar 4, 2016 at 5:40
  • just open the file with any text editor like vim or nano, write it like this nano yourfilename when done ctrl+x to exit it will ask for saving changes press y or n then exit Mar 4, 2016 at 15:22
  • if my naswer helped you, then choose as answer ,give vote to it so others can find this easily seeing it solved Mar 4, 2016 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .