Is it possible to start a web server from any php web based directory?

Print Friendly, PDF & Email

I recently discovered another way to start a web server from any location for any application written in PHP. As of PHP web developer, I bet all of you are aware of htdocs or www directory sounding very popular in the world of LAMPP or XAMPP. Don’t let you waste your time. I am going to write how to do so instantly.

Steps

To practise this tutorial, I have made a simple web application and pushed it to the blog’s GitHub to help you approach quickly the instruction. The repository can be found at https://github.com/ITersDesktop/phplog.

From your terminal,

  • run git clone to copy this repo to your local working directory.
  • start the server php -s 0.0.0.0:[port-number]. For example, php -S 0.0.0.0:2021 to start the server at the current directory on port 2021.

If you clone the repo into your already established application server which is being used to run PHP based apps, you don’t need to start the server as instructed above. The result will look like this:

Start a PHP server at any directory
Start a PHP server at any directory

The screenshot shows that the server has been started at the address 0.0.0.0 on port 2021. The application can be accessed from http://127.0.0.1:2021.

Comments

The reason why I want to capture the steps and leave them on this blog is to make my work more efficient. So far all we know is that PHP based web applications must be placed in htdocs or www directories of the traditional and common servers recommended using for developing websites with PHP, MySQL as well as Apache. The drawbacks of this way can be shown, for example, the web application is too large to move to those specific directories, my application is trivial so I want to test a feature as quickly as possible. By using this new proposed way, I can stay anywhere on my favourite study or research directory, start a simple web server and begin testing the feature of interest. This approach is similar to the way of running a simple HTTP server with Python introduced and published in this blog.

The job’s done!

As always, all constructive comments are welcomed.

 

One thought on “Is it possible to start a web server from any php web based directory?

  1. Please pay attention to the optional argument S, uppercase. The s lowercase doesn’t not work.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.