Did You Know?
Donate to TecMint

We are pleased to announce our new TecMint Q/A section to submit your Linux questions

Exploring Linux Shell (Terminal) Remotely Using PHP Shell

Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators

PHP Shell or Shell PHP is a program or script written in PHP (Php Hypertext Preprocessor) which provides Linux Terminal (Shell is a much broader concept) in Browser. PHP Shell lets you to execute most of the shell commands in browser, but not all.

Linux Shell Acess on Browser

Linux Shell Acess on Browser

PHP Shell is very much useful in executing Shell commands on remote web-server, similar to Telnet and SSH. It can be useful in moving, unzipping and handling larger files or bulk files on Web-Server. Administrating and Maintaining a webserver using PHP Shell is very much easier, provided the user has working knowledge of Shell Programs.

When there was Telnet and SSH already, what is the need of phpshell, is a question which may come to the mind of yours. The answer is – in many cases, the firewall is so restrictive that nothing, apart from HTTP(S), gets through, in that case phpshell lets you gain the shell access on a remote server.

However you can not execute a GUI program or an interactive script/program using PHP Shell, It could be it’s limitation but this limitation is a boon, as GUI disabling means higher security.

Download PHP Shell

The latest version can be downloaded from here:

  1. http://sourceforge.net/projects/phpshell/?source=dlp

How to Install PHP Shell

As stated above PHP Shell is written in PHP so you don’t need to install it, just move the archived file to your working apache/httpd directory, and of course you must have Apache and PHP installed.

Install Apache and PHP

Install on Debian based systems using apt-get command.

# apt-get install apache2 
# apt-get install php5 libapache2-mod-auth-mysql php5-mysql
# service apache2 start

Install on Red Hat based systems using yum command.

# yum install httpd 
# yum install php php-mysql
# service httpd start

By default working directory of apache/http is:

on Debian based distro /var/www

on Red Hat based distro /var/www/html

Note: It can be changed to any other folder, and it is recommended as a security measure.

Move the downloaded PHP Shell archive file to Apache working directory. Here I am using Debian system, so my Apache working directory is.

# mv phpshell-2.4.tar.gz /var/www/

Unzip php shell

# tar -zxvf phpshell-2.4.tar.gz

Remove the compressed file.

# rm -rf phpshell-2.4.tar.gz

Rename the php shell folder to anything hard to guess, as a security measure. For example, I move to the phpshell (now tecmint-nix) folder and rename phpshell.php to index.php so that you are redirected directly to the index page and not the contents of the folder.

# mv phpshell-2.4 tecmint-nix 
# cd tecmint-nix/
# mv phpshell.php index.php

Fine, Its time to open your Web browser and navigate to “http://127.0.0.1/tecmint-nix“.

PHP Shell Login Screen

PHP Shell Login Screen

By default no username or password will work, hence you need to add username and password manually.

To create a user name and password call the pwhash.php script already in phpshell folder like “http://127.0.0.1/tecmint-nix/pwhash.php“.

PHP Shell Password Hasher

PHP Shell Password Hasher

Enter Username and password on the above php page and click ‘Update‘.

Set PHP Shell Password

Set PHP Shell Password

As stated in the Result section you need to add the sha line as it as by copying and pasting into config.php in the [user] section.

Open config.php file using your favorite editor.

# nano config.php

Add the line.

tecmint = "sha1:673a19a5:7e4b922b64a6321716370dad1fed192cdb661170"

As it is in the [user section], obviously your sha1 will be unique based upon your username and password.

PHP Shell Password Line

PHP Shell Password Line

Save the config.php file with the current changes and exit it.

Now it’s time to login. Visit http://127.0.0.1/tecmint-nix. Login using your ‘User Name‘ and ‘Password‘.

PHP Shell Terminal Access

PHP Shell Terminal Access

Yeah you have successfully logged into your phpshell. Now you can execute most the the shell program as smooth as if you are running those commands and scripts on your own system.

Certain bottlenecks of PHP Shell

  1. No additional input supported, i.e., once a program is launched no interactive script can be used.
  2. All the webserver is configured to timeout at a certain time frame, say 30 sec. This limitation is of webserver/ Apache and not phpshell.
  3. Each command in phpshell must be strictly one liner. Phpshell don’t understand command in continuation or a multi lines command as in loops.

Remember that it’s very important to have PHP Shell password protected, or else everybody will be able so snoop into your files and perhaps also be able to delete them! Please take the time to protect your installation of PHP Shell.

This article is aimed to make you aware of the broader Aspect and implementation of shell in a much lucid way.

That’s all for now, from me. I will soon be here again with another interesting topic you people will love to read. Till then stay tuned and connected to tecmint. Enjoy!

I am a major in computer science, love to research nix. I love to write codes and scripts, review distros, experiment Foss Technologies, write technical articles, Hack, of course Ethically. I am working as System Administrator (nix) for a NGO.

Linux Services & Free WordPress Setup

Our post is simply ‘DIY’ aka ‘Do It Yourself, still you may find difficulties and want us to help you out. We offer wide range of Linux and Web Hosting Solutions at fair minimum rates. Please submit your orders by Clicking Here.

3 Responses

  1. hi ,

    as you told ..php shell is a good one for remote login but i could not able to understand . i have installed it in cent os….. so will you please explain one more time with an example?

  2. Avishek says:

    why don’t u just read the whole article once again, and let us know where you got stuck

  3. vartak says:

    Can we perform any future enhancement in this php shell???

Leave a Reply

This work is licensed under a (cc) BY-NC | TecMint uses cookies. By using our services, you comply to use of our cookies. More info: Privacy Policy.
© 2012-2014 All Rights Reserved.