Loading...

How to PHP Built-in Web Server

View: 484    Dowload: 0   Comment: 0   Post by: hanhga   Category: Php&mySql   Fields: Other

Starting from PHP 5.4 , PHP incorporates a feature of  a built-in web server. You can take the advantage of  PHP built-in web server for development and testing of your PHP applications. It means you don’t need to configure Apache to run your PHP applications.

If you have already installed LAMP , WAMP, XAMPP on your system, still you can try and use this feature.

To use PHP built-in web server you need PHP 5.4 or higher version. If you are not sure which PHP version you have installed on your machine, just open the terminal and type a simple command (php -v).

php -v
 
PHP 5.5.9-1+sury.org~precise+1 (cli)(built: Feb 13 2014 15:53:53)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
   with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

I have already installed PHP version 5.5 .

To check some of the options by typing PHP -h (PHP help command) on a terminal

php -h
 
 -a Run as interactive shell
 -c <path>|<file> Look for php.ini file in this directory
 -n No php.ini file will be used
 -d foo[=bar] Define INI entry foo with value 'bar'
 -e Generate extended information for debugger/profiler
 -f <file> Parse and execute <file>.
 -h This help
 -i PHP information
 -l Syntax check only (lint)
 -m Show compiled in modules
 -r <code> Run PHP <code> without using script tags <?..?>
 -B <begin_code> Run PHP <begin_code> before processing input lines
 -R <code> Run PHP <code> for every input line
 -F <file> Parse and execute <file> for every input line
 -E <end_code> Run PHP <end_code> after processing all input lines
 -H Hide any passed arguments from external tools.
 <strong>-S <addr>:<port> Run with built-in web server.</strong>
 <strong>-t <docroot> Specify document root <docroot> for built-in web server.</strong>
 -s Output HTML syntax highlighted source.
 -v Version number
 -w Output source with stripped comments and whitespace.
 -z <file> Load Zend extension <file>.

Look at the line marked in bold (-S, -t) this is the option for running PHP built-in web server.

How to Start with PHP Built-in Web Server

To use a PHP built-in web server, go to the root directory of your project and run this simple command on a terminal

php -S localhost:8000

Using this command a simple Web Server will run and listen to a port 8000. You can specify any port. If specified port is used by some other process, it will throw an error.

// If port is not free, then error is thrown.
 
[Sat Oct 25 10:43:00 2014] Failed to listen on localhost:8080 (reason: Address already in use)

When a web server is running successfully then the following output  will be displayed on a terminal.

PHP 5.5.9-1+sury.org~precise+1 Development Server started at Fri Oct 24 23:37:53 2014
Listening on http://localhost:8000
Document root is /var/www

When a web server is started, by default your current directory is your document root . If you want to change the document root, you can specify them with -t flag.

// Specify Document Root /var/www/laravel
 
php -S localhost:8000 -t /var/www/laravel

As per PHP Manual :

Warning : This web server was designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network.

Conclusion

Remember this is a great feature for testing your PHP applications but it’s not a full-featured web server.

I have written this post based on my experience with PHP built-in web server. If you are using this feature and you want to add something, you can let us know through your comment.

How to PHP Built-in Web Server

Starting from PHP 5.4 , PHP incorporates a feature of a built-in web server. You can take the advantage of PHP built-in web server for development and testing of your PHP applications. It means you don’t need to configure Apache to run your PHP applications.

Posted on 21-09-2016 

Comment:

To comment you must be logged in members.

Files with category

  • Twitter-like Hashtag Function in PHP

    Twitter-like Hashtag Function in PHP

    View: 42    Download: 0   Comment: 0

    Category: Php&mySql     Fields: none

    If you ever want a function to hashtag and style words within a string which has '#' next to it like twitter. This piece of code will help

  • PSITS Automated Voting System

    PSITS Automated Voting System

    View: 72    Download: 8   Comment: 0

    Category: Php&mySql     Fields: none

    A free sourcecode for PSITS Automated Voting System develop in PHP programming language. The purposed of the system is to automate the process of voting and maintain the quality of data

  • PHP-University Application System

    PHP-University Application System

    View: 74    Download: 10   Comment: 0

    Category: Php&mySql     Fields: none

    Greeting from Malawi the warm heart of Africa. I developed this university registration system project just to share with the people who can make use of the project like this and at the same time for others like students who can learn from it. This...

  • School Event Management System in PHP/MSQLi

    School Event Management System in PHP/MSQLi

    View: 69    Download: 0   Comment: 2

    Category: Php&mySql     Fields: none

    This School Event Management System can create school events such as Volleyball games, Basketball, Cultural presentation, Election of school officers etc . During school election Instead of having a compile list of candidates and voters this system...

  • Resort Reservation System with PayPal/Credit Card/Debit Card Payment

    Resort Reservation System with PayPal/Credit Card/Debit Card Payment

    View: 57    Download: 0   Comment: 0

    Category: Php&mySql     Fields: none

    This reservation system has the ability to help its customers find available rooms, cottages and even function hall for their convenience . And in here, they will also have the idea of the room rates where they can quickly reserve for their family...

  • Activity log

    Activity log

    View: 58    Download: 0   Comment: 0

    Category: Php&mySql     Fields: none

    Simple program to track user's activity log-in time and online/offline status.

  • Electricks - eCommerce

    Electricks - eCommerce

    View: 58    Download: 0   Comment: 0

    Category: Php&mySql     Fields: none

    Electricks is an e-commerce website built using PHP, Bootstrap and some jQuery plugins. It has all the major functionalities of a typical e-shop. This project was used to present in Southern Luzon State University - Lucban. Feel free to use this code...

  • Simple Email App Using PHP

    Simple Email App Using PHP

    View: 50    Download: 0   Comment: 0

    Category: Php&mySql     Fields: none

    Creating a simple PHP script using mail function for sending out emails.

 
File suggestion for you
Loading...
File top downloads
Loading...
Loading...
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd