Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

phpMick's avatar

Clone a Laravel Project

What is the best way to do this?

I want to copy my dev project, so i can have a test environment.

I'm just going to copy them on the same server.

Should I just copy the folder, or create a new Laravel project, hook up to GIT and clone?

Mick

0 likes
19 replies
phpMick's avatar

So,

I have a test branch and a development branch.

To create my test environment. Create a new Laravel project and then do a git clone?

Mick

igor_talevski's avatar

@Ftoi bad idea is relative :-) ... is not bad if you need it, but if you look in the future is nice to have branching strategy.
Think on scenario when client want some feature ...you start new branch...work on it, merge to test branch and have changes only on one server.... then merge to qa...staging and finally master ... in ideal case this is fine, but what if you decide not to merge... you have two or more new features in parallel... this when your branching strategy can help you to survive with almost no damage :-)

igor_talevski's avatar

@phpMick yes, you clone specific branch to specific env. (don't forget composer install, .env files and other specific env config)

You also can think on CI (Continues Integration) = auto deployment ...

1 like
scsilver's avatar

Using Git or Ansible, Chef, Puppet, Capistrano ...

phpMick's avatar

So, I did a laravel new blahblah The I try to do a git clone into that directory from my remote but it fails because the dir already exists.

What is the correct way to do this?

joedawson's avatar
Level 18

You just clone the repo, there's no need to create a new Laravel project as your repo will already have the Laravel files...

Take the October CMS for example...

git clone https://github.com/octobercms/october.git

Will create a new folder name october with the repo contents. You'd do the same with your remote. To clone to repo into another directory name just append the clone command with a name of your choice.

git clone https://github.com/octobercms/october.git my-folder-name
1 like
igor_talevski's avatar

@phpMick yes, as @JoeDawson ...you don't need to create new project, you just clone your own and specify what branch you will use.
Please read the first link for git flow, you will get more clear picture what we are talking here.

phpMick's avatar

I thought a lot of the framework stuff was git ignored.

Hang on I will have a go.

joedawson's avatar

That's right @phpMick, but you'll just have to run a composer install to pull that all in then you should be set. Just need to consider your config files (copy over your .env from your existing and modify if you're using it).

Then checkout your branch you want to use in the new folder :)

1 like
igor_talevski's avatar

@phpMick yep, same as @JoeDawson tell you... read my comment up...it will also need to create .env file to setup cos it in .gitignore and it will not be copied when you clone from git.
And this is one time only, next time you will just make git pull (and only composer install if you have new packages in composer.json)

phpMick's avatar

Hmmm.

Did a git clone to a new dir. Then composer install.

There is still 20 meg difference and I am getting:

Whoops, looks like something went wrong.

Just having a look in the logs.

production.ERROR: exception 'RuntimeException' with message 'No supported encrypter found. The cipher and / or key length are invalid.' in /var/www/html/selectionTestEnv/bootstrap/cache/compiled.php:70$ Stack trace:

Copied the .env file and it looks like it is working.

phpMick's avatar

Hmm I added some code to AuthenticatesUsers;

$gotPermissions = AccessManager::getPermissions($request);

        if(!$gotPermissions){
            return redirect('/auth/login')->withErrors(['You do not have access to this application.']);
        }

Should I have put this somewhere else?

I just want it to run after login.

igor_talevski's avatar

@phpMick The last question is out of scope of this conversation, you should open another one....

Any case, changing in vendor directory is not ok, it will be overwritten next time you run composer update.

And working with permissions is authorization ....so please use best practice from the documentation: https://laravel.com/docs/master/authorization

phpMick's avatar

Yeah, I understand the permission stuff.

I have some custom code because permissions for all my applications are in a separate db/application.

pratikkdk007's avatar

For cloning the laravel project please go to project file from the Terminal or Command:

git clone "GIT_PROJECT_URL ; "

Go to the project file using cd from

Type composer install

Type cp .env.example .env (copy if using cmd cp for terminal)

Type php artisan key:generate

' Nano .env ' file and change mysql username,database and password.

Type php artisan migrate

Go to "ProjectName.dev" from browser

2 likes
Singhpreeti's avatar

hlww everyone i am clone the project every thing work fine but if try to login then it show only view page means not goto the conroller ... . i am created the controller and set the route .. .please help me ..

Please or to participate in this conversation.