Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the PHP command line interactively?

Tags:

shell

php

Are there any howtos for using the PHP command line interactively?

I found a lot about running scripts that are in text files, but not really about the shell with the prompt where I type in commands:

$ php -a
Interactive shell

php > echo "hello world";
hello world
php > $a = 1;
php > echo $a;
1
php > exit;
$

When I go to the Linux shell and run php -a I get the PHP shell. Can I load classes that live in files? What are the rules here?

like image 466
user89021 Avatar asked Feb 27 '26 17:02

user89021


1 Answers

Instructions to install phpsh in Ubuntu 10.04 Server edition.

Get phpsh source and extract

  wget http://github.com/facebook/phpsh/zipball/master

  sudo apt-get install unzip

  mkdir temp

  mv facebook-phpsh-8438f3f.zip temp

  cd temp

  unzip facebook-phpsh-8438f3f.zip

phpsh uses python, install dependencies

  sudo apt-get install python-setuptools

  sudo apt-get install linux-headers-$(uname -r)

  sudo apt-get install build-essential

  sudo apt-get install python-dev

  sudo apt-get install sqlite3 libsqlite3-dev

  sudo easy_install pysqlite

  sudo apt-get install libncurses5-dev

  sudo easy_install readline

Setup phpsh, run and see that is works

  sudo python setup.py install

  phpsh

    $a = array("a"=>1,"b"=>2);

    print_r($a)
like image 57
mozey Avatar answered Mar 02 '26 05:03

mozey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!