Mysql not found even the Laravel-homestead is installed - php

I am a newbie to both Laravel and PHP. Now I wish to link my Laravel project to Mysql database. I am using the os x 10.10 and I have already installed homestead and vagrant. But when I input which mysql in the command line, it is told that mysql not found.
A mysql database is supposed to be included in the homestead package. But why can't the mysql be found? How can I link my project to mysql db and how can I ensure that I have successfully done that? Thanks in advance!

If I guess correctly you are trying to find mysql on your physical machine, when it is actually installed on your virtual machine. You have to connect to the Homestead via ssh first, in order to do which mysql. So in your terminal do:
homestead up
homestead ssh
which mysql
You can read more about Homestead in the documentation documentation. Also you can read wiki article to keep up with concept of virtual machine.
To create a new database inside the Homestead you simply have to find you Homestead.yaml file (usually path is ~/.homestead/Homestead.yaml) and add the name of you database to the databases section:
databases:
- homestead
- your_new_database_name
Then you have to provision the Homestead machine with homestead provision. After this the databases will be created and only thing you will have to do is link to it from you projects .env file (located in the root of your Laravel project):
DB_HOST=localhost
DB_DATABASE=your_new_database_name
DB_USERNAME=homestead
DB_PASSWORD=secret
This have to do it. The Laravels documentation regarding database is really great. Usually you can find all you need there. I guess you will need to create some migrations to create the schema for you databases. It is covered there too.

Related

Running a provisional script in one of the Homestead projects?

In my Homestead directory, I have mapped two projects, one laravel, and one PHP.
My PHP project could be run with vagrant up. This would then create tables in a database and everything setup to work.
My question is how would I set up this to happen automatically after I vagrant up my Homestead machine?
I think that vagrant up inside a Homestead machine is not the best solution.
I know it is complicated if someone has any idea how this would be done, I am grateful.
Thank you
You can use after.sh to do anything you want to the Homestead VM after it's been booted but before it finishes the vagrant up process.

How to set up React-Laravel project with out php artisan serve?

I have created a react-laravel project using laravel-mix. Right now I am run project using
npm run watch
php artisan serve
So by this, I access project by : http://localhost:8000
I have also worked in laravel. In laravel, if we want to access project without php artisan serve then we can access using : http://localhost/project_name/public.
Now my question is, how can I access/execute react-laravel project without php artisan serve? Is there any kind of way to access/execute project without port? Because I want to set up react-laravel on live server and I don't want to continue open terminal on server after code uploading.
I will really appreciate your feedbacks.
There are a multitude of ways to set up a laravel project. and it has nothing to do with the frontend suite you use whether its React or Vue, I will give you 2 options here to run a laravel application.
1. vagrant/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. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes!
Doc Link
2. XAMPP/WAMP/ or any LAMP stack
XAMPP is a completely free, easy to install Apache distribution containing MariaDB, PHP, and Perl. The XAMPP open source package has been set up to be incredibly easy to install and to use.
Link
Personally I prefer Laravel Homestead since it contains everything out of the box for laravel Development. like PHP, Nginx, MariaDB, Node, etc...

Share homestead vagrant box and laravel project on Git

On my local machine I have created using homestead vagrant box a laravel project. Now I have an Homestead folder that contains many files like Vagrantfile, Homestead.yaml configuration and as soon as. I have also another folder sibling of Homestead folder that contain the Laravel files project. My question is how to share on Git this folders in order to clone the repository from another machine and recreate automatically the same Vagrant machine and the laravel project? In both folders there are composer.json files.Thanks in advance.
Depends on what you want to achieve. If you want to have a "frozen" in time vagrant box you would init homestead, let it do it's thing and them remove anything that's not mentioned in the vagrant file, then use that as a base for your repo. You can also fork homestead, run init and the use that as a base.
Homestead has an extra provisioning script, by convention named after.sh (see this for an example and this to see when it's called), which could clone your project from a separate repo into a place of your choosing (consistent with the project root you set up in your homestead file).
My point is -- don't mix development environment setup with your project files.
All of the above could be done under assumption you would have all the prerequisite software installed on your machine (vagrant, homestead, git, etc). Otherwise (maybe homestead would do it for you) you might also right a custom setup script that would check those dependencies, attempt to install them and the up the homestead box based on your configuration (something like a pre-init to init.sh :)). Or just put the instructions in the readme file (or link to Laravel's documentation).
I hope this helps!

Vagrant based development

I was just discovered Vagrant and i want to use it in my development. I just wanted to see how are some more experienced developers handing this.
I will assume on my local machine i will have a folder, say ~/server/, where i will keep all my projects (one in each folder), and each will contain a Vagrantfile.
Questions:
GIT: do i install the git on my machine and make the pushing/pulling locally, or put it on the vm for each project and run those from there?
DB: the database will obviously go into the vm for each project, but how will i be able to easily modify them? Should i install phpmyadmin or a tool like that on each vm?
what is the best way to access the vms in the browser? Do i assign each of them a different IP and then add a record into my /etc/hosts?
I'm just starting out with Vagrant, so there are probably questions i have that didn't even popped into my head yet, so any other suggestions you could give me that you think are important for this will be very useful to me.
Thanks in advance for the answers.
GIT: In my opinion, you should install git and setup repositories via vagrant provisioning on each VM, and after that you can create git hooks on your local machine that will update the code on each VM on local commit.
DB: You don't need to install phpmyadmin on vms. You can easily modify DB (I am assuming, you want to modify records) via DB client installed on your local machine (preferred) or you can also use local machine's phpmyadmin with remote connection.
Yes, you can do that.

Get database from git project

I am a beginner in Laravel. For the purpose of studying, I downloaded and installed a sample project from Github. I followed the given steps and installed the project.
However, I don't know how to import the database from the git repository. I have searched for .sql files in the project folder, but none exist.
Does anyone know how to import the database of this project?
You need to run the migrations - in Laravel, you don't import from .sql files, you run migrations.
$ php artisan migrate
For reference, you can find the migration files here.
You can use basic tools built in the mysql console.
1. Use mysqldump command, it will create a dump file of your database.
2. Add the dump file to the repository
3. If you want to install the db to a remote host, in the ssh console you can use mysql -u username dbname -p < dumpfile.dump (or .sql). You can do this on your localhost too from xampp shelp/terminal/cmd
4. Enter your password

Categories