phpsh: Running An Interactive PHP Shell (Python)

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, July 22, 2010

Follow me on Twitter as @mattiasgeniar

If you haven’t heard of it yet, there’s a very intersting tool available called phpsh, a python implementation to a PHP shell – but better.

Installing phpsh

SSH into your server, and download, build & install the binaries. This assumes you’ve downloaded the .tar.gz version.

# wget http://github.com/facebook/phpsh/tarball/master
# tar xzf facebook-phpsh-1bc1c01.tar.gz
# cd facebook-phpsh-1bc1c01/
# python setup.py build
# python setup.py install
# phpsh

As simple as that.

How to use phpsh?

Even more simple. Once the install is done, execute phpsh on the CLI, and get started writing PHP code.

srv ~ # phpsh 
Starting php
type 'h' or 'help' to see instructions & features
php>
php>
php> echo "Testing this new PHPSH";
Testing this new PHPSH
php>
php>
php> $dbconn = mysql_connect('localhost', 'user', 'pass');
PHP Warning:  mysql_connect(): Access denied for user 'user'@'localhost' (using password: YES) in /usr/lib/python2.4/site-packages/phpsh/phpsh.php(534) : eval()'d code on line 1
php>
php>
php> exit;

This can help to easily test or debug some PHP code. It has syntax highlighting, tab completion (!!), manual pages, … Still not convinced? Have a look at some real-life examples for a PHP interface shell.  Seriously, awesome tool.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.