PHP Interpreter for Windows - php

Trying to mess around with PHP, but I don't want to install IIS or Apache and was hoping for a small interpreter that I can pass the scripts to and have them run in like a console or something. Much like Lua does. Does this exist? When I go to download PHP it seems to only talk about running it on IIS or Apache.

PHP can be used on the command line. Just download and extract the executable.
Running can be done 3 ways: a file, supplied code or in an interactive shell
php file.php
php -r "echo 'hello';"
php -a
You can also install a pre-packaged server (e.g. XAMPP) or run your code online on various places (e.g. phpfiddle.org)

With PHP 5.1+ you have an interactive shell too:
launch php with -a parameter
php.exe -a
http://php.net/manual/en/features.commandline.interactive.php

I believe that PHP v5.4 comes with its own webserver built-in. Install that version and you should be fine. Though I really would like to know why you have problem with installing Apache (IIS sucks though).
EDIT:
As a few others have said, you can run PHP from the command line.

check out easyphp, a server for php development

http://php.net/cli
Alternatively, you can write your PHP scripts as you would normally (with some limitations),
And use the following command line:
C:\php.exe -f "D:\phpFile.php"

dtech's answer seems most fitting for the simple script-running things you're looking for. If you decide you want an actual web-server, with as little setup as possible, look at "XAMPP".

Related

Is there any way to test PHP locally without installing a server?

I'm looking for something like http://phpfiddle.org/, but completely local. I don't want to commit to installing something as complex as Apache, then PHP on top of that, just to try out code when I'm offline. Is there anything that can run PHP 5.5 on the local machine without installing an entire server underneath it?
There's no need for a server if using PHP 5.5+ - it has a built-in server (http://www.php.net/manual/en/features.commandline.webserver.php)
Just use:
$ cd ~/public_html
$ php -S localhost:8000
As a minimalistic solution, on the command line you can also start php in interactive shell with php -a that will execute the commands you enter line by line. I often use it for testing small snippets of code.
You can download a portable webserver http://www.usbwebserver.net/en/ and use this script under it https://github.com/websiteduck/Run-PHP-Code
You can install either XAMPP or WAMP server locally if you find it complicated to configure PHP for Apache.
You should try phpsh as well. It is a php interactive shell from the facebook developer folks with history, tab completion and quick access to documentation.
The project is maintained on github.
Use psysh which is a wonderful tool for the purpose you described.
If your project is on Laravel, then it's "built in", as tinker, so you can invoke it as php artisan tinker.
I really dont think so. but it isnt so complex as you think.
if you are on windows - just download: http://www.wampserver.com/ - it will install the whole server for you (mysql&phpmyadmin,php5).
on linux - got to google: install lamp to [your-linux] -- and follow the simple instructions
For Windows Users:
Check out the ezPHP GitHub project. Per the project description...
EzPHP is an alternative to Xamp/Wamp. EzPHP is the easiest way to setup a PHP development environment for learning PHP programming on Windows.
The scope of this project is to provide a single .exe file that will get you a PHP developing server.
Link - https://github.com/marcomilon/ezphp
Setting it up was simple. Download the exphp.exe file and drop it in a folder. When you run the exe, it will launch the server and generate a public_html folder and index.php file. Follow the instructions in the command window and navigate to http://localhost:8080. Now you can start developing in the public_html folder and refresh your browser to see your changes.
This is what I do for simple pages:
Download php in zip and extract (PHP 8.0.2 ~25MB)
Then run
> php.exe path\to\your\index.php>path\to\the\output\index.html
Open the result index.html with your favorite browser
You have to find a workaround for your _GETs though.
If you use a development environment, like Aptana Studio, you might as well click on the Run As, and run it in your preferred browser. You need WAMP/XAMPP to be installed and running in order to do so.

How can I to run php script from powershell-commandline?

How can i setup my powershell to run php scripts in like a commandcall like this
php test.php
I'm able to do this on a server at work which I connect to by putty, but would be nice if I was able to execute those scripts directly from my own without having some server running.
I also know about Xaml, which I don't like since its require you to refresh some browser.
You can do all the stuff suggested above or ...
Go to php.net and download the php file stack for windows.
Copy the file stack into say c:\php or if you want multiple versions, say c:\php5 or c:\php7 etc.
Open powershell and type c:\php\php.exe -h, you will get the php help output. Yay you are up and running, whoot.
(Note: you may need to rename php.ini.development -> php.ini
Advanced instructions:-
Type env into os search (cortana) and select environmental variables.
Add your php location to path (c:\php) and create a variable php (or php5 etc) pointing to c:\php\php.exe
Now you can run php in powershell with php (php -h to test).
Note: while not the question, this also works in the git bash shell.
I'm assuming windows since you said powershell. You can just install php on windows but that means also installing apache or enabling IIS.
Or there's apparently a built-in webserver for command-line functionality that might minimize the amount of headache involved in configuring that stuff.
This might help get you going also:
http://php.net/manual/en/install.windows.legacy.index.php#install.windows.legacy.commandline

Run PHP script from shell or apache server

I am wondering if a PHP script can be executed from a shell command line.
Does a script executed from shell have the exact functionality if executed from the browser? or is there a difference in coding.
Is it better to run a script from shell for performance and also is it better to run it from windows or unix/linux
I am asking all these questions because, I am suppose to develop a PHP script that can fetch some data from http headers of some urls listed in a MySQL db and then store the data in the database.
Can you guys point me to the right direction please, Do I need ubuntu, or is there a shell that can run php from windows? all I have at the moment installed is WAMP, which has mysql, php and apache server.
I am sorry for being a novice.
thanks for your kind help
I am wondering if a PHP script can be executed from a shell command line.
Yes
Does a script executed from shell have the exact functionality if executed from the browser? or is there a difference in coding.
It won't have $_REQUEST and friends populated, and $_SERVER won't have server information in it.
Is it better to run a script from shell for performance
Maybe. It avoids the overhead of runnning a webserver. It stops you having cached versions in memory for faster re-execution.
and also is it better to run it from windows or unix/linux
Benchmark it.
I am asking all these questions because, I am suppose to develop a PHP script that can fetch some data from http headers of some urls listed in a MySQL db and then store the data in the database.
There doesn't seem to be any need to involve a web server for that.
Can you guys point me to the right direction please, Do I need ubuntu, or is there a shell that can run php from windows?
The standard Windows shell can.
all I have at the moment installed is WAMP, which has mysql, php and apache server.
You'll need the command line version of PHP. I've no idea if WAMP includes it or not.
I am wondering if a PHP script can be executed from a shell command line.
It's possible either by executing:
$ php -f your_script.php
Or by inserting #/usr/bin/env php into the first line of the script and by making it executable.
$ head -n 1 your_sript.php
#/usr/bin/env php
$ chmod +x your_script.php
$ ./your_script.php
Note: this example only works on UNIX systems.
Does a script executed from shell have the exact functionality if executed from the browser? or is there a difference in coding.
You can use the same Syntax/Functions etc. The only difference is that there are command line arguments in $argv and some other values in the $_SERVER variable.
Is it better to run a script from shell for performance and also is it better to run it from windows or unix/linux.
That doesn't really matter. For your usecase you don't really need a webserver, and a full featured GUI. The advantage of having a command line tool is, you can combine your program with other program available like grep etc.
Can you guys point me to the right direction please, Do I need ubuntu, or is there a shell that can run php from windows?
You don't need ubuntu, you can also execute a shell script from windows. The PHP executable is located in the %PATH%. This question will help you in order to do this: https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them
Then simply open cmd.exe and execute a script using php -f your_script.php
Yes, PHP can be run from command line.
No, there aren't any differences in coding.
The only difference is that it's not Apache running the script, but the user you are currently logged in as. That could mean different privileges on certain maps and folders.
Yes you can execute PHP from the command line using:
/path/to/php.exe /path/to/script.php
The main difference is that it doesn't run through Apache, so you won't have things that rely on it (like some $_SERVER data).
Also it won't be subject to timeouts on the command line, unless you have a PHP limit set.
Take a look at http://php.net/manual/en/features.commandline.php for more info.

php webserver equivalent of mongrel?

Is there a php equivalent of mongrel? I don't want to install Apache, just to preview a simple template.
mongrel2 looks promising!
This is possible starting with php 5.4:
http://php.net/manual/en/features.commandline.webserver.php
As of PHP 5.4.0, the CLI SAPI provides a built-in web server.
This web server is designed for developmental purposes only, and
should not be used in production.
To run it:
$ cd ~/public_html
$ php -S localhost:8000
I know it's not the ideal solution, but if it's just one page, you can render it straight out to HTML.
php /path/to/file.php > /path/to/output.html
As I posted in the other thread - have a look at Photon (http://www.photon-project.com), it might serve your needs quite well already.

Compile a PHP script in Linux

I know PHP scripts don't actually compile until they are run. However, say I want to create a small simple program and compile it to a binary without requiring the PHP binary. How could I do this?
I've seen a few IDE's out there that would do this, but either they are all for windows or the Linux versions don't actually build properly.
What I would like is something like py2exe that does it in the script itself.
Check out phc: the PHP compiler
If you just want to run it like a script, you may not need to compile it per se, but just run it via the command line. Read running PHP via the command line.
There is this: http://www.bambalam.se/bamcompile/ but that compiles to Windows bytecode. There are a few others, but all I have seen will compile for windows only.Few More:
http://www.nusphere.com/products/phpdock.htm
Edit: I almost forgot if your looking to make it work on linux without regard for windows you can just add
#!/usr/bin/php
to the top of the script and you should be able to run it from the command line. Don't forget to chmod +x the file first.
Have a look at Facebook's Hiphop-PHP. It's able to convert PHP code into C++ then compile it with g++. Apparently, they've even gotten it to successfully compile entire WordPress installations.

Categories