PHP, one of the most popular server-side scripting languages, comes equipped with a built-in web server that provides a convenient way to test and develop web applications locally. This feature is particularly useful during the early stages of development, when setting up a full-fledged web server might be overkill. This tutorial demonstrates how to use PHP built-in web server.
Note: It's crucial to understand that the built-in web server is specifically crafted to facilitate application development. While it proves beneficial for testing and demonstrating applications, it is not designed to function as a full web server. Using it on a public network is strongly discouraged.
For demonstration purposes, we will utilize an empty Laravel application. To begin, create a new Laravel project using Composer with the following command:
composer create-project laravel/laravel example-app
Once it is installed, navigate to the project's root directory:
cd example-app
Now start the PHP built-in web server and bind it to the localhost on port 8000:
php -S localhost:8000 -t public
You can choose a different port if necessary. The -t
option sets the document root of the server. The document root is the directory where the server looks for files to serve. In many PHP frameworks, including Laravel, the entry point for the application is typically in the public
directory.
After running this command, you should see output similar to:
[Sun Dec 10 08:44:30 2023] PHP 8.3.0 Development Server (http://localhost:8000) started
Open the web browser and navigate to http://localhost:8000
. You should see the application running, and you can interact with it just as if it were deployed on a remote server.
Leave a Comment
Cancel reply