Setup Laravel project after cloning - php

So I have just cloned big repo with Laravel project, for the moment this folder (lets call it /var/www/project) does not have vendor folder, .env file, autoload files etc.
Is there some kind of detailed united tutorial with all the steps what should I do next? Install composer (it is already installed on my computer, I have other working projects), generate autoload files and vendors?
Which commands should I run in my console (I have Ubuntu 14.04) to make this folder a working virtual host? Or could someone be so kind to give me all the instructions?

run composer install to generate depedencies in vendor folder
change .env.example to .env
run php artisan key:generate
configure .env
basiclly you need do these things, more info you should check docs

Windows
Go to the project folder
Shift+Right Click -> Open command window here
Mac
Open Terminal, Type "cd " (with a space)
From finder, Drag the project folder
Press Enter to go inside the project folder
Compose
composer install
Generate Key
php artisan key:generate
Setup Database
Open the file .env
(Assuming wamp or xampp)
Edit values to match your database
Add empty database using phpmyadmin
Include that name in the DB_DATABASE
DB_HOST=localhost
DB_DATABASE=students_data
DB_USERNAME=root
DB_PASSWORD=
Get Tables
php artisan migrate
Get default/initial/dummy table values
php artisan db:seed
Run the project
php artisan serve

Install Docker Desktop. See https://laravel.com/docs/8.x/installation for details.
Change working directory to project dir.
Set up sail dependencies:
docker run --rm \
-v $(pwd):/opt \
-w /opt \
laravelsail/php80-composer:latest \
composer install
See https://laravel.com/docs/8.x/sail#installing-composer-dependencies-for-existing-projects for details.
Run the docker container:
vendor/bin/sail up
Connect to MySQL container shell:
vendor/bin/sail exec mysql bash
Inside that shell, create the database:
mysql --password= --execute='create database yourDatabaseName'
exit
Connect to Laravel container shell:
vendor/bin/sail bash
Copy .env file:
cp .env.example .env
Generate application key:
php artisan key:generate
Seed the database:
php artisan migrate:fresh --seed
Visit the site on host machine: http://localhost

1. clone the repo
git clone <l_repo>
2. go into the repo
cd l_repo
3. install require packages
composer install
4. generate the laravel project key
php artisan key:generate
5. migrate and seed at the same time
php artisan migrate:fresh --seed
6A. convert ".env.example" to ".env"
6B. change the 'database name' & 'username' & 'password'
DB_HOST=localhost
DB_DATABASE=own_databse_name
DB_USERNAME=root
DB_PASSWORD=
7. Change the file upload limit for php.ini
upload_max_filesize = 4G
post_max_size = $4G
8. Link with storage
php artisan storage:link
9. start the server
php artisan serve

Follow the Install Laravel documentation:
https://laravel.com/docs/5.2#installation

First of all, if there's no vendor folder - you will need to run composer install to get all the packages. It will download all the required dependencies to run the project and also will create an .env file for local development starter.
To configure virtual host in apache, run the following command:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.dev.conf
Here example.dev is a sample virtual host name. Change it accordingly. Now edit it:
sudo nano /etc/apache2/sites-available/example.dev.conf
Here's an example contents for this file:
<VirtualHost *:80>
ServerAdmin admin#localhost
ServerName example.dev
ServerAlias www.example.dev
DocumentRoot /var/www/project/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then you will need to run the following commands to enable virtual host:
sudo a2ensite example.dev.conf
sudo service apache2 restart

For those people using Laravel Sail or that cloned a project that used Sail from source control, I have made Gist with a simple script and some steps to follow after executing the script. It also explains how to set up the .env file with values that work with the Sail stack. If you do not know what stack the project was using you can find out by looking in the docker-compose.yml file. Also, make sure that you have Docker Desktop installed before running the script, information on this can be found on the Laravel docs. Run the script from the root directory of the project.
https://gist.github.com/LaurenceRawlings/3b4f801cafb2e683f45a3b573dad868d

run composer install
rename .env.example to .env
run php artisan serve

Related

How to setup and run laravel, from git?

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.

How to configure Laravel application on localhost?

I'm new to Laravel framework. I have installed and developed a small application. I've got source code from Github for an application which I want to integrate and run on my localhost. Please guide me any link or material where I get proper instructions to start working on this website. Give me details about which file to be edited so that atleast I can access on my localhost.
Github link : https://github.com/fakharkhan/laravel-school-erp
If you don't want to use homestead (which is somewhat complex for beginners to setup) follow this:
steps to setup laravel app from github repo
first of all you need to install git and composer.
open command prompt (terminal) in your document root folder.
clone the repository by executing git clone https://github.com/fakharkhan/laravel-school-erp.git
change directory in terminal to newly cloned project by using cd laravel-school-erp in your case.
run composer install to install project dependencies.
rename .env.example to .env file.
open .env file and enter the database connection information.
run laravel migrations (import database) by executing php artisan migrate from terminal.
visit the url by adding /public to it.
Optional
Setup virtual host by editing httpd-vhosts.conf file (so you can avoid typing /public in the url) and adding following to it
<VirtualHost example.dev:80>
DocumentRoot "C:/xampp/htdocs/laravel/public"
ServerName example.dev
</VirtualHost>
then edit your host file and add following to it:
127.0.0.1 example.dev
You can replace example.dev with whatever URL you like.
You can use Laravel Homestead
https://laravel.com/docs/5.4/homestead
Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine.
You should give a look on Laravel's documentation.
This the best way to understand Laravel.
If you just get the source code you'll need to do some things :
Copy .env.example and rename it .env
Edit .env file to fit on your needs like database informations
Run composer install to install dependencies
Run php artisan key:generate
Assuming you are using xampp on Windows as localhost. Now go to path/to/xampp/htdocs then open git terminal by right click on Git Bash Here
Now run following commands:
1. git clone https://github.com/fakharkhan/laravel-school-erp
2. cd laravel-school-erp
3. composer install
4. cp .env.example .env
5. php artisan key:generate
For database connection: make a database and set (DB_DATABASE, DB_USERNAME, DB_PASSWORD) values to .env file (which is in your project root).
And finally browse: localhost/laravel-school-erp/public

Homestead: command not found- Windows 10 - Tried everything

Receiving bash Homestead command not found
//After running composer global require "laravel/homestead=~2.0"
Changed current directory to C:/Users/Eric/AppData/Roaming/Composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
//Inside my vi ~/.zshrc
export PATH=/Users/eric/AppData/Roaming/composer/vendor/bin:$PATH
export PATH="$laravel:$PATH"
I enabled Virtualization in BIOS
// Inside etc/hosts
Hosts:
127.0.0.1 homestead.app
192.168.10.10 homestead.app
//Inside environmental variables
C:\Users\Eric\AppData\Roaming\composer\vendor\bin
I can't find the homestead.yaml folder and I can't run any homestead commands. Any help with this would be appreciated, thanks!
Assuming that you already have VirtualBox, Vagrant, Git Bash (Git for Windows) installed and working you have two options to install Homestead
Using Git Bash:
Open git bash, navigate to home directory (typically it's C:\Users\{username}) and run
git clone https://github.com/laravel/homestead.git Homestead.
This will download Homestead in C:\Users\{username}\Homestead directory.
Then go to the Homestead installation directory
cd ~/Homestead and run bash init.sh.
This last command will create the Homestead configuration file (homestead.yaml).
Using composer
You need to have PHP and Composer already installed.
Open git bash and run composer global require "laravel/homestead=~2.0" command.
To take advantage of the Homestead CLI, make sure to add the Composer /bin directory to your PATH e.g. command prompt with admin privileges:
set PATH=%PATH%;%USERPROFILE%\AppData\Roaming\Composer\vendor\bin
Then to create the Homestead configuration file (homestead.yaml) you have to run homestead init.
If none of the above don't work you can use Laragon http://laragon.org/.

Troubles with Homestead / Laravel installation (Mac)

I was following these instructions to install homestead on my Mac
http://pastebin.com/48PHSNC2
Homestead installed properly, but when it initialized, it didn't create a Homestead.yaml file. I have no idea how to reinitialize homestead or fix this. Reading through the installation guide Laravel gives you, it suggests using $ bash init.sh to create the .yaml file... unfortunately, this apparently doesn't exist for me either.
I used the composer command to install the CLI:
composer global require "laravel/homestead=~2.0"
Any ideas? I'm stumped...
I ran into a similar issue using Homestead 2.X (I dont care for Homestead 3 ATM).
basically do the following:
find the bash_init.sh file by running sudo find / -name init.sh
cd into the directory it's in, mine was in /Users/me/.composer/vendor/laravel/homestead/init.sh
make it executable, by running chmod +x init.sh
run ./init.sh
...
profit!
You can generate manually by clone git clone https://github.com/laravel/homestead.git Homestead. This will generate homestead.yaml file. Open and edit and change the parameters to fit your system configuration. For further reading
https://dev.to/ko31/installing-laravel-homestead-on-macos-5910

Installing Laravel 4.1 in Windows 7 // Make .phar file globally available to windows command line

i have some problems installing Laravel 4.1 in Windows 7 via the first method explained in the Laravel documentation ( http://laravel.com/docs/installation#install-laravel ).
So I downloaded the laravel.phar file and put it in my path ( System32 ). Which would be the equivalent of /usr/bin in linux based systems?
( I also added .PHAR in the PATHEXT system variable ).
When i ran the laravel command from the command line it didn't know how to open it, so i chose to open it with php.exe. Now, when I run the composer command it says: "Could not open input file: C:\Windows\system32\laravel.phar".
I suppose it's less a problem with laravel itself but my limited knowledge of the Windows command line. The installation via composer works fine.
Any help is appreciated.
To rephrase and clarify this question: How do I make a .phar file globally available to the Windows command line?
Phar allows you to put an entire PHP application into a PHP Archive. It is not a direct executable as you may assume.
To install Laravel 4.1 successfully on Windows 7, you need Composer -a package manager.
First install Composer. This will install globally on your system. Composer can now be called through your command prompt via 'composer'.
Next, go to where your WAMP or XAMP project folder is -generally, this would be your www folder (i.e. C:\wamp\www).
Make a new project directory: www\new_project. Now go to your start menu and run cmd as admin. Next you need to change your directory to the C drive and then into your www\new_project folder:
C:\> cd wamp\www\new_project
Now you can take advantage of composer by calling:
composer create-project laravel/laravel --prefer-dist
Call the above statement in that new_project folder because that is where laravel will install. The above will make your directory path as:
C:\wamp\www\new_project\laravel\
Laravel is now available on your system. You can verify a successful install by going to:
http://localhost/new_project/laravel/public/
Based on the above question edit regarding making a .phar globally available for command:
The directory your looking for is
C:\bin --the equivalent folder to /usr/bin on Linux.
Copy the laravel.phar file in the C:\bin folder. Or , you can put it in a folder, such as, C:\php\laravel.phar. Then you need to make a batch file somewhere within the PATH called laravel.bat which will then do the following:
#ECHO OFF
php "%~dp0laravel.phar" %*
The "%*" repeats all of the arguments passed to the shell script.
Thus, you can run 'laravel new project'. Hope this points you in the right direction.
The documentation on the Laravel website is not a good way to install laravel on windows. You'll got problem with the routing later.
Accessing laravel URL like this is a no-no:
http://localhost/new_project/laravel/public/
to get a better URL you must setup Apache Virtual Host and edit hosts file.
The best way to install Laravel on windows is to use Git and Composer. if you already successfully install Git and Composer, open Git bash and using ls and cd terminal command go to c:\xampp\htdocs folder
and run this command (it will ask you for your Git passphrase, make sure you install your Git properly - tutorial here - http://www.thegeekstuff.com/2012/02/git-for-windows/):
git clone git#github.com:laravel/laravel.git laraveldev
It will download laravel into a folder name laraveldev in htdocs:
c:\xampp\htdocs\laraveldev
Use the Git bash terminal to install laravel into PHP using this command:
composer install
edit hosts file - located in c:\windows\system32\drivers\etc, add this:
127.0.0.1 www.laravel.dev
and put virtual hosts entry in c:\xampp\apache\conf\extra\httpd-vhosts.conf.
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/laraveldev/public"
ServerName www.laravel.dev
ServerAlias www.laravel.dev
ErrorLog "logs/laravel.log"
CustomLog "logs/custom.laravel.log" combined
<Directory "C:/xampp/htdocs/laraveldev/public">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Restart you xampp apache. Then you can access laravel app in your browser like this:
http://www.laravel.dev
I'm totally 100% sure you'll got those "You have arrived" text :D
installing laravel is easy way with composer, if you cant use composer, than you can go with laravel.phar file. This method is also easiest way to install laravel on your local machine.
I think it will be useful to install using laravel.phar file.
kvcodes

Categories