Skip to main content

Running a Web Server with PHP

If you want to run a PHP server directly without Docker, you can use PHP's built-in web server, which is convenient for development purposes. Here’s how you can set it up to run on port 8080:

Running PHP Server Locally

  1. Navigate to Your PHP Application Directory:

    Open a terminal or command prompt and navigate to the directory where your PHP files are located. For example:

    cd /path/to/your/php-app
    
  2. Start PHP Built-In Web Server:

    Use the php command with the -S flag to start the PHP built-in web server:

    php -S localhost:8080
    

    This command starts a web server locally on port 8080, serving files from the current directory (/path/to/your/php-app).

  3. Access Your PHP Application:

    Once the server is running, open your web browser and go to:

    http://localhost:8080
    

    You should see your PHP application running.

  4. Develop and Test:

    You can now develop and test your PHP application locally. Any changes you make to PHP files will be immediately reflected in the running server.

Additional Notes:

  • PHP Built-In Server: This is suitable for development purposes but may not be as robust or feature-rich as a full web server like Apache or Nginx in a production environment.

  • Routing: PHP's built-in server supports PHP scripts directly and basic routing. For more complex routing or features, consider using a framework like Laravel, Symfony, or a micro-framework like Slim or Lumen.

  • Stopping the Server: To stop the PHP built-in server, go back to your terminal or command prompt and press Ctrl + C.

This method allows you to run PHP applications locally without Docker, leveraging PHP's built-in capabilities for development and testing. Adjust paths and configurations based on your specific project setup and requirements.