0

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.

5
  • 2
    sudo screen php ./file.php Commented Feb 8, 2015 at 19:22
  • 1
    Don't sudo unless you really need to (which you don't since it worked without sudo in the two step approach at the start of the question). Commented Feb 8, 2015 at 19:26
  • @Quentin I believe you, but may I ask why? Commented Feb 8, 2015 at 19:29
  • 1
    Giving code superuser access to the system when it doesn't need it does nothing except increase the severity of any security issues that might be in that code. Commented Feb 8, 2015 at 19:32
  • @KacyRaye - don't grant additional privileges as per sudo unless you actually need them, it's not good security Commented Feb 8, 2015 at 19:32

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

2 Comments

But I was first! :D, with that comment
@Quentin Cool thank you. Super clear. I'll accept the answer as soon as it lets me. I guess that post I linked just assumed the php file was already set to be an executable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.