Launching is as Easy as:
Open your terminal and navigate to the public folder within your Barebone project.
Execute the following command to launch the server:
./launch-server.sh
This single line initiates the entire launch process, including:
Prompting for a Port:
The script pauses and presents a prompt:
Port number: (default: 8888)
You can choose:
Opening Your Browser:
http://localhost:$PORT/barebone/, where $PORT reflects the chosen port
number.Running the Local PHP Server:
Stopping the Local PHP Server:
Understanding the Script:
While the command itself might seem straightforward, the underlying script (launch_server.sh) takes care of the details:
#!/bin/bash
# Ask which port to use default 8888 must be > 1000 or you need sudo
read -e -p "Port number:" -i "8888" PORT
# Open browser before running server for user experience
sensible-browser http://localhost:$PORT/barebone/
# Run local php server using chosen port
php -S localhost:$PORT
This script provides several benefits:
Remember:
sensible-browser command, which is a tool designed to launch
the appropriate web browser based on your system's configuration. It instructs the browser to open the Barebone application at
http://localhost:8888/barebone/.php command. The -S flag
enables server mode, and the subsequent parameters localhost:8888 specify the host and port to bind the server to (localhost and port 8888 in
this instance).Here's a breakdown of the index.php file, serving as the starting point for your Barebone
application:
<?php
/* remove this when you are sure the file exist to save a disk-read */
if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
die('RUN COMPOSER FIRST!');
}
/* composer autloader */
require_once '../vendor/autoload.php';
$app = new \Barebone\Application();
$app->disableDebugger();
$app->run();
1. Checking for Composer:
if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
$ composer
install first2. Loading Composer Autoloader:
require_once '../vendor/autoload.php';
3. Initializing the Applications:
$app = new \Barebone\Application();
4. Enabeling / Disabling Debugger:
$app->disableDebugger();
$app->enableDebugger();
5. Running the Application:
$app->run();
In essence, this index.php file serves as the gatekeeper and orchestrator of your applications. It
ensures essential files are included, checks for necessary dependencies, initializes the core application class, and then commences the application's core
functionality.