55

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?

hakre
  • 193,403
  • 52
  • 435
  • 836
Ky -
  • 30,724
  • 51
  • 192
  • 308
  • 1
    http://www.php.net/manual/en/features.commandline.webserver.php ? – DCoder Feb 01 '14 at 08:13
  • http://www.uniformserver.com/ - runs on a flash drive – Tieson T. Feb 01 '14 at 08:14
  • 1
    You can test your php program by PHP CLI. – Ganesh Patil Feb 01 '14 at 08:14
  • The purpose of / and reason for using a complete server is to get as close to a production environment as possible so you're sure in the end that your code works in the real world. Without Apache there to toss out request errors you'll be handicapped as far as debugging. – oucil Feb 01 '14 at 09:14
  • 2
    Using VirtualBox to run a VM that replicates the production environment and versions on your local development box is pretty common practise these days: it allows you to run PHP , MySQL, etc in a sandbox on your development machine – Mark Baker Feb 01 '14 at 09:44

10 Answers10

118

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
WD40
  • 429
  • 1
  • 7
  • 19
Eugen Dimboiu
  • 2,733
  • 2
  • 26
  • 33
6

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.

Randall
  • 2,859
  • 1
  • 21
  • 24
Attila Fulop
  • 6,861
  • 2
  • 44
  • 50
3

You can download a portable webserver http://www.usbwebserver.net/en/ and use this script under it https://github.com/websiteduck/Run-PHP-Code

Uchiha Itachi
  • 850
  • 2
  • 10
  • 15
2

You can install either XAMPP or WAMP server locally if you find it complicated to configure PHP for Apache.

vlad1918
  • 338
  • 3
  • 15
  • Alright, I have XAMPP running and got the shell open, but when I use `php -a` for the interactive shell, nothing I type does anything :/ – Ky - Feb 01 '14 at 18:03
2

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.

Attila Fulop
  • 6,861
  • 2
  • 44
  • 50
2

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.

Attila Fulop
  • 6,861
  • 2
  • 44
  • 50
1

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

Jentel
  • 148
  • 2
  • 17
1

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.

Lucky
  • 4,443
  • 2
  • 8
  • 18
1

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.

Poniros
  • 131
  • 9
0

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.

omrakhur
  • 1,362
  • 2
  • 24
  • 48