1

We are trying to automate website deployment on aws ec2 ubuntu instance using php.

So to deploy website on aws ec2 ubuntu instance we have to follow steps

  1. Make folder in www folder
  2. Make conf file site-available
  3. Execute a2ensite
  4. restart apache
  5. Create database
  6. Create user and grant all access

I am trying to do all things using PHP. So I stuck at 1st steps for following code

echo shell_exec("sudo mkdir /var/www/{$_POST['environment']} 2>&1");
echo shell_exec("sudo mkdir /var/www/{$_POST['environment']}/{$_POST['site']}/public_html 2>&1");
echo shell_exec("sudo mkdir /var/www/{$_POST['environment']}/{$_POST['site']}/ssls 2>&1");
echo shell_exec("sudo mkdir /var/www/{$_POST['environment']}/{$_POST['site']}/conf 2>&1");
echo shell_exec("sudo mkdir /var/www/{$_POST['environment']}/{$_POST['site']}/sqls 2>&1");

but got following error

sudo: no tty present and no askpass program specified

I searched for some alternatives (In my mind)

  1. Set password to sudo (Didnt get anything on google)
  2. Connect ec2 using PHP library (Library is available but dont know how to execute commands)

Suggest anything.

KuKu
  • 646
  • 2
  • 15
  • 38

1 Answers1

0

That error indicates the script needs to ask the user for a password to sudo and it can't. You can allow the user running the php commands to sudo without a password. See this related answer or search for how to allow sudo without a password and you will find lots of guides.

Community
  • 1
  • 1
jzonthemtn
  • 3,344
  • 1
  • 21
  • 30