Run PHP,  just as a local script platform on Windows, how to?

zzhang2006
zzhang2006 used Ask the Experts™
on
I installed PHP using the installer
   php-5.3.2-nts-Win32-VC9-x86.msi

and try to run the follow script  (hello.php) at a command prompt.

> hello.php

and this is the error messageI got from windows:
      php-win.exe - Inable To locate Component  (pop up)
         X  --  This application has failed to start because OCI.dll was not found. Reinstalling the
                  applicaton may fix this problem.

The script (may be irrelavant at the moment) contains:

<?

# This a comment

echo "Hello";

$a = 1;

$b = 2;

$c = $a + $b;

echo $c;


>

...

When under the setup/install, I chose  "do not setup the web servers" since I thought I  just want to run the scripts. However I remember I had it work on the machines had apache servers
installed.  Do I have to have one type of web servers installed or even running to be able to
run the php script locally?  How do I let it find the OCI.dll file  (for Oracle?)?

Or my goal is just being able to run a php script like a program locally, don't need to use any
servers at this time.  Am I on the right track or you experts have better solutions?

Thanks

Ze
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
What Windows version are you using?
Mark BradyPrincipal Data Engineer

Commented:
Php won't run on it's own without having the server engine started. I assume you are running either XP or Vista or Windows 7?  The best thing to do is uninstall your PHP and download WAMPSERVER from here...  

http://www.wampserver.com/en/download.php

Click "download Wampserver from the box at the bottom. Once you run the setup, it will set everything up properly for you and configure everything.

You will now be able to go and open a browser and go to "http://localhost/" and run any php scripts you have. I think the default directory for wampserver is C:\wamp\www\      so all your scripts need to be put somewhere after that directory. If you take a php script outside of the "www" folder, it will not run.

Hope that clears it up for you.
Mark BradyPrincipal Data Engineer

Commented:
I should have added that PHP is a serverside scripting language. That means the "SERVER" or web server runs the scripts behind the scenes and outputs the results to the web browser. That is why if you right click on a webpage written in PHP or view the source, you won't see ANY PHP code, only what the code prints to the browser window ie:  

$your_name = "zzhang2006";
echo $your_name;


Viewing the source will only show "zzhang2006"

But that script must be in the www directory or a folder inside the www folder.
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Use Wamp server, you can then place the scripts inside :

c:/wamp/www/

and browse as
http://localhost..
Senior Software Developer
Commented:
@Elvin66, I'm sorry to say, but you are wrong. Please read the rest of the comment below. If you have any questions about this, let me know.




@zzhang2006, PHP runs in several ways or SAPIs.

Commonly, using a webserver, the SAPI will be CGI, FastCGI (preferred), ISAPI (now defunct). Many others exist. Some maintained by third parties.

PHP can also run as a command line script interpreter. Just like .VBS or .BAT scripts.

NOTE: To run PHP scripts it is not necessary to run a web server if all you want is to use PHP at the command line.

So. With that, 2 important pages to read:

1 - Manual Installation : http://docs.php.net/manual/en/install.windows.manual.php
2 - Command Line PHP on Microsoft Windows : http://docs.php.net/manual/en/install.windows.commandline.php


Personally, the manual install procedure is so much easier than any other mechanism.

At best, you only really need 2 files.

The SAPI executable : You have a choice of 2 : php.exe and php-win.exe. In your case, use php.exe
The php5.dll : This is the main part of PHP which all the SAPI's link to.

If you don't want any extensions and are happy with all the built in defaults, that's all you need.

Put them in your path somewhere and then read the second link above for more info on getting .PHP scripts executable just like a .BAT or .VBS script.


With regard to your OCI issue, PHP _can_ use an external INI file which contains instructions and settings to include addition libraries or "extensions". These can include connectors to different databases, encryption tools, ... etc. (just take a look at http://docs.php.net/manual/en/funcref.php to see the different categories available - and more always being added/updated/outdated - PHP never stands still).

So, your php.ini file contains a line like ...

extension=php_oci8.dll

But, that is just the extension that will join PHP to the OCI library. If it can find it.

On your setup, it can't.

Your options are to either install the Oracle libraries or to remove the extension from the ini file.

To find the ini file, type ...

php --ini

at the command line.

Look for something like ...

Loaded Configuration File:         C:\PHP\INI\php-cli.ini

The file named above will be the INI file that your php installation is using.

As you can see, I've got one for using the command line (CLI).

You can have different ones for CLI, CGI, etc.

The pages in http://docs.php.net/manual/en/configuration.php provide a highly detailed description of what that is all about.


Hopefully that'll help you.

If you have any issues, please come back...

Mark BradyPrincipal Data Engineer

Commented:
I stand corrected !  Cheers..... I personally would recommend installing wampserver as it configures everything for newbies and is very easy to use. However, you are correct in your posting. There is a lot more manual setup work your way but yes it is very possible. Thanks for setting me straight.
zzhang2006Professor

Author

Commented:
QRaudling,
thanks for the answer, the script worked after I removed the Oracle extensions at the installer/setup options. Though it may be unfair :-),  do you also know how to write to a USB port from a command line php script?  I have a device attached to USB port and it takes ascii commands. If I can write from php to the port to control the device, I may eventually have a remote interface to it by setting up a server.

Thank again
Dave BaldwinFixer of Problems
Most Valuable Expert 2014
Commented:
I use some PHP command line utilities in Win2000 and Win XP.  You might be able to talk to your USB device thru a PHP command line program.  However, you will probably Not be able to talk to it thru a web server because that is considered a security violation to let web pages access your hardware.  At the command line, it is running as your user with your privileges.  Thru a web page, it runs with limited privileges of the anonymous web user.
Richard QuadlingSenior Software Developer

Commented:
If the USB device creates a COM port as part of its configuration, then it should be possible to communicate with it in that way...

$fp = fopen('COMx', 'wt');

sort of thing.

USB ports aren't directly accessible as USB1, USB2, etc. (what's with that!!!).

You could use the php_win32api.dll to talk to the appropriate dll's to allow you direct usb comms, essentially using php as a wrapper for the dll library calls - you'd need to learn about the port calls and protocol and handling - and compile php_win32api.dll as it is is PECL source only - at which stage, doing it all in C would certainly be the easier route (comparatively).


OOI, what is the device? Does it have any utils installed to allow you to use it?

If it provides a COM interface (not a "COM"munication port, but a Component Object Model interface), then PHP fully supports COM, so you _could_ talk to it that way. You can use COM to talk to Word, Excel, Crystal Reports, etc.


Options, options, options.



Something I just thought of, ... and no idea if it would/could work, ... is to use a USB to COM port mapping tool. Essentially allowing a USB device to be accessed as a COM port. If that works, then PHP can talk to it. Obviously, you are putting another layer of complexity in here and YMMV. http://www.ftdichip.com/Drivers/VCP.htm was the first site I came across with something like this. This site only supports USB devices based upon the specific chipset, so again, YMMV.

zzhang2006Professor

Author

Commented:
good job!
Richard QuadlingSenior Software Developer

Commented:
OOI. What would have got a grade A?

As far as I can tell, all your issues in the question have been answered completely.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial