How to configure Laravel application on localhost? - php

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

Related

Laravel/Homestead vagrant box disapeared from system

I got a php project which is already done and for starters I have to put it up on a server (planning to use Heroku). I am new to PHP virtual boxes, Laravel, etc. The person who made the project recommended to use Laravel so I started to get things going that way. I am running on Windows 10 and using cmder as my terminal.
I downloaded VirtualBox & Vagrant.
Then using commander I added the Laravel/Homestead box
by doing:
vagrant box add laravel/homestead
in the folder c:\Users\Jacky\vagrant\ubuntu (At least I think that is where I added it)
Afterwards I believe I did
vagrant init
or vagrant init laravel/homestead
whatever I did afterwards I was able to run
vagrant ssh
and get into the system. There I was able to check and I had php and composer installed.
I then followed laravels instructions and created a homestead folder at c:\Jack\Homestead
ran git checkout for v7.19.2
ran init.bat
and configured the Homestead.yaml file
I made the following folder map
- map: C:\Jack\myapp\public
to: /home/vagrant/myapp
and the following site map
- map: myapp.test
to: /home/vagrant/myapp/public
I am a bit confused with the directory structure of this whole thing and not sure if I was supposed to put the myapp directory inside c:\Jack\Homestead\myapp or if just doing it like i did in c:\Jack\myapp is fine.
Anyways that still worked and I could see it in my web browser. So far all was good.
Then the project instructions told me to do the following
run composer install
There was an env.example file I had to change to .env and change some setting
run php artisan key:generate
run php artisan migrate --seed
run php artisan passport:install
run php artisan storage:link
At this point I got an error that the Symlink could not be created, so I googled and found in Stack Overflow to restart as admin. I ran cmder as admin and have been having a heart attack for the last 30 minutes since it told me I had to vagrant up and when I did so it couldnt find my box and even doing vagrant box list
I would get no results and it wanted to redownload which takes over 3 hours.
I just restarted without admin and I do find that my Laravel/Homestead box is listed so I assume it was installed for my user and not admin so I guess I cant run cmder as admin.
So now I am trying to connect again, I am not sure in which folder I should be running the vagrant commands but I only seem to have a VagrantFile in my C:\Jack\Homestead folder so if I run a vagrant command anywhere else it gives me an error that a vagrant environment is required, etc.
So I tried the following inside my homestead folder:
vagrant ssh - I get:
VM must be running to open SSH connection. Run `vagrant up to start the virtual machine.
(In my VirtualBox Manager i see my homestead-7 VM running though)
vagrant up - I get:
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Importing base box 'laravel/homestead'...
==> homestead-7: Matching MAC address for NAT networking...
==> homestead-7: Checking if box 'laravel/homestead' is up to date...
A VirtualBox machine with the name 'homestead-7' already exists.
Please use another name or delete the machine with the existing
name, and try again.
vagrant ssh 'homestead-7' I also get
VM must be running to open SSH connection. Run vagrant up
to start the virtual machine.
And the problem is once I do connect I assume I will still have the same problem running:
php artisan storage:link
So my questions are as follows:
Where should I have my projects myapp folder, should it be where it is at C:\Jack\myapp or am I supposed to put it in C:\Jack\Homestead\myapp
Is the VagrantFile supposed to be only in my Homestead folder and is that where I should be running all my Vagrant commands from? Like vagrant ssh and vagrant up
How do I connect again now that I am getting those errors running vagrant ssh and vagrant up
Once I connect I assume I will get the same error running php artisan storage:link since to run as administrator seems to not work what do I do?
I Assume that I should run git init and heroku create inside the myapp folder is this correct?
1) I always keep my apps folders outside of the Homestead folder. Your Homestead folder contains a git project, so if you put your apps inside you should include the folder in the .gitignore file. I think it's easier if you just put your apps elsewhere.
2) Vagrantfile is suposed to only be inside of your Homestead folder ( c:\Jack\Homestead). You should run all your vagrant commands inside the Homestead folder.
3) I used to get this error when I tried to run 'vagrant up' to a project that used the same box name 'homestead-7'. If you have version control, check if the file c:\Jack\Homestead\.vagrant\machines\homestead-7\virtualbox\id has been changed. If so, try restoring the old value and running 'vagrant up' again.
4) You are running in a windows environment, right? Windows can be a little temperamental with symlinks inside vagrant. You'll get the same problem if you try to npm install something. What I do to solve this is to run npm (and php artisan storage:link) outside of the virtual machine, in the host pc, inside the root of the app folder. Just a reminder: to do that you will need php installed in your host machine.
5) All commands related to the app (and not the virtual machine) should be run inside the virtual machine, in the folder app (ex: /home/vagrant/code/myapp) or inside the app folder of your host machine. Those two folders are in sync, thanks to vagrant.

Setup Laravel project after cloning

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

Laravel homestead is setup and works. But can't find files created

I've just got my new Macbook Pro, and installed Homestead on it. Followed this link: https://laravel.com/docs/master/homestead
I can view the site after installing Laravel on Homestead, but can't find where the files created are on my computer.
Here's homestead.yaml file
My browser
Code Folder
To check for any hidden files I've tried the same on Terminal
When I ssh into the Vagrant instance, I can see the file.
Where could the files be stored? Or am I looking at the wrong place? Thanks
I was able to fix it using the following steps.
I ran vagrant provision from the Homestead directory.
I was able to access the mac Code folder from ssh:
ssh vagrant#192.168.10.10
cd /home/Code
Just had to install Laravel again in this directory.
I think by default it is in your User folder. Mac HD/Users/yourname/Code
Check your command by which you create the project. It looks like:
$composer create-project laravel/laravel --prefer-dist your_project_name
If no error occurs, a directory named your_project_name would be created under your Code path.
Good luck!

Laravel Homestead Installation Error on Windows

I have been trying to set up Laravel Homestead Environment on a local machine. But I was unable to do it.I faced several errors in the installation process. Actually,I am confused with the installation procedure from configuring the SSH Key in the "homestead.yaml" file step.
In the "homestead.yaml" file,How to configure the authorize and keys components according to my local SSH file location against the standard Absolute Path location?
And what exactly is the use of Composer which is being mentioned as a package managing tool?
Is there a good tutorial out there regarding the installation procedure?
Its the first task in my new job and I am really struggling. Any help is really appreciated.
Thanks,
Sri
As you're asking for SSH i assume that you already downloaded Homestead completely (box & clone)and that a Homestead folder is present in you home directory.
First make sure you have Git Bash installed if you're on Windows, Go to your Homestead folder, right click and chose Git Bash then type in this command ssh-keygen -t rsa -C "you#homestead" this will create an SSH key in your folder.
You have to make sure that the keys are named like id_rsa.pub and id_rsa and place them in C:/Users/{username}/.SSH if they're somewhere else, install Composer if you don't have yet go to the folder you want laravel to be in, right click use composer here in next window put this command composer create-project laravel/laravel --prefer-dist
For your authorize key path question this is what you need to put in the Homestead.yaml file authorize: C:/Users/{username}/.ssh/homestead_rsa.pub
for the folders :
folders:
- map: C:/path/to/{local_laravel_project_folder}
to: /home/vagrant/Code
type: "nfs"
sites:
- map: sitename.dev
to: /home/vagrant/Code/Laravel/public
hhvm: true
Open notebook with administrative rights and go to C:\Windows\System32\drivers\etc\hosts and add this line 192.168.10.10 : sitename.dev save the file, run Homestead then in Bash put this command vagrant upand you should see the laravel homepage when you visit sitename.dev .

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