run php directly at shell

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vito

    #1

    run php directly at shell

    how to config the linux to know the path of /usr/bin/php so no need to type
    it before running a php script every time?


  • vito

    #2
    Re: run php directly at shell


    "Michael Vilain" <vilain@spamcop .net> wrote in message
    news:vilain-74AD59.02180503 062006@comcast. dca.giganews.co m...[color=blue]
    > In article <e5rj5q$27d3$1@ justice.itsc.cu hk.edu.hk>,
    > "vito" <vitogen2003@ya hoo.com.tw> wrote:
    >[color=green]
    >> how to config the linux to know the path of /usr/bin/php so no need to
    >> type
    >> it before running a php script every time?[/color]
    >
    > it should be in your path already. try discussing your account with
    > your local sysadmin. they should be able to set your account up to do
    > this without a problem.
    >[/color]

    well, even though it is added by

    set path = ($path /usr/bin/php)

    it can't recognize the interpreter and run it directly. the first ? in
    <?php> immediately generates an error.

    thanks for your help anyway :)


    Comment

    • bobmct

      #3
      Re: run php directly at shell

      vito wrote:
      [color=blue]
      > how to config the linux to know the path of /usr/bin/php so no need to
      > type it before running a php script every time?[/color]

      You need a "shabang" at the top of your script. That is... a line to tell
      the shell which program to use to run this script.

      First, determine the path of your php interpreter with this command:

      "which php"

      and it should print out something like "/usr/bin/php"

      what ever it states, use it verbatim at the top of your script (the VERY
      FIRST statement) similar to this:

      #!/usr/bin/php
      <?php


      Then save your script and it will run as you expect.

      Good luck,

      Bob

      Comment

      • David Haynes

        #4
        Re: run php directly at shell

        vito wrote:[color=blue]
        > "Michael Vilain" <vilain@spamcop .net> wrote in message
        > news:vilain-74AD59.02180503 062006@comcast. dca.giganews.co m...[color=green]
        >> In article <e5rj5q$27d3$1@ justice.itsc.cu hk.edu.hk>,
        >> "vito" <vitogen2003@ya hoo.com.tw> wrote:
        >>[color=darkred]
        >>> how to config the linux to know the path of /usr/bin/php so no need to
        >>> type
        >>> it before running a php script every time?[/color]
        >> it should be in your path already. try discussing your account with
        >> your local sysadmin. they should be able to set your account up to do
        >> this without a problem.
        >>[/color]
        >
        > well, even though it is added by
        >
        > set path = ($path /usr/bin/php)
        >
        > it can't recognize the interpreter and run it directly. the first ? in
        > <?php> immediately generates an error.
        >
        > thanks for your help anyway :)
        >
        >[/color]
        This is if you are running the cshell. (echo $SHELL will tell you)
        For sh, ksh, bash use: export PATH=$PATH:<pat h to php directory>

        For example:
        If your php was installed as /usr/local/bin/php, you would set:
        export PATH=$PATH:/usr/local/bin

        This will last for the life of the login session. If you want it
        permanently you will have to add this command to your shell run-time
        commands file (e.g. .bashrc)

        -david-

        Comment

        • vito

          #5
          Re: run php directly at shell

          > #!/usr/bin/php[color=blue]
          > <?php
          >
          >
          > Then save your script and it will run as you expect.
          >
          > Good luck,
          >
          > Bob[/color]

          Bob, you've already brought luck to me!
          but if i place such a script on web, would it lead to a security weak point?


          Comment

          • vito

            #6
            Re: run php directly at shell

            >but if i place such a script on web, would it lead to a security weak[color=blue]
            >point?[/color]

            at least now i find that it will print #!/usr/bin/php out on web so it is
            very ugly :(


            Comment

            • Jerry Stuckle

              #7
              Re: run php directly at shell

              vito wrote:[color=blue][color=green]
              >>#!/usr/bin/php
              >><?php
              >>
              >>
              >>Then save your script and it will run as you expect.
              >>
              >>Good luck,
              >>
              >>Bob[/color]
              >
              >
              > Bob, you've already brought luck to me!
              > but if i place such a script on web, would it lead to a security weak point?
              >
              >[/color]

              You don't use those on the web. Apache (if configured correctly) will detect
              it's a PHP file and call the interpreter.


              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              Working...