Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6084105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:28:57+00:00 2026-05-23T11:28:57+00:00

On OS X and Linux I can run .php files from from the command

  • 0

On OS X and Linux I can run .php files from from the command line if two things are true:

  1. I set the executable bit (chmod +x file.php)
  2. I have added #!/usr/bin/php to the top of the file.

If I want to run a shell script, however, I noticed that I can omit step 2, and it will use a default interpreter, /usr/bin/sh

Is there a configuration options I can set, that basically says “if the file is executable (chmod +x) and the extension is .php then use /usr/bin/php as the interpreter?

My ideal solution would allow file.php to live in /localhost/www/, and allow it to be accessed via a web browser as http://localhost/file.php or in terminal via:

/localhost/www/$ ./file.php

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:28:58+00:00Added an answer on May 23, 2026 at 11:28 am

    If there is some way to associate a MIME type other than by looking at the interpreter line or the extension, you could do it. But I suspect what you’re really asking is “magically recognize random PHP scripts that don’t mark themselves as such”, and the “magically” part means the answer is “no”. Humans can recognize it with sufficient reliability, but your computer can’t without help. Which is why there are file extensions and interpreter lines. (In general it won’t be smart enough to reliably distinguish PHP from Perl.)

    If you do have an extension (.php from your subject line, as opposed to the .sh in the question itself), then zsh has some ability to configure that but bash doesn’t as yet. However, you can make open on OS X and xdg-open on Linux handle it correctly; the former is configured fro the Get Info dialog and the latter via xdg-mime or your desktop’s MIME type database (the latter preferred as sometimes getting raw XDG settings imported is a black art).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can run my script just fine from the command line: php test.php and
How can I run this on linux command line when my username has an
I can run an svn command from the command line but not from within
Making my PHP Command line application support Linux and Windows. Currently it has this
I'm creating a utility in C++ to be run on Linux which can convert
Android is based on Linux; can native Linux applications be run on Android?
Is there a command like cat in linux which can return a specified quantity
Is there a function in the C Library under Linux which can set the
Can sendfile() linux syscall be used to send part of file from one mmaped
Is there a standard Linux command i can use to read a file chunk

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.