62

I would like to ask if I can run a php without having installed a web server. Do I have to use the php like CGI and run my page via command line? And if so, what are the steps that I do I have to choose through the installation of php? I mean the preferences as CGI and the components after that step?

I installed the php 5.3.3 but is seems not working, I get several message that the php5ts.dll is missing and when I put that file in my ext folder other error messages appear. Are there any configuration files or steps that I have to use? (is php 5.3.3 suitable for doing something like this?)

If I have to have a web server installed how can I run my php code through the command line?

Mike Laren
  • 8,028
  • 17
  • 51
  • 70
touinta
  • 971
  • 3
  • 10
  • 26
  • 2
    "run my page" - If you are serving web pages why would you use anything other than a web server? – BoltClock Nov 29 '10 at 08:36
  • 1
    I actually want to execute a php (sorry that i said "page") that it does http request with responses,once per day automatically.(I quess i heve to make the task that wiil open the php file through the command line or just executes the php) When i run it from a browser everything goes well. When i run it without ex.apache, from php command line nothing seems to execute. (I get and the errors when open the coomand line) what should i choose wehn i intsall php 5.3.3 (no CGI)? But i dont really found vie web what do i have to do as confuguraion so to execute php. – touinta Nov 29 '10 at 08:52
  • Does this answer your question? [Is there any way to test PHP locally without installing a server?](https://stackoverflow.com/questions/21495733/is-there-any-way-to-test-php-locally-without-installing-a-server) – ggorlen May 13 '23 at 21:05

4 Answers4

106

You should normally be able to run a php file (after a successful installation) just by running this command:

$ /path/to/php myfile.php // unix way
C:\php\php.exe myfile.php // windows way

You can read more about running PHP in CLI mode here.


It's worth adding that PHP from version 5.4 onwards is able to run a web server on its own. You can do it by running this code in a folder which you want to serve the pages from:

$ php -S localhost:8000

You can read more about running a PHP in a Web Server mode here.

Michal M
  • 9,322
  • 8
  • 47
  • 63
  • 1
    thank you for your answer(after a successful installation) thats my point i cannot have the right installation or the confuguration for the php so to be execute i always get the errors about the php5ts.dll and then the zlib.dll... i have read so much in web about that but it dont have any result...maybe is the 5.3.3 version tha it has the problem..anyway – touinta Nov 29 '10 at 09:27
  • I see two options: 1. Try installing lower version, from 5.2.x branch (if you're ok with not having the latest features of 5.3 2. Instead of installator, use a ZIPped version, so there's no installation involved. Choose a version suitable for you from here: http://windows.php.net/download/ (you probably won't be interested in Debug Pack though) – Michal M Nov 29 '10 at 09:40
  • thank you So if I understand what you say is to use the manual way installation of php. (the installer of php 5.2.8 i finally used it gives the error about the CLI dll.... when i open the command prompt) and not to use a 5.3+ version if i do this. I wiil give a try. Are there any other directions that i have to follow exept those in install.txt? i guess i follow the "Installation on Windows systems" part and "Installation of PECL extensions" part. – touinta Nov 29 '10 at 11:15
  • You might not need PECL. PHP should work as is out of the ZIP package/installer. – Michal M Nov 29 '10 at 15:44
  • hello! I have add some PECL dlls as php_http.dll because my project use httpRequest. (Ι have the whole PEAR package) I read about the error message and i found out that it has to do with Oracle. But I am no going to use any oracle database in my present project and in fact not db at all. So I comment the according dll but the errors insists like a "ghost" over my php :)... – touinta Nov 30 '10 at 07:29
  • ....Another point that i remember i did in my old installation of php was to put some files in my System32 folder..(Do you know which are the correct files? i remember sure about php5ts.dll and some others)... i have lost my old "sweet" php ..because i was advice to use the 5.3.3 and everything was destroyed...(I must have taken a backup) now i reinstall the 5.2.8 and at least i can execute php trhough a browser and apache of course...but the command prompt is not working... – touinta Nov 30 '10 at 07:37
  • I remember I used to put some mcrypt related stuff in system32 folder, but I doesn't seem to be the case lately though. It definitely wasn't any php*.dll file. – Michal M Nov 30 '10 at 07:55
  • hello!!! everything looks good now, I used 5.2.14 zip package and works fine. I left the idea of 5.3.3.. and i only made the basic changes and those for the PATH according to php.net. Thank you very much..hey you may be interesting to check this out...http://www.devside.net/articles/php... bb – touinta Dec 01 '10 at 12:54
  • @MichalM How can I insert data in to database using this technique. I have to install MySQL, sql separately ?? – G Naga Subrahmanyam Oct 24 '16 at 03:20
7

For windows system you should be able to run php by following below steps:

  1. Download php version you want to use and put it in c:\php.
  2. append ;c:\php to your system path using cmd or gui.
  3. call $ php -S localhost:8000 command in a folder which you want to serve the pages from.
3

PHP is a normal sripting language similar to bash or python or perl. So a script with shebang works, at least on linux.

Example PHP file:

#!/usr/bin/env php

<?php

echo("Hello World!\n")

?>

How to run it:

$ chmod 755 hello.php  # do this only once
$ ./hello.php
Michel Samia
  • 4,273
  • 2
  • 24
  • 24
-12

You can use these kind of programs to emulate an apache web server and run PHP on your computer:

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

http://www.apachefriends.org/en/xampp.html

Latox
  • 4,655
  • 15
  • 48
  • 74
  • 2
    well i know and i have use those two for several reasons ex joomla. But the work i have to do now is that the file must be execute for several pcs in my net..and i would like not to install a web server on every pc.. – touinta Nov 29 '10 at 09:28
  • 9
    Last time I checked, those were web servers. – bryc Aug 23 '14 at 04:06
  • 1
    Both WAMP, and XAMPP are web servers, please delete this answer. – saji89 Jun 10 '15 at 08:30