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.
- 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 requiresudo
password). - Automatically starts the Laravel Sail (Docker) containers in detached mode (
./vendor/bin/sail up -d
). - Provides feedback throughout the process.
- macOS (the
sed
commandsed -i ""
is specific to macOS/BSD sed). - Docker Desktop must be installed and running.
- curl must be installed.
- A shell like Bash or Zsh.
-
Download the Script: Save the script content (provided separately) into a file named
create-laravel-project.sh
(or any name you prefer). -
Make it Executable: Open your terminal, navigate to the directory where you saved the file, and run:
chmod +x create-laravel-project.sh
-
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
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]
- 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
- 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:
- Create a directory for your project.
- Install Laravel with the specified (or default) services using Sail.
- Configure .env for the .test domain.
- Attempt to update /etc/hosts.
- Start the Sail containers.
- Output the project URL.
- 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.