rseletsk wrote a reply+100 XP
1w ago
Please briefly explain how you use github as opposed to 'build'?
rseletsk liked a comment+100 XP
2w ago
Certainly! Here’s a detailed solution for your Laracasts question:
Yes, using the app:build command provided by Laravel Zero is the recommended (and best) approach to generate a standalone, packaged executable of your CLI app for end users.
Explanation
What does app:build do?
- The
app:buildcommand leverages Box, which is bundled with Laravel Zero. - This process compiles your entire application, including dependencies from the
vendordirectory, into a single executable PHAR file. - The resulting
.phar(PHP archive) is what you should distribute to your users. They won't need to install Composer or any PHP dependencies to run your CLI app.
How to Use
From your project root, run:
php application app:build
Replace application with the entry point of your Laravel Zero app, if you renamed it.
This will generate a packaged executable (e.g., application.phar) in the builds directory.
What to Distribute
- Distribute only the generated
.pharfile to your users. - Users can execute your CLI app by running:
(Or make it executable and runphp yourapp.phar./yourapp.phar.)
Benefits
- Clean: Your users don't see your app structure or dependencies.
- Standalone: No Composer or Laravel Zero knowledge required for your users.
- Efficient: Smaller, more portable deliverable.
In summary:
Yes, app:build is the best and recommended way to package and distribute your Laravel Zero CLI application.
Reference:
Laravel Zero Documentation – Compiling an Application
Let me know if you have any follow-up questions!
rseletsk started a new conversation+100 XP
2w ago
Have a working laravel-zero CLI app with the entire app structure (ex: vendor directory). Is using appName app:build 'best' to generate a 'packaged' executable for the user?
rseletsk liked a comment+100 XP
2w ago
Ok thank you.
When you need help, it's important to share with us all the informations you can give us.
Without knowing that you were using laravel-zero, it's not possible for us to guess.
So now restart from the beginning ... what have you done step by step until you get the error ?
Step 1 : ... ?
Step 2 : ... ?
...
rseletsk wrote a reply+100 XP
2w ago
Step 1: (Using WSL) Create Laravel CLI 'stub' via laravel-zero new appName Step 2: Update appName to get some functionality working Step 3: Testing -> Verify appName working via ./appname exampleCommand Step 4: Deploy app: php appName app:build -> creates a builds directory with appName Step 5: Cd builds and execute via ./appName exampleCommand Step 6: Get runtime error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at ... /builds/appName/bootstrap/../.env]. This runtime error is due to there not being a appName directory under builds directory (there is appName executable under builds) Notes: Code in bootstrap/app.php: $dotenv = Dotenv\Dotenv::createImmutable(DIR . '/../');
Why is DIR not returning the full path of the file currently being executed (.../builds) and instead returning (.../builds/appName/bootstrap) ?
Certainly looks like the built appName is returning a different directory path than the Testing appName (since the latter works as expected)
rseletsk wrote a reply+100 XP
2w ago
Code in bootstrap/app.php: $dotenv = Dotenv\Dotenv::createImmutable(DIR . '/../');
Why is DIR not returning the full path of the file currently being executed (.../builds) and instead returning (.../builds/appName/bootstrap) ?
rseletsk wrote a reply+100 XP
2w ago
Ok: Here is summary of current status of issue: Did deploy process of appName app:build which created appName in the (new) builds directory When execute appName get runtime error Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at ... /builds/appName/bootstrap/../.env]. This runtime error is due to there not being a appName directory under builds directory (there is appName executable under builds)
Why is it looking for appName directory under builds directory?
rseletsk liked a comment+100 XP
2w ago
Do you, though? In which path is it? The error clearly says it doesn't exist, or it's not readable due to improper permissions.
rseletsk liked a comment+100 XP
2w ago
Easiest is to use github, other than that you can use a mounted share, or a regular usb stick.
rseletsk wrote a reply+100 XP
2w ago
From created a Laravel CLI app via laravel-zero new applicationName
rseletsk wrote a reply+100 XP
2w ago
From created a Laravel CLI app via laravel-zero new applicationName
rseletsk wrote a reply+100 XP
2w ago
From created a Laravel CLI app via laravel-zero new applicationName
rseletsk wrote a reply+100 XP
2w ago
Is best practice to deploy the application to production with app:build and use the production executable?
rseletsk wrote a reply+100 XP
2w ago
On remote serverthe appname above the builds directory executes without any runtime error
rseletsk wrote a reply+100 XP
2w ago
On local laptop (WSL) the appname above the builds directory executes without any runtime error
rseletsk wrote a reply+100 XP
2w ago
On local laptop (WSL): php appname app:build does work are generates the deployed executable appname under the builds directory. But, when execute appname (via ./appname) get: PHP Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at ... bootstrap/../.env].
rseletsk wrote a reply+100 XP
2w ago
php appname app:build -vvv results in runtime error: [_HumbugBox6ab58bf96c33\KevinGH\Box\Composer\Throwable\UndetectableComposerVersion] Could not detect the Composer version: The command "'/usr/local/bin/compose r' '--version' '--no-ansi'" failed.
Exit Code: 1(General error)
Working directory: /home/whatever
Output:
PHP's phar extension is missing. Composer requires it to run. Enable the ex tension or recompile php without --disable-phar then try again.
rseletsk wrote a reply+100 XP
2w ago
ALready have .env there
rseletsk started a new conversation+100 XP
2w ago
Executing app resulting from app:build results in a runtime error: PHP Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at ... bootstrap/../.env].
rseletsk liked a comment+100 XP
2w ago
Certainly! Here’s a step-by-step solution to move a Laravel application to another computer, even if the operating systems are different:
Steps to Move a Laravel Application to Another Computer
-
Copy the Project Files
- Copy your entire Laravel project directory (excluding
/vendorand/node_modulesfolders as they can be large and can be restored). - Optionally, you can use Git to pull from a repository if your project is version-controlled.
- Copy your entire Laravel project directory (excluding
-
Install PHP, Composer, and Other Requirements
- Make sure the new computer has PHP (match your Laravel version requirements), Composer, and a web server (like Apache or Nginx) installed.
- Install Node.js and npm if you use frontend assets built with Mix/Vite.
-
Transfer the Project
- Paste/move your project folder into the desired directory on the new machine.
-
Install Composer Dependencies
- In your new machine, open a terminal in the project root and run:
composer install
- In your new machine, open a terminal in the project root and run:
-
Install Node Dependencies (Optional)
- If you use Laravel Mix or Vite for assets:
npm install - Then build your assets as needed:
npm run dev # or for production: npm run build
- If you use Laravel Mix or Vite for assets:
-
Set Up Environment Configuration
- Copy
.env.exampleto.env:cp .env.example .env - Update
.envwith the new database, mail, and other relevant settings for the new environment.
- Copy
-
Generate Application Key
php artisan key:generate -
Set Up the Database
- Create a new database on the target machine.
- If you have an existing database, export it (
mysqldump, phpMyAdmin, etc.) from the old computer and import it to the new one.
-
Run Migrations/Seeders (if needed)
php artisan migrate --seed- Only if you want to migrate and seed the database from scratch.
-
Set Correct Permissions (Linux/Mac)
chmod -R 775 storage bootstrap/cache -
Start the Application
- Start the local development server:
php artisan serve - Or set up your web server (Apache/Nginx) to serve the project.
- Start the local development server:
That’s it! Your Laravel app should now be running on the new computer.
Extra Tips:
- Don’t forget to transfer any storage/app/public files if your app uses local file storage.
- If you’re using git, pushing/pulling your code makes transfer much easier.
- If you face permission issues, verify your web server user has access to the necessary directories.
rseletsk started a new conversation+100 XP
2w ago
Looking for basic steps to move a Laravel application to another computer (different Operating System)