Just migrated a website from a linux server without a cpanel to a server with a cpanel. My problem is when I hit start to start a process which executes a php file. It will not run the file. If I run the file from terminal everything works.
The code that calls the file.
if ($do === "start_service") {
create_marker_file("$service_running_marker");
system_bg("php $dir/$service_script");
$message = "Started Service!";
$running = true;
$status = "Running";
}
The systembg is a function.
function system_bg($command) {
exec('bash -c "exec nohup setsid ' . $command . ' > /dev/null 2>&1 &"');
}
If i do ps ax | grep service.php
in terminal is see this
/opt/cpanel/ea-php70/root/usr/bin/php-cgi /home/xsocial1/public_html/xsmp/service.php
When I run the file in terminal this is what i see when I run ps ax | grep service.php
/opt/cpanel/ea-php70/root/usr/bin/php service.php
I think my problem is I need the server to call a cli call and not a cgi call
2
Answers
This is correct, you will need to figure out the CLI PHP path and use that to start the process. This is sadly not exactly standardised, but on a *nix machine you will usually have the right one by using
PHP_BINDIR .'/php'
(PHP_BINDIR being a PHP constant).You may try to check the webserver user has a privilegies to run the bash.