Search code examples
phpserverbackground-processgnu-screen

How do I execute a php file on the server using the screen command?


I was looking at this post which is where I got the idea to use screens to execute my php scripts on the server: Running a PHP script completely on server side

I was successfully able to execute a php script using:

screen

php ./file.php

However, this did not work for me:

screen ./file.php

And it was that last way of doing it that was recommended in that post I linked.

All it says is: Cannot exec './file.php': Permission Denied

sudo screen ./file.php did not work either.


Solution

  • You have to pass screen a shell command that works.

    You had a shell command that works in your first attempt.

    You then removed part of it when you tried to pass it to screen. Don't do that. Leave the command intact.

    screen php ./file.php
    

    If you want the PHP script to be executable directly (i.e. without passing it as an argument to the php command line binary) then you need to:

    • Make sure that the first line explains how to execute it (#!/usr/bin/env php)
    • Set the permissions on it so it is executable (chmod u+x file.php)