Skip to content

iforemann/create-laravel-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Laravel Project Initializer Script

A standalone shell script to quickly scaffold a new Laravel project using Docker (via laravel.build). It allows specifying services like PostgreSQL, Redis, Meilisearch, etc. It automatically sets up a .test domain, attempts to update your /etc/hosts file, and starts the Laravel Sail containers.

This script is designed primarily for macOS users due to its use of sed -i "" and macOS-specific DNS flush commands.

Features

  • Creates a new Laravel project in a directory of your choice.
  • Uses laravel.build to scaffold the project.
  • Allows specifying a comma-separated list of services (e.g., pgsql,redis,meilisearch) to be installed with Sail. If no services are specified, laravel.build's default services will be used (typically includes MySQL, Redis, Meilisearch, Mailpit, Selenium).
  • Configures the project's .env file to use a local .test domain (e.g., http://project-name.test).
  • Attempts to automatically add the corresponding entry to your /etc/hosts file (may require sudo password).
  • Automatically starts the Laravel Sail (Docker) containers in detached mode (./vendor/bin/sail up -d).
  • Provides feedback throughout the process.

Prerequisites

  • macOS (the sed command sed -i "" is specific to macOS/BSD sed).
  • Docker Desktop must be installed and running.
  • curl must be installed.
  • A shell like Bash or Zsh.

Installation & Setup

  1. Download the Script: Save the script content (provided separately) into a file named create-laravel-project.sh (or any name you prefer).

  2. Make it Executable: Open your terminal, navigate to the directory where you saved the file, and run:

    chmod +x create-laravel-project.sh
  3. Optional: Move to a PATH Directory: To run the script from anywhere without specifying its full path, you can move it to a directory included in your system's PATH (e.g., /usr/local/bin or ~/bin). Example:

    sudo mv create-laravel-project.sh /usr/local/bin/create-laravel-project

Usage

Once installed and executable:

# If in PATH and named 'create-laravel-project'
create-laravel-project <project-name> [comma,separated,services]

# Or, if in the current directory
./create-laravel-project.sh <project-name> [comma,separated,services]

Examples

  1. Create a project myblog with default services provided by laravel.build (e.g., MySQL, Redis, Meilisearch, etc.):
create-laravel-project myblog

or

./create-laravel-project.sh myblog
  1. Create a project crm with only PostgreSQL and Redis:
create-laravel-project crm pgsql,redis

or

./create-laravel-project.sh crm pgsql,redis

The script will then:

  1. Create a directory for your project.
  2. Install Laravel with the specified (or default) services using Sail.
  3. Configure .env for the .test domain.
  4. Attempt to update /etc/hosts.
  5. Start the Sail containers.
  6. Output the project URL.

Important Notes

  • Sudo Password: The script will attempt to modify your /etc/hosts file, which requires administrator privileges. You may be prompted for your sudo password.
  • Docker: Ensure Docker Desktop is running before you execute the script.
  • DNS Flushing: If the new .test domain isn't resolving, you might need to flush your DNS cache.
  • Error Handling: The script includes basic error checking. If any step fails, check the terminal output for error messages.
  • Current Directory: After the script finishes, your terminal's current directory will be the same as where you ran the script. You'll need to manually cd your-project-name to navigate into the newly created project directory.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages