sylvain1264 sylvain1264 - 1 year ago 145
PHP Question

Run php in a bash script: error "Could not open input file"

I made a simple script like:

php /var/www/mysite/script1.php
php /var/www/mysite/script2.php

When I run it as root like this:


I get following errors:

Could not open input file: /var/www/mysite/script1.php
Could not open input file: /var/www/mysite/script2.php

What is wrong ? I tried with permissions 777 on my php files and all folders to access it. When I do directly php /var/www/mysite/script1.php in my command line it works fine.

Answer Source

When a batch file passes through some windows-compliant editors or other mishaps, it may happen that carriage return chars are appended to the end of the line (just before linefeed)

so the all the lines for instance this one:

php /var/www/mysite/script1.php

contains an invisible \r char which is interpreted as part of the argument py php => file /var/www/mysite/script1.php<invisible char> not found.

Do the following:

dos2unix >


tr -d "\015" < >

(compare file sizes, if the newbatchfile is smaller, problem was CR chars and is fixed)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download