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
- Make folder in www folder
- Make conf file site-available
- Execute a2ensite
- restart apache
- Create database
- 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)
- Set password to sudo (Didnt get anything on google)
- Connect ec2 using PHP library (Library is available but dont know how to execute commands)
Suggest anything.