Launching Your Barebone studio with Confidence

Launching is as Easy as:

  1. Open your terminal and navigate to the public folder within your Barebone project.

  2. Execute the following command to launch the server:

    Bash
    ./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:

      • Press Enter to accept the default port (8888).
      • Type a valid port number and press Enter to use that port. This chosen value will be used for launching the server.
  • Opening Your Browser:

    • The script opens your web browser, directing you to the Barebone GUI at http://localhost:$PORT/barebone/, where $PORT reflects the chosen port number.
  • Running the Local PHP Server:

    • Behind the scenes, the script starts a local PHP server using the chosen port. This allows your Barebone application to process requests and function properly.
  • Stopping the Local PHP Server:

    • To stop the server press ctrl-c. Or you could kill the process yourself in your taskmanager.

Understanding the Script:

While the command itself might seem straightforward, the underlying script (launch_server.sh) takes care of the details:

Bash
#!/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:

  • User-friendly Port Selection: You can customize the port used by the server, offering flexibility in your development environment.

Remember:

  • Refresh the page if needed: If you see a "server not found" message initially, simply wait a few seconds and refresh the page.
  • This script streamlines the launch process, provides control over the port selection, and enhances user experience during development.
  • Line 1: This line specifies the interpreter to be used for executing the script, which is the Bash shell in this case.
  • Line 3: This line triggers the 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/.
  • Line 5: This line kicks off a local PHP server using the 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')) {
    :
    This conditional statement verifies the existence of the Composer autoloader file, which manages dependencies automatically.
    • If the file is absent, the script halts with the message "RUN COMPOSER FIRST!", indicating the necessity to install dependencies using Composer. You should simply run $ composer install first

2. Loading Composer Autoloader:

  • require_once '../vendor/autoload.php';
    :
    If the Composer autoloader is present, it's included to enable automatic loading of classes and files from installed dependencies.

3. Initializing the Applications:

  • $app = new \Barebone\Application();
    :
    This line creates a new instance of the Barebone application class, laying the foundation for handling requests and responses to all applications.

4. Enabeling / Disabling Debugger:

  • $app->disableDebugger();
    :
    This disables debugging functionality, potentially to enhance performance or for security reasons.
  • $app->enableDebugger();
    :
    This enables debugging functionality, never use this in production for security reasons.

5. Running the Application:

  • $app->run();
    :
    This pivotal line initiates the application's main execution process, triggering it to start handling incoming requests and generating responses.

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.