Either I miss something, or the whole chain lacks something.
Here's my assumption:
The whole point of containerization in development, is to reduce the cost of environment setup, and create a prepared image with all the required pieces.
So, when I read that Laravel Sail is installing laravel via containerization, I get excited. Thus I install it via their instructions, and everything works.
Then the problem begins. Because:
After a successful installation, I create a git repo, with GitHub's default laravel .gitignore
Then I push the newly installed laravel app into my git repo.
Then I ask a developer to start developing it. Please note that:
He does not have PHP installed
He does not have Composer installed
He clonse the repo, and as per installation guide, runs ./vendor/bin/sail up
But ./vender folder is correctly excluded in .gitignore
Thus his command results in:
bash: ./vendor/bin/sail: No such file or directory
He Googles it of course, and finds out that people suggest to run composer update
He goes to install composer, then before that PHP, then all extensoins of PHP, then ...
Do I miss something here? The whole point of containerization was to not install the required environment locally.
What is the proper way of running a laravel app, that is not installed from https://laravel.build, but is cloned from a git repo, WITHOUT having PHP or Composer installed locally?
Update
I found Bitnami laravel docker and it's exactly what containers should be.
You are right and the other developer doesn't need to have php nor composer installed.
All he/she needs is Docker installed on the local machine.
If you scaffolded the project with what is mentioned in the official Laravel docs under the Getting started section, then you will have a docker-compose.yml file in your project root directory.
For Windows
For Linux
For Mac OS
All the developer has to do after git cloning the repository is to run
docker-compose up --build -d
That's it.
For those struggling with this issue... I've found a command that work perfectly fine.
First of all, you don't need to locally have any PHP or Composer installed, maybe there is a misunderstanding about it, all you need is Docker.
Docker will install everything you need in something I understand is like a sandbox, not locally, for each project.
And for those downloaded projects, from GIT as example, that does not have vendor folder, and obviously cannot execute sail up you can simple execute:
docker run --rm --interactive --tty -v $(pwd):/app composer install
That command will download a composer image for docker, if you do not have one yet. Then, will run a composer install and you are free to execute a ./vendor/bin/sail up if you hadn't configured an alias or just sail up if you already configure an alias.
That's all.
The official documentation lists the following command.
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
If you were to clone a Laravel project and run this command in the project root, it would create a very small container with php and composer installed and run composer in the project root to install all php dependencies. In effect, this installs the Laravel core code into the cloned project. Once the project in set up this way, the user should create a local .env file to match their development evironment.
cp .env.example .env # creates a .env file to be populated for the local environment
With the envronment set up, they can now create the application containers in docker and run the application. Laravel provides the Sail helper for this.
./vendor/bin/sail up -d # runs the docker containers in detached mode
Now it's a matter of setting up the laravel app and running the Laravel app. (I'm assuming the app uses one of the Laravel start kits that rely on Node.js. If you are using a Blade only application, you can skip the "npm" commands.)
sail artisan key:generate # (Best Practice) Generate a new application key on each machine
sail artisan migrate # Scaffold the database structure
sail artisan db:seed # (Optional) Seed the database with data
sail npm install # (Optional) Install front-end dependencies (Inertia, Vue, React, others...)
sail npm run dev # (Optional) Run the front-end framework in development mode
With this, the new developer should be running an exact copy of both the project and the development environment as the original developer.
Your project README may include additional steps to set up some other dependencies, but this is the basic workflow for contributing to a Laravel project.
The only prerequisites for this workflow is to have Docker installed with an Internet connection. This is most easily accomplished on Windows, Mac, and Linux by installing Docker Desktop.
Alternate for Older Projects
If you are working on an older project that doesn't use Laravel Sail, but does have a docker-compose.yml file, you should be able to build and run the necessary containers with the following command.
docker-compose up --build -d
Once you have the containers running, you would need to install the project dependencies directly into the container.
docker ps # find the container ID of your project's container
docker exec -it CONTAINER_ID php artisan key:generate
docker exec -it CONTAINER_ID php artisan migrate
docker exec -it CONTAINER_ID php artisan db:seed
docker exec -it CONTAINER_ID npm install
docker exec -it CONTAINER_ID npm run dev
Of course, Docker Desktop simplifies this process. With a button click you can have a terminal shell open directly in your container eliminating the need for the docker exec command.
I used to use forge for deploying my laravel application to production. I recently deregisted forge and I wanted to deploy via ssh to ubuntu server on my own.
I did composer update and I pull changes to my server via ssh; but after these my application started to give error 500. I did every thing I searched may be useful such as commands below but nothing worked.
does any one know why am I facing is this error? in local environment every thing works properly and my laravel project worked properly before ssh and composer update.
these are the steps I have go through but nothing worked:
deleting vendor folder and reinstalling composer
changing permisions for bootstrap and also for the whole project :
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
run composer dump-autoload
php artisan config:cache
composer update and sudo composer update
I also tried these commands but none of them worked:
php artisan view:clear
php artisan config:cache
php artisan cache:clear
php artisan config:clear
I am using laravel 8
my .env file also exists and every thing are set there
when I turn on debug mode the error of the application page is like this:
Target class [hash] does not exist.
please helpme if any one has any experience on this problem.
From russia /ivorycoat
delete vendor
composer update
.env.example copy and create .env
php artisan cache:clear
php artisan config:clear
php artisan key:generate
php artisan serve
How do you to setup a Git Repo for a Laravel Project to run after cloning from a remote host like Gitlab, Guthub or Bitbucket? After cloning a Laravel repo to a local computer php artisan serve gives this error 'PHP Warning: require(D:\MyGitLab\laravel-project/vendor/autoload.php): failed to open stream: No such file or directory '. This means simply cloning does not work. What is the solution? I added all files and directories to origin repo.
Make a copy of .env.example to .env file.
Make database and link it from .env file.
Run composer update command
Run php artisan key:generate command
Install Bower, NPM or any other front end package if you are using.
Run php artisan migrate command.
Run php artisan serve command.
You are good to go!!!
run
php artisan key:generate
That should work.
You need to run
composer update
first to install package dependency and run
php artisan serve
and run
php artisan key:generate
I have a webhook for my application that currently does this:
cd /var/www/html; git pull origin master; /usr/local/bin/composer dump-autoload; php artisan migrate
I've been able to get all the commands above to work except the composer dump-autoload command.
When I log into the server as ec2-user and run sudo -u apache /usr/local/bin/composer dump-autoload, the command runs. But if I hit the endpoint that runs this command through a PHP script using shell_exec, this does not work.
Is there a way for me to get apache user to run this command on its own?
This should be doable by modifying your sudoers file.
visudo
Add the line:
ec2-user ALL=(apache) NOPASSWD: /path/to/script.sh
Don't forget to check if the apache user does have writing privileges under Laravel directory. composer will try to write in 'vendors' directory.
Regards.
I am currently running the laravel 4 development server using:
php artisan serve
Now when uploading a file into a folder, I guess it is not working, because the server has
no write permissions. How can I set write permissions on mac for artisan php serve?
For example on Linux I have apache apache as owner and group. What does artisan use. Thank you.
Well, the artisan serve command will run under the permissions of the currently logged in user. If you need to run it using any other user you'll have to tell your system:
sudo su - <loginname> php artisan serve
I'm not sure if you should run it as apache:
sudo su - www-data php artisan serve
or
sudo su - httpd php artisan serve
Because apache may not have the environment set to run php.
But you can simply run it as root:
sudo php artisan serve
And root has rights to write files pretty much everywhere in your system.