Based on the error message youβve posted:
[ErrorException]
chdir(): No such file or directory (errno 2)
during the PHAR build process with Laravel Zero (via Box), this typically means that Box is trying to change to a directory that no longer exists or is incorrect in your config or project setup.
Hereβs how to troubleshoot and resolve it:
1. Check for a valid working directory in your box.json
If your box.json uses a cwd (current working directory) or any directories settings, make sure all paths are correct and exist. Itβs common for directory structure to change, or typos to sneak in.
Example from a box.json:
{
"directories": ["app", "bootstrap", "config", "vendor"],
...
}
If those folders are missing or misnamed in your project root, Box could fail.
2. Verify your composer.json "bin" setting
If you set a custom bin path in composer.json, ensure that file exists, is executable, and points to a valid script.
Example:
{
"bin": [
"canvassettings"
]
}
Does canvassettings exist in your project root? Is it executable (chmod +x canvassettings)?
3. Missing or Misplaced Files
From your build log:
? Adding binary files
No file found
This hints that your main binary file is missing or not where Box expects it.
- Make sure the
"main"file defined inbox.json(or the default, project root with same name as project) exists and is executable.
Example box.json setting:
{
"main": "canvassettings"
}
You should have a file at:
/home/rsatpriv/canvassettings/canvassettings
If not, create one or update the path in box.json.
4. Auto-discovery Confirmation Problem
From your log:
? Auto-discover files? No
If you answered "No" and misconfigured file inclusion, Box might not be able to gather the correct files, leading to issues. Consider answering "Yes", or manually curate your included files in box.json.
5. Running from Proper Project Root
Box (and Laravel Zero) expects you to run the build from your project root folder. If you run the build command from a different directory, relative paths can break!
Always run:
php ./vendor/bin/laravel-zero app:build
from the root of your project.
6. General Recommended Solution to Your Error
Double check:
- Your main binary path (as set in
box.json) exists and is executable. - All paths in
box.json(directories,main, etc.) are valid. - Youβre running commands from the root project directory.
- Your working directory exists and is accessible.
Example: Project Structure
Your project directory should look something like:
canvassettings/
βββ app/
βββ bootstrap/
βββ config/
βββ vendor/
βββ canvassettings <-- this file should exist and be executable
βββ composer.json
βββ box.json
Sample box.json
Adjust to fit your setup:
{
"main": "canvassettings",
"output": "canvassettings.phar",
"directories": [
"app",
"bootstrap",
"config",
"vendor"
],
"files": [
"composer.json",
"artisan" // if you have a custom binary, reference it here
]
}
Make sure the main file exists.
Final Checklist
mainscript exists and is executable:ls -l canvassettings # if missing or not executable: touch canvassettings chmod +x canvassettings- Run build from project root.
- Check your
box.jsonpaths. - Re-run your build:
or (if debugging)php ./vendor/bin/laravel-zero app:build./vendor/laravel-zero/framework/bin/box compile --config box.json --debug
Summary
The error is almost always due to a missing or misconfigured binary (main) file, or invalid working directory specified in box.json. Double check the paths, ensure all referenced files exist, and run the build from the correct directory.
If you continue having trouble, please paste:
- The contents of your
box.json - Your directory tree (output of
tree -L 2 .) - The full command you are running
for more specific diagnostics.