Since PHP 5.4, you can run PHP scripts and apps with the built-in PHP web server, without needing a common web server such as Apache or Nginx. As long as you have PHP 7.4 installed, you can skip the preceding Apache installation. To start the PHP server, just open a terminal from your project's root directory and run the following command:
$ php -S 0.0.0.0:8181
If you want to start the app from a specific document root directory, such as from the public directory, in the project directory called www, do the following:
$ cd ~/www
$ php -S localhost:8181 -t public
Let's create a classic "Hello World" example that will be served up by this built-in PHP web server to see whether everything is set up correctly:
- Create a simple "Hello World" message page in a PHP file, as follows:
// public/index.php
<?php
echo 'Hello world!';
- Navigate to your project directory and start it with the built...