Post

Laravel Homestead Setup|phpMyAdmin Integration for MySQL Management

Developers struggling with Laravel environment setup can follow this guide to build Laravel Homestead from scratch and integrate phpMyAdmin for efficient MySQL database management, streamlining development workflows effectively.

Laravel Homestead Setup|phpMyAdmin Integration for MySQL Management

点击这里查看本文章简体中文版本。

點擊這裡查看本文章正體中文版本。

This post was translated with AI assistance — let me know if anything sounds off!


[Reinstallation Note 1] - Laravel Homestead + phpMyAdmin Environment Setup

From 0 to 1: Setting Up a Laravel Development Environment with phpMyAdmin GUI for Managing MySQL Database

[Laravel](https://laravel.com/){:target="_blank"}

Laravel

Recently reset my Mac and documented the steps to restore the Laravel development environment.

Environment Requirements

  • Vagrant: Virtual environment configuration tool

  • VirtualBox: Free virtualization software. If you have already purchased Parallels, you can use Parallels directly (but you need to install the plug-in).

After downloading and installing these two software, proceed to the next setup step.

VirtualBox installation requires a reboot and navigating to “Settings” -> “Security & Privacy” -> “Allow VirtualBox” to enable all services.

Setting up the Homestead Environment

1
2
3
4
git clone https://github.com/laravel/homestead.git ~/Homestead
cd ~/Homestead
git checkout release
bash init.sh

phpMyAdmin

phpMyAdmin is a PHP-based, web-based MySQL database management tool hosted on a website server, allowing administrators to manage MySQL databases via a web interface. This web interface provides an easy way to input complex SQL commands, making it especially convenient for importing and exporting large amounts of data. — Wiki

Go to the phpMyAdmin official website and download the latest version.

Unzip .zip -> Folder -> Rename Folder -> “phpMyAdmin”:

Move the phpMyAdmin folder to the ~/Homestead directory:

phpMyAdmin Settings

Find config.sample.inc.php in the phpMyAdmin folder, rename it to config.inc.php, and open it with an editor to modify the settings as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * phpMyAdmin sample configuration, you can use it as base for
 * manual configuration. For easier setup you can use setup/
 *
 * All directives are explained in documentation in the doc/ folder
 * or at <https://docs.phpmyadmin.net/>.
 *
 * @package PhpMyAdmin
 */
declare(strict_types=1);

/**
 * This is needed for cookie based authentication to encrypt password in
 * cookie. Needs to be 32 chars long.
 */
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

/**
 * Servers configuration
 */
$i = 0;

/**
 * First server
 */
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'config';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['user'] = 'homestead';
$cfg['Servers'][$i]['password'] = 'secret';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;

/**
 * phpMyAdmin configuration storage settings.
 */

/* User used to manipulate with storage */
// $cfg['Servers'][$i]['controlhost'] = '';
// $cfg['Servers'][$i]['controlport'] = '';
// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';

/* Storage database and tables */
// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
// $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
// $cfg['Servers'][$i]['relation'] = 'pma__relation';
// $cfg['Servers'][$i]['table_info'] = 'pma__table_info';
// $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
// $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
// $cfg['Servers'][$i]['column_info'] = 'pma__column_info';
// $cfg['Servers'][$i]['history'] = 'pma__history';
// $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
// $cfg['Servers'][$i]['tracking'] = 'pma__tracking';
// $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
// $cfg['Servers'][$i]['recent'] = 'pma__recent';
// $cfg['Servers'][$i]['favorite'] = 'pma__favorite';
// $cfg['Servers'][$i]['users'] = 'pma__users';
// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
// $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
// $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
// $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
// $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
// $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';

/**
 * End of servers configuration
 */

/**
 * Directories for saving/loading files from server
 */
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';

/**
 * Whether to display icons or text or both icons and text in table row
 * action segment. Value can be either of 'icons', 'text' or 'both'.
 * default = 'both'
 */
//$cfg['RowActionType'] = 'icons';

/**
 * Defines whether a user should be displayed a "show all (records)"
 * button in browse mode or not.
 * default = false
 */
//$cfg['ShowAll'] = true;

/**
 * Number of rows displayed when browsing a result set. If the result
 * set contains more rows, "Previous" and "Next".
 * Possible values: 25, 50, 100, 250, 500
 * default = 25
 */
//$cfg['MaxRows'] = 50;

/**
 * Disallow editing of binary fields
 * valid values are:
 *   false    allow editing
 *   'blob'   allow editing except for BLOB fields
 *   'noblob' disallow editing except for BLOB fields
 *   'all'    disallow editing
 * default = 'blob'
 */
//$cfg['ProtectBinary'] = false;

/**
 * Default language to use, if not browser-defined or user-defined
 * (you find all languages in the locale folder)
 * uncomment the desired line:
 * default = 'en'
 */
//$cfg['DefaultLang'] = 'en';
//$cfg['DefaultLang'] = 'de';

/**
 * How many columns should be used for table display of a database?
 * (a value larger than 1 results in some information being hidden)
 * default = 1
 */
//$cfg['PropertiesNumColumns'] = 2;

/**
 * Set to true if you want DB-based query history.If false, this utilizes
 * JS-routines to display query history (lost by window close)
 *
 * This requires configuration storage enabled, see above.
 * default = false
 */
//$cfg['QueryHistoryDB'] = true;

/**
 * When using DB-based query history, how many entries should be kept?
 * default = 25
 */
//$cfg['QueryHistoryMax'] = 100;

/**
 * Whether or not to query the user before sending the error report to
 * the phpMyAdmin team when a JavaScript error occurs
 *
 * Available options
 * ('ask' \\| 'always' \\| 'never')
 * default = 'ask'
 */
//$cfg['SendErrorReports'] = 'always';

/**
 * You can find more configuration options in the documentation
 * in the doc/ folder or at <https://docs.phpmyadmin.net/>.
 */

Mainly added or modified these three settings:

1
2
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'homestead';

The default MySQL username and password for homestead are homestead / secret.

Configure Homestead Settings

Open the ~/Homestead/Homestead.yaml configuration file with an editor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
ip: "192.168.10.10"
memory: 2048
cpus: 2
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Projects/Web
      to: /home/vagrant/code
    - map: ~/Homestead/phpMyAdmin
      to: /home/vagrant/phpMyAdmin

sites:
    - map: phpMyAdmin.test
      to: /home/vagrant/phpMyAdmin

databases:
    - homestead

features:
    - mysql: false
    - mariadb: false
    - postgresql: false
    - ohmyzsh: false
    - webdriver: false

#services:
#    - enabled:
#        - "postgresql@12-main"
#    - disabled:
#        - "postgresql@11-main"

# ports:
#     - send: 50000
#       to: 5000
#     - send: 7777
#       to: 777
#       protocol: udp
  • IP : Default is 192.168.10.10, can be changed or left as is

  • provider: The default is virtualbox. Change it only if using Parallels.

  • folders: added
    • map: ~/Homestead/phpMyAdmin to: /home/vagrant/phpMyAdmin
  • sites: added
    • map: phpMyAdmin.test
      to: /home/vagrant/phpMyAdmin

If you already have a Laravel project, you can add it here as well. For example, I keep all my projects under ~/Projects/Web, so I first add the directory mapping accordingly.

sites sets up local virtual domains and directory mappings. We also need to modify the local Hosts file to add domain-to-virtual machine mappings:

Use Finder -> Go -> /etc/hosts to locate the hosts file; copy it to the desktop (cannot modify it directly)

The domain name can be freely customized since only the local machine can access it.

Open the copied Hosts file and add site records:

1
<homestead IP address> <domain name>

After editing, save the file, then cut and paste it back into /etc/hosts to overwrite the original.

Installing & Starting Homestead Virtual Machine

1
2
cd ~/Homestead
vagrant up --provision

⚠️Please note that if you do not add --provision, the provisioning profile will not be updated, and entering the URL will result in a no input file specified error.

The first launch requires downloading the Homestead environment package, which takes a longer time.

If no specific errors appear, it means the startup was successful. You can enter:

1
vagrant ssh

ssh into the virtual machine.

Check if phpMyAdmin is Connected Correctly

Go to http://phpmyadmin.test/ to check if it opens properly.

Success! When we need to operate the database, we can directly come here to make changes.

Create a New Laravel Project

If you already have an existing project, by this step you can run it locally from the browser. If not, here is how to create a new Laravel project.

1
2
~/Homestead
vagrant ssh

vagrant ssh into the VM, then cd into the code directory:

1
cd ./code

Run laravel new project_name to create a Laravel project: (using blog as an example)

1
laravel new blog

blog project created successfully!

Next, we need to configure the project to allow the machine to access the test domain:

Open the ~/Homestead/Homestead.yaml configuration file again for editing.

Add a new record in sites:

1
2
3
sites:
  - map: myblog.test
  to: /home/vagrant/code/blog/public

Remember to add the corresponding records to the hosts file as well:

1
192.168.10.10.   myblog.test

Finally, restart homestead:

1
vagrant reload --provision

Enter http://myblog.test in the browser to test if it is correctly created and running:

Done!

Supplement — Installing Composer on Mac

Although Homestead allows you to avoid installing Composer separately, since some PHP projects do not use Laravel, it is still necessary to install Composer on your local machine.

Copy the command from the download section and replace php composer-setup.php with:

1
php composer-setup.php - install-dir=/usr/local/bin - filename=composer

Composer v2.0.9 Example:

1
2
3
4
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"

Then enter the commands in the terminal in order.

⚠️Please note do not directly copy and use the above examples, as the hash check code will change with Composer version updates.

Type composer -V to check the version and confirm successful installation!

References

If you have any questions or feedback, feel free to contact me.


Buy me a beer

This post was originally published on Medium (View original post), and automatically converted and synced by ZMediumToMarkdown.

Improve this page on Github.

This post is licensed under CC BY 4.0 by the author.