Koolstr
Koolstr

Reputation: 502

Accessing phpMyAdmin in Laravel Homestead with XAMPP

After a night of frustration with the steep learning curve in setting up Laravel Homestead and getting it to work without any problems, I come across this one problem that I cannot seem to find a solution to. How do I manage my databases in a Laravel Homestead instance, using phpmyadmin?

Ideally, I would like to access it from my pre-configured phpMyAdmin in XAMPP, located in C:/xampp/. But I did not set up my Laravel project in C:/xampp/htdocs/, which seems to be where XAMPP gets its databases from. I created the Laravel project in ~\Google Drive\College\...\Project\, so it has no connection to my XAMPP installation. How can I manage/create databases for my Laravel project using XAMPP?

I've tried installing phpmyadmin in Laravel Homestead directly, but it just creates it as another 'project', right next to the one I am trying to use it for, as in ~\Google Drive\College\...\phpMyAdmin\. (If this is how it is supposed to be, then how do I use that phpMyAdmin installation/instance to access and modify my project's databases?)

Going to localhost:8000/home properly delivers my index page within my project's public directory, but there is no phpMyAdmin accessible by going to localhost:8000/home/phpMyAdmin or localhost:8000/phpMyAdmin. However, with my Apache and mySQL servers on in XAMPP, I can access my local (yet external from the project) phpMyAdmin installation with its databases.

What aspect of this am I missing, to not be able to work with databases? I'd appreciate any help. I've been up all night trying to figure this out.

Upvotes: 1

Views: 3434

Answers (1)

Koolstr
Koolstr

Reputation: 502

Hijacking XAMPP's phpMyAdmin config did not work. What the problem really was, was a proper mapping of the file directory, setting up the config files to match, and then re-provisioning to apply the config changes. XAMPP was never even needed. In detail, this is the configuration that worked:

In Homestead.yaml:

folders: 
# The iMeetUp project folder is contained within the project folder specified here:
- map: C:/Users/****/******/******/Project Files/ 
  to: /home/vagrant/Code
# The above directory is where the local project folder should be mapped to within your Homestead VM. So the mapping works as follows: Map from local, to VM.

sites:
- map: imeetups.local
  to: /home/vagrant/Code/iMeetUp/public
# This mapping, when combined with the hosts file edit, enables you to access your app at http://imeetups.local:8000

databases:
- iMeetUp

Add this to your hosts file located at C:\Windows\System32\drivers\etc (make sure to open the file with your code editor of choice (mine is Sublime Text) and that you launched that editor with Run As Administrator enabled):

127.0.0.1 imeetups.local

In your Laravel project, change the following part of this file to match: iMeetUp/app/config/local/database.php:

  'mysql' => array(
        'driver'    => 'mysql',
        'host'      => '127.0.0.1',
        'database'  => 'iMeetUp',
        'username'  => 'homestead',
        'password'  => 'secret',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),

The username and password for homestead's database is what is used, the same one described on their documentation.

Lastly, you must re-initialize the project - no need to vagrant destroy the entire thing. Just run this within your Homestead folder in command prompt, wherever you saved your Homestead installation:

Git bash init.sh

If that doesn't work, make sure you have Git bash installed and included in your PATH file. Then you can just run init.sh from the Homestead folder, and it should automatically launch a Git bash window. In the dialog, choose yes to overwrite all 3 configuration files it will ask about. I first made the mistaken assumption the first file was asking about overwriting the homestead.yaml file, but then I noticed it is referring to the cached version of the file, so you definitely should say yes to it and not no.

After initialization, you need to re-provision the entire project. Run in your Homestead directory:

vagrant up --provision

Or, if your VM is currently running,

vagrant reload --provision

This will force the project to re-apply its cache setup of config files. Now your app should work and be connected to the database, and the site should be accessible at any of the following addresses:

http://localhost:8000
http://127.0.0.1:8000
http://imeetup.local:8000

Also, if you plan to use Laravel's built in Auth:: framework, you'll need to change the framework to use the databases instead. For example:

iMeetUp/app/config/auth.php:

'driver' => 'database', 
'model' => 'member', 
'table' => 'members',

The table should match your default/primary user/member table in your database, and the model should be referencing the name of the user/member model file you are using in iMeetUps/app/models.

With this setup, your app should appropriately use your Homestead's database. I was not able to find any extensive, clear, detailed solutions to this problem, so I decided to write one up myself. I hope this helps someone else save a weekends-worth of time, which is how long it took me to figure this out.

Upvotes: 1

Related Questions