Hot File

How to PHP Built-in Web Server

View: 287    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: Php&mySql   Fields: Other

0 point/0 review File has been tested

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.

Introduction

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

How to PHP Built-in Web Server Posted on 21-09-2016  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. 5/10 287

Comment:

To comment you must be logged in members.

Files with category

  • How to Picking the Brains of Your Customers with Microsoft’s Text Analytics

    View: 3806    Download: 0   Comment: 0   Author: none  

    How to Picking the Brains of Your Customers with Microsoft’s Text Analytics

    Category: Php&mySql
    Fields: Other

    2.5/2 review
    With the explosion of machine learning services in recent years, it has become easier than ever for developers to create “smart apps”. In this article, I’ll introduce you to Microsoft’s offering for providing machine-learning capabilities to apps.

  • How to MySqli Tutorial PHP MySqli Extension

    View: 320    Download: 0   Comment: 0   Author: none  

    How to MySqli Tutorial PHP MySqli Extension

    Category: Php&mySql
    Fields: Other

    0/0 review
    PHP provides three api to connect mysql Database.

  • Make Laravel Artisan Commands

    View: 294    Download: 0   Comment: 0   Author: none  

    Make Laravel Artisan Commands

    Category: Php&mySql
    Fields: Other

    0/0 review
    Artisan is the command line tool used in Laravel framework. It offers a bunch of useful command that can help you develop application quickly. Apart from Artisan available commands, you can create your own custom commands to improve your workflow.

  • Check if a Number is a Power of 2

    View: 278    Download: 0   Comment: 0   Author: none  

    Check if a Number is a Power of 2

    Category: Php&mySql
    Fields: Other

    2.25/2 review
    How to check if a number is a power of 2. To understand this question, let’s take some example.

  • Concatenate columns in MySql

    View: 341    Download: 0   Comment: 0   Author: none  

    Concatenate columns in MySql

    Category: Php&mySql
    Fields: Other

    0/1 review
    Artisan is the command line tool used in Laravel framework. It offers a bunch of useful command that can help you develop application quickly. Apart from Artisan available commands, you can create your own custom commands to improve your workflow

  • How to Query NULL Value in MySql

    View: 269    Download: 0   Comment: 0   Author: none  

    How to Query NULL Value in MySql

    Category: Php&mySql
    Fields: Other

    5/1 review
    Misunderstanding NULL is common mistake beginners do while writing MySql query. While quering in MySql they compare column name with NULL. In MySql NULL is nothing or in simple word it isUnknown Value so if you use comparison operator for NULL values...

  • How to Abstract Class in PHP

    View: 308    Download: 0   Comment: 0   Author: none  

    How to Abstract Class in PHP

    Category: Php&mySql
    Fields: Other

    0/0 review
    What is an abstract class in PHP and when to use an abstract class in your application. In this tutorial, we’ll learn about abstract class and their implementation.

  • Use Enums in Rails for Mapped Values

    View: 283    Download: 0   Comment: 0   Author: none  

    Use Enums in Rails for Mapped Values

    Category: Php&mySql
    Fields: Other

    2.5/2 review
    When I worked in a call center, we used to mark cases with different statuses. This allowed upper management to get a handle on where cases stood, what the bottlenecks were and flow of calls. Thankfully it has been a long time since I worked in a...

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd