Home Reinstallation Note 1 - Laravel Homestead + phpMyAdmin Environment Setup
Post
Cancel

Reinstallation Note 1 - Laravel Homestead + phpMyAdmin Environment Setup

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

Setting up a Laravel development environment from scratch and managing MySQL databases with phpMyAdmin GUI

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

Laravel

Recently reset my Mac, recording the steps to restore the Laravel development environment.

Environment Requirements

  • Vagrant: Virtual environment configuration tool
  • VirtualBox: Free virtual machine software. If you have purchased Parallels, you can also use Parallels (but you need to install the plug-in)

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

During VirtualBox installation, you will be required to restart and go to “Settings” -> “Security & Privacy” -> “Allow VirtualBox” to enable all services.

Configure 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 that allows administrators to manage MySQL databases through a web interface. This web interface provides a simpler way to input complex SQL syntax, especially for handling large data imports and exports. — Wiki

Download the latest version from the phpMyAdmin official website.

Unzip the .zip -> Folder -> Rename the folder to “phpMyAdmin”:

Move the phpMyAdmin folder to the ~/Homestead folder:

phpMyAdmin Configuration

In the phpMyAdmin folder, find config.sample.inc.php, 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 add and modify 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: The default is 192.168.10.10, can be changed or not
  • provider: The default is virtualbox, only needs to be changed if using Parallels
  • folders: Add - map: ~/Homestead/phpMyAdmin to: /home/vagrant/phpMyAdmin
  • sites: Add - map: phpMyAdmin.test to: /home/vagrant/phpMyAdmin

If you already have a Laravel project, you can also add it here. For example, I put my projects under ~/Projects/Web, so I also add the directory mapping.

sites is to set the local virtual domain and directory mapping. We also need to modify the local Hosts file to add the domain virtual machine mapping:

Use Finder -> Go -> /etc/hosts, find the hosts file; copy it to the desktop (because it cannot be modified directly)

The domain name can be customized as you like, as only your local machine can access it.

Open the copied Hosts file and add the sites record:

1
<homestead IP address> <domain name>

After modifying, save it, then cut and paste it back to /etc/hosts, overwriting the original file.

Install & Start Homestead Virtual Machine

1
2
cd ~/Homestead
vagrant up --provision

⚠️ Please note that if you do not add --provision, the configuration file will not be updated, and you will get a no input file specified error when entering the URL.

The first time you start it, you need to download the Homestead environment package, which takes a long time.

If no special errors occur, it means the startup was successful. You can then run:

1
vagrant ssh

ssh into the virtual machine.

Check if phpMyAdmin is correctly connected

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

Success! We encountered a place where we need to operate the database, just come here and modify it directly.

Create a New Laravel Project

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

1
2
~/Homestead
vagrant ssh

SSH into the VM, then cd to the code directory:

1
cd ./code

Run laravel new followed by the project name to create a Laravel project (using blog as an example):

1
laravel new blog

The blog project has been successfully created!

Next, we need to set up the project to access the test domain locally:

Go back and open the ~/Homestead/Homestead.yaml configuration file.

Add a record in sites:

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

Remember to add a corresponding record in hosts:

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 set up and running:

Done!

Supplement — Installing Composer on Mac

Although using Homestead means you don’t need to install Composer separately, considering that some PHP projects may not use Laravel, you still need to install Composer locally.

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');"

Enter the commands sequentially in the terminal.

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

Enter composer -V to confirm the version and successful installation!

References

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

===

本文中文版本

===

This article was first published in Traditional Chinese on Medium ➡️ View Here



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

What's New with Universal Links

Using Python+Google Cloud Platform+Line Bot to Automate Routine Tasks