Well, first you'll want to make sure that you have execute permissions for the file. ls -l the file.
Code:- $ ls -l index.php
- -rw-r--r-- 1 iota users 1302 Jun 9 23:28 test.php
Copy Code From the above we can see that it is not executable for the owner, so we'll chmod it.
Code:- $ chmod u+x test.php
- -rwxr--r-- 1 iota users 1302 Jun 9 23:28 test.php
Copy Code Once that's done you can execute it by typing
Code:- $ . test.php
- Hello, world!
Copy Code provided that you've included the appropriate shebang as the first line, i.e. #!/usr/bin/php or something to that effect. Alternatively you could just do
Code:- $ php test.php
- Hello, world!
Copy Code Executing it like that would eliminate the need to make the file executable.
Here's a useful tip, if you add a . (current directory) to your PATH variable) you can execute scripts/programs etc. in the current directory without having to type the . in front of the script name. (Add it to your rc file to make it permanent)
Code:- $ export PATH=$PATH:.
- $ test.php
- Hello, world!
Copy Code |