Upstart a Yii console gives me error - php

I am trying to run a backend process and I am hitting into problem getting the upstart to run the yiic command.
I am using xampp server
Here is my upstart script:
#description "Sample upstart"
#start on stopped
start on startup
stop on shutdown
respawn
chdir /opt/lampp/htdocs/my_project/protected
setuid mad
setgid www-data
script
exec /opt/lampp/htdocs/my_project/protected/yiic project test
end script
So when i do
sudo start test-monitor
the upstart is starting and it it seems like it is firing a command to yii project as error is being caught in yii log file. The error in yii log file is:
2014/10/31 15:06:44 [error] [worker.*] CDbConnection failed to open the DB connection: could not find driver
2014/10/31 15:06:44 [error] [worker.*] CDbConnection failed to open the DB connection: could not find driver
2014/10/31 15:06:44 [error] [worker.*] CDbConnection failed to open the DB connection: could not find driver
2014/10/31 15:06:44 [error] [worker.*] CDbConnection failed to open the DB connection: could not find driver
However if I do the command manually:
./yiic project test
This are working fine. Can someone please help me.
Here is the codes for the yii console command:
public function actionTest(){
try{
while(1){
TestManager::_MonitorTest();
usleep(1000000);
}
}catch(Exception $e){
Yii::log( $e->getMessage(), 'error', 'worker.*');
}
}
Here is the log file of the upstart (It isn't the case as I have taken the sudo out):
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
Mysql connection is working fine and I have tested it

After some persistent tries and some configuration, I managed to solve the issue.
Since the server was a xampp server, php is installed in xampp thus there is an environment issue. Thus the bin directory of the php has to be referenced in the upstart as such:
This was the solve on the upstart script:
script
exec /opt/lampp/bin/php -f /opt/lampp/htdocs/my_project/protected/yiic.php project test
end script

Related

shell_exec not working with ssh command in virtual machine

I have a script PHP that this has a command ssh with ls -la to list the files and directories. But when I run the script, it returns me error code 255 in addition to the following error message:
Could not create directory '/usr/sbin/.ssh'. ssh_askpass: exec(/usr/bin/ssh-`askpass): No such file or directory Host key verification failed.`
When I use sudo on the ssh command, it returns me another error, being the following:
sudo: no tty present and no askpass program specified
The authentication key is already inside the know_hosts file and when I run the same command inside the terminal, connecting via ssh, everything works perfectly. The key is inside the Downloads folder and her permission is 0644. I've tried several possible solutions, but none have been able to help me solve the problem.
Here is the code used:
$oldldpath = getenv('LD_LIBRARY_PATH');
putenv("LD_LIBRARY_PATH=");
var_dump(shell_exec("ssh -i $key_file user#ip \"ls -la ~\" 2>&1"));
putenv("LD_LIBRARY_PATH=$oldldpath");
Editing - Correcting a part of the problem
The problem Could not create directory '/usr/sbin/.ssh' has been fixed from the creation of the .ssh folder inside /usr/sbin. Now, when the script runs again, it returns the rest of the problem, which is as follows:
ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory Host key verification failed.
Edit 2:
The above error was corrected with the installation of ssh_askpass, from the following code below:
sudo apt-get install ssh-askpass
However, after the corrections on the described errors, another error was generated, being the following:
No protocol specified Error: Can't open display: :0.0 Host key verification failed.

libvirt-php receives the error: internal error Unable to locate libvirtd daemon in /usr/sbin

I have installed php-libvirt as well as all required packages
I have setup my php file as follows:
<?php
echo “WebAdmin 0.1Beta”;
echo “<br/>”;
$uri=”qemu:///system”;
echo (“Connecting to libvirt (URI:$uri)\n”.”<br/>”.”<br/>”);
$conn=libvirt_connect($uri,false);
if ($conn==false)
{
echo (“Libvirt last error: “.libvirt_get_last_error().”\n”);
exit;
}
However when I load the page I get:
WebAdmin 0.1Beta
Connecting to libvirt (URI:qemu:///system)
Libvirt last error: internal error Unable to locate libvirtd daemon in /usr/sbin (to override, set $LIBVIRTD_PATH to the name of the libvirtd binary)
It works fine from the command line when I run
[root#localhost ~]# virsh -c qemu:///system list
Id Name State
----------------------------------------------------
I checked Libvirtd status, it's also running
[root#localhost ~]# service libvirtd status
libvirtd (pid 14017) is running...
What could be the issue?
Do you have libvirtd executable in /usr/sbin?
You should find where it is and point $LIBVIRTD_PATH to the correct folder.
If you run the script as non-root user then the executable could be there, just the script does not have permissions to use it.
p.s. probably this question is for Server Fault

Asterisk Failed to execute '/usr/share/asterisk/agi-bin/call_handle.php': Permission denied

Server: Ubunto
Asterisk Version: 11.x
Directory: /usr/share/asterisk/agi-bin/
File: call_handle.php
Directory Permission: 755 root root
File Permission: 755 root root
asterisk.conf
astagidir => /usr/share/asterisk/agi-bin
extensions.conf
same => n,AGI(call_handle.php)
When I dial any number this AGI PHP Script is run.
But, It will give me this message in asterisk console.
Asterisk Failed to execute '/usr/share/asterisk/agi-bin/call_handle.php': Permission denied
I am not sure why this message is comes up. It has execute permission with ROOT user
The probable issue seems to be with the file ('/usr/share/asterisk/agi-bin/call_handle.php') not falling in the user group of Asterisk daemon that is asterisk:asterisk
That is to say - Asterisk daemon should have the ownership of this file.
Secondly, there is also a possibility that the user who is actually running this Asterisk daemon is not having the execute permission of this daemon.It should be there.
I got answer myself:
Set PHP Envirement in my php script and it will run by asterisk.
I have set following in my php file at first line:
#!/usr/bin/env php
Reff: PHPAGI: Exec format error
First ensure file can be executed
chmod a+x /usr/share/asterisk/agi-bin/call_handle.php
After that check that selinux not enabled or setup correctly
Disable selinux on Centos/Redhat
echo "SELINUX=disabled" > /etc/sysconfig/selinux
After that need reboot

shell_exec throws: sudo: no tty present and no askpass program specified

I have been trying to execute a script using shell_exec() function in php:
I've written the following lines of code:
$command = "bash /path/to/my/script/ funciton_name() 2>&1";
echo shell_exec($command);
Inside the shell script I'm doing:
sudo rsync -avvc /source/path /destination/path
On executing this on the browser, I get the following error message:
sudo: no tty present and no askpass program specified
When I execute the same shell script on my server, it executes fine.
When I went through similar questions posted on this forum, I realised that I had to add the NOPASSWD line on my server which I found out has already been added in the following format:
User_Alias NOBODY=nobody,apache
NOBODY ALL=(ALL) NOPASSWD : /path/to/my/script
Also when I do:
echo shell_exec("whois");
I get the output as:
apache
Any assistance in overcoming this problem would be of great help.
sudo will require a TTY, even if you have set up it up to be passwordless, unless you explicitly do not require it. But as #Cfreak pointed out, it would be much better (simpler and safer) to avoid sudo by setting correct access rights (read it before continuing) in the first place.
rsync itself will not require root permissions on a sanely configured *nix install. To verify this, you can check that type -a rsync doesn't print anything weird like rsync is aliased to `sudo rsync' and that ls -l $(which rsync) prints sensible permissions (at least rx for everyone).

PHP: Run Shell Script as root user

I'm trying to run a script as root user. here is my code
echo shell_exec("sudo bash.sh 2>&1");
It's giving error
sudo: no tty present and no askpass program specified
www-data is not in the sudoers file. This incident will be reported.
I've followed these methods as well but end up with no permission error
There are a couple of issues you might encounter:
The user that is running the php process must have sudo rights (check with visudoers command)
There is no environment set, so the $PATH variable does not include the path to the sudo command
sudo might require a password. Either change the sudoers file, adding NOPASSWORD, which would be hugely unsafe. Or you have to use pipes (proc_open), and pass the password through the stdin pipe
I've managed to find a way to do so, but after some help from people on this site:
load .profile with proc_open()
proc_open interaction

Categories