{"id":434,"date":"2023-02-25T12:26:38","date_gmt":"2023-02-25T04:26:38","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=434"},"modified":"2023-04-29T21:05:32","modified_gmt":"2023-04-29T13:05:32","slug":"laravel-homestead-development-environment-deployment","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/laravel-homestead-development-environment-deployment\/","title":{"rendered":"Laravel\u7684Homestead\u5f00\u53d1\u73af\u5883\u90e8\u7f72"},"content":{"rendered":"<h2>Vagrant\u811a\u672c\u5b89\u88c5<\/h2>\n<p>Vagrant\u547d\u4ee4\u53ea\u80fd\u8bc6\u522bVagrantfile\uff0c\u901a\u8fc7<code>Homestead\/Vagrantfile<\/code>\u52a0\u8f7d<code>Homestead\/scripts<\/code>\u76ee\u5f55\u4e0b\u7684<code>homestead.rb<\/code><\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-bash\">> git clone https:\/\/github.com\/laravel\/homestead.git Homestead  \/\/\u4f7f\u7528Git Bash\u6267\u884c\uff0c\u4f7f\u7528CMD\u6709\u70b9\u95ee\u9898\n\n> vagrant box add laravel\/homestead\n==&gt; box: Loading metadata for box &#039;laravel\/homestead&#039;\n    box: URL: https:\/\/atlas.hashicorp.com\/laravel\/homestead\nThis box can work with multiple providers! The providers that it\ncan work with are listed below. Please review the list and choose\nthe provider you will be working with.\n\n1) hyperv\n2) parallels\n3) virtualbox\n4) vmware_desktop\n\nEnter your choice: 3\n==&gt; box: Adding box &#039;laravel\/homestead&#039; (v2.1.0) for provider: virtualbox\n    box: Downloading: https:\/\/atlas.hashicorp.com\/laravel\/boxes\/homestead\/versions\/2.1.0\/providers\/virtualbox.box\n    box: Progress: 100% (Rate: 359k\/s, Estimated time remaining: --:--:--)\n==&gt; box: Successfully added box &#039;laravel\/homestead&#039; (v2.1.0) for &#039;virtualbox&#039;!<\/code><\/pre>\n<p>\u5982\u679c\u901f\u5ea6\u5f88\u6162\uff0c\u76f4\u63a5Ctrl+C\u4e2d\u65ad\uff0c\u4f7f\u7528\u8fc5\u96f7\u4e0b\u8f7d\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/atlas.hashicorp.com\/laravel\/boxes\/homestead\/versions\/2.1.0\/providers\/virtualbox.box\">https:\/\/atlas.hashicorp.com\/laravel\/boxes\/homestead\/versions\/2.1.0\/providers\/virtualbox.box<\/a><\/p>\n<pre><code class=\"language-bash\">> vagrant box add laravel\/homestead E:\/VagrantBox\/homestead-virtualbox.box\n\n> vagrant box list\n\n> cd Homestead\n\n> init.bat\n\n> vagrant up<\/code><\/pre>\n<p>\u5982\u9047\u5230<code>id_rsa\/id_rsa.pub<\/code>\u7b49SSH\u95ee\u9898\uff0c\u5219\u5728Git Bash\u4e0b\u6267\u884c\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-bash\">ssh-keygen -t rsa -C &quot;yezhou@yezhou.org&quot;<\/code><\/pre>\n<p>\u5982\u679c<code>vagrant up<\/code>\u51fa\u73b0\u95ee\u9898\uff1a<\/p>\n<pre><code>C:\/HashiCorp\/Vagrant\/embedded\/gems\/gems\/vagrant-1.9.3\/lib\/vagrant\/util\/is_port_open.rb:21:in `initialize&#039;: The requested address is not valid in its context. - connect(2) for &quot;0.0.0.0&quot; port 8000 (Errno::EADDRNOTAVAIL)<\/code><\/pre>\n<p>\u5219\u4fee\u6539<code>Homestead\/scripts\/homestead.rb<\/code>\uff0c<code>host_ip<\/code>\u6539\u4e3a &quot;127.0.0.1&quot;<\/p>\n<pre><code class=\"language-ruby\"># Use Default Port Forwarding Unless Overridden\ndefault_ports.each do |guest, host|\n  unless settings[&quot;ports&quot;].any? { |mapping| mapping[&quot;guest&quot;] == guest }\n    # config.vm.network &quot;forwarded_port&quot;, guest: guest, host: host, auto_correct: true\n    config.vm.network &quot;forwarded_port&quot;, guest: guest, host: host, host_ip: &quot;127.0.0.1&quot;, auto_correct: true\n  end\nend\n\n# Add Custom Ports From Configuration\nif settings.has_key?(&quot;ports&quot;)\n  settings[&quot;ports&quot;].each do |port|\n    # config.vm.network &quot;forwarded_port&quot;, guest: port[&quot;guest&quot;], host: port[&quot;host&quot;], protocol: port[&quot;protocol&quot;], auto_correct: true\n    config.vm.network &quot;forwarded_port&quot;, guest: port[&quot;guest&quot;], host: port[&quot;host&quot;], protocol: port[&quot;protocol&quot;], host_ip: &quot;127.0.0.1&quot;, auto_correct: true\n  end\nend<\/code><\/pre>\n<h2>\u5168\u5c40\u5b89\u88c5<\/h2>\n<pre><code class=\"language-bash\">> composer global require &quot;laravel\/homestead=~2.0&quot;\nChanged current directory to C:\/Users\/yezhou\/AppData\/Roaming\/Composer\n.\/composer.json has been updated\nLoading composer repositories with package information\nUpdating dependencies (including require-dev)\n  - Installing laravel\/homestead (v2.2.2)\n    Downloading: 100%\n\nWriting lock file\nGenerating autoload files\n\n> homestead -V\nLaravel Homestead version 2.2.2\n\n> homestead up<\/code><\/pre>\n<p>\u5982\u679c homestead up \u51fa\u73b0\u95ee\u9898\uff1a<\/p>\n<pre><code>C:\/HashiCorp\/Vagrant\/embedded\/gems\/gems\/vagrant-1.9.3\/lib\/vagrant\/util\/is_port_open.rb:21:in `initialize&#039;: The requested address is not valid in its context. - connect(2) for &quot;0.0.0.0&quot; port 8000 (Errno::EADDRNOTAVAIL)<\/code><\/pre>\n<p>\u5219\u4fee\u6539<code>C:\\Users\\yezhou\\AppData\\Roaming\\Composer\\vendor\\laravel\\homestead\\scripts\\homestead.rb<\/code>\uff0c<code>host_ip<\/code>\u6539\u4e3a &quot;127.0.0.1&quot;<\/p>\n<pre><code class=\"language-ruby\"># Use Default Port Forwarding Unless Overridden\ndefault_ports.each do |guest, host|\n  unless settings[&quot;ports&quot;].any? { |mapping| mapping[&quot;guest&quot;] == guest }\n    # config.vm.network &quot;forwarded_port&quot;, guest: guest, host: host, auto_correct: true\n    config.vm.network &quot;forwarded_port&quot;, guest: guest, host: host, host_ip: &quot;127.0.0.1&quot;, auto_correct: true\n  end\nend\n\n# Add Custom Ports From Configuration\nif settings.has_key?(&quot;ports&quot;)\n  settings[&quot;ports&quot;].each do |port|\n    # config.vm.network &quot;forwarded_port&quot;, guest: port[&quot;guest&quot;], host: port[&quot;host&quot;], protocol: port[&quot;protocol&quot;], auto_correct: true\n    config.vm.network &quot;forwarded_port&quot;, guest: port[&quot;guest&quot;], host: port[&quot;host&quot;], protocol: port[&quot;protocol&quot;], host_ip: &quot;127.0.0.1&quot;, auto_correct: true\n  end\nend<\/code><\/pre>\n<h2>Homestead\u6d4b\u8bd5<\/h2>\n<h3>\u67e5\u770bVagrant Box<\/h3>\n<pre><code class=\"language-bash\">> vagrant box list\nCentOS72          (virtualbox, 0)\nlaravel\/homestead (virtualbox, 0.3.3)\nlaravel\/homestead (virtualbox, 2.1.0)<\/code><\/pre>\n<blockquote>\n<p>\u6ce8\u610f\uff1a\u4f7f\u7528Homestead\u5168\u5c40\u5b89\u88c5\u7684\u9ed8\u8ba4\u7248\u672c\u5e76\u4e0d\u662f\u6700\u65b0\u7684<\/p>\n<\/blockquote>\n<h3>Homestead.yaml<\/h3>\n<blockquote>\n<p>\u6ce8\u610f\uff1a\u4f7f\u7528\u811a\u672c\u542f\u52a8\u9ed8\u8ba4\u542f\u52a8\u540d\u79f0\u4e3ahomestead-7\u7684\u865a\u62df\u673a\uff1b\u4f7f\u7528\u5168\u5c40\u542f\u52a8\u9ed8\u8ba4\u542f\u52a8\u540d\u79f0\u4e3ahomestead\u7684\u865a\u62df\u673a\u3002<\/p>\n<\/blockquote>\n<p>\u65e0\u8bba\u662f\u811a\u672c\u542f\u52a8\u8fd8\u662f\u5168\u5c40\u542f\u52a8\uff0cHomestead\u7684\u914d\u7f6e\u6587\u4ef6\u5747\u4e3a<code>C:\\Users\\yezhou\\.homestead\\Homestead.yaml<\/code><\/p>\n<pre><code class=\"language-yaml\">ip: &quot;192.168.10.10&quot;\nmemory: 2048\ncpus: 1\nprovider: virtualbox\n\nauthorize: ~\/.ssh\/id_rsa.pub\n\nkeys:\n    - ~\/.ssh\/id_rsa\n\nfolders:\n    - map: ~\/Code\n      to: \/home\/vagrant\/Code\n\nsites:\n    - map: homestead.app\n      to: \/home\/vagrant\/Code\/Laravel\/public\n\ndatabases:\n    - homestead<\/code><\/pre>\n<h3>\u4fee\u6539hosts<\/h3>\n<pre><code>192.168.10.10       yz.app\n192.168.10.10       homestead.app<\/code><\/pre>\n<h3>SSH \u767b\u5f55<\/h3>\n<p>\u542f\u52a8\u6210\u529f\u4fe1\u606f\uff1a<\/p>\n<pre><code class=\"language-bash\">> vagrant up\nBringing machine &#039;homestead-7&#039; up with &#039;virtualbox&#039; provider...\n==&gt; homestead-7: Checking if box &#039;laravel\/homestead&#039; is up to date...\n==&gt; homestead-7: Clearing any previously set forwarded ports...\n==&gt; homestead-7: Clearing any previously set network interfaces...\n==&gt; homestead-7: Preparing network interfaces based on configuration...\n    homestead-7: Adapter 1: nat\n    homestead-7: Adapter 2: hostonly\n==&gt; homestead-7: Forwarding ports...\n    homestead-7: 80 (guest) =&gt; 8000 (host) (adapter 1)\n    homestead-7: 443 (guest) =&gt; 44300 (host) (adapter 1)\n    homestead-7: 3306 (guest) =&gt; 33060 (host) (adapter 1)\n    homestead-7: 5432 (guest) =&gt; 54320 (host) (adapter 1)\n    homestead-7: 27017 (guest) =&gt; 27017 (host) (adapter 1)\n    homestead-7: 22 (guest) =&gt; 2222 (host) (adapter 1)\n==&gt; homestead-7: Running &#039;pre-boot&#039; VM customizations...\n==&gt; homestead-7: Booting VM...\n==&gt; homestead-7: Waiting for machine to boot. This may take a few minutes...\n    homestead-7: SSH address: 127.0.0.1:2222\n    homestead-7: SSH username: vagrant\n    homestead-7: SSH auth method: private key\n==&gt; homestead-7: Machine booted and ready!\n==&gt; homestead-7: Checking for guest additions in VM...\n==&gt; homestead-7: Setting hostname...\n==&gt; homestead-7: Configuring and enabling network interfaces...\n==&gt; homestead-7: Mounting shared folders...\n    homestead-7: \/vagrant =&gt; D:\/Laravel\/Homestead\n    homestead-7: \/home\/vagrant\/Code =&gt; C:\/Users\/yezhou\/Code\n==&gt; homestead-7: Machine already provisioned. Run `vagrant provision` or use the `--provision`\n==&gt; homestead-7: flag to force provisioning. Provisioners marked to run always will still run.\n\n> homestead up\nBringing machine &#039;default&#039; up with &#039;virtualbox&#039; provider...\n==&gt; default: Checking if box &#039;laravel\/homestead&#039; is up to date...\n==&gt; default: Clearing any previously set forwarded ports...\n==&gt; default: Clearing any previously set network interfaces...\n==&gt; default: Preparing network interfaces based on configuration...\n    default: Adapter 1: nat\n    default: Adapter 2: hostonly\n==&gt; default: Forwarding ports...\n    default: 80 (guest) =&gt; 8000 (host) (adapter 1)\n    default: 443 (guest) =&gt; 44300 (host) (adapter 1)\n    default: 3306 (guest) =&gt; 33060 (host) (adapter 1)\n    default: 5432 (guest) =&gt; 54320 (host) (adapter 1)\n    default: 22 (guest) =&gt; 2222 (host) (adapter 1)\n==&gt; default: Running &#039;pre-boot&#039; VM customizations...\n==&gt; default: Booting VM...\n==&gt; default: Waiting for machine to boot. This may take a few minutes...\n    default: SSH address: 127.0.0.1:2222\n    default: SSH username: vagrant\n    default: SSH auth method: private key\n==&gt; default: Machine booted and ready!\n==&gt; default: Checking for guest additions in VM...\n    default: The guest additions on this VM do not match the installed version of\n    default: VirtualBox! In most cases this is fine, but in rare cases it can\n    default: prevent things such as shared folders from working properly. If you see\n    default: shared folder errors, please make sure the guest additions within the\n    default: virtual machine match the version of VirtualBox you have installed on\n    default: your host and reload your VM.\n    default:\n    default: Guest Additions Version: 5.0.4\n    default: VirtualBox Version: 5.1\n==&gt; default: Setting hostname...\n==&gt; default: Configuring and enabling network interfaces...\n==&gt; default: Mounting shared folders...\n    default: \/vagrant =&gt; C:\/Users\/yezhou\/AppData\/Roaming\/Composer\/vendor\/laravel\/homestead\n    default: \/home\/vagrant\/Code =&gt; C:\/Users\/yezhou\/Code\n==&gt; default: Machine already provisioned. Run `vagrant provision` or use the `--provision`\n==&gt; default: flag to force provisioning. Provisioners marked to run always will still run.<\/code><\/pre>\n<p>\u9ed8\u8ba4\u8d26\u6237\u548c\u5bc6\u7801\uff1a<\/p>\n<ul>\n<li>SSH address: 127.0.0.1:2222<\/li>\n<li>SSH username: vagrant<\/li>\n<li>SSH password: vagrant<\/li>\n<\/ul>\n<h3>\u73af\u5883\u6d4b\u8bd5<\/h3>\n<pre><code class=\"language-bash\">vagrant@homestead:~$ composer\n   ______\n  \/ ____\/___  ____ ___  ____  ____  ________  _____\n \/ \/   \/ __ \\\/ __ `__ \\\/ __ \\\/ __ \\\/ ___\/ _ \\\/ ___\/\n\/ \/___\/ \/_\/ \/ \/ \/ \/ \/ \/ \/_\/ \/ \/_\/ (__  )  __\/ \/\n\\____\/\\____\/_\/ \/_\/ \/_\/ .___\/\\____\/____\/\\___\/_\/\n                    \/_\/\nComposer version 1.4.1 2017-03-10 09:29:45\n\nvagrant@homestead:~$ nginx -v\nnginx version: nginx\/1.11.9\n\nvagrant@homestead:~$ php -v\nPHP 7.1.3-3+deb.sury.org~xenial+1 (cli) (built: Mar 25 2017 14:00:03) ( NTS )\nCopyright (c) 1997-2017 The PHP Group\nZend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies\n    with Zend OPcache v7.1.3-3+deb.sury.org~xenial+1, Copyright (c) 1999-2017, by Zend Technologies\n    with blackfire v1.16.0~linux-x64-non_zts71, https:\/\/blackfire.io, by Blackfireio Inc.\n\nvagrant@homestead:~$ mysql -V\nmysql  Ver 14.14 Distrib 5.7.17, for Linux (x86_64) using  EditLine wrapper\nvagrant@homestead:~$ mysql -uroot -p\nEnter password:     \/\/\u9ed8\u8ba4\u5bc6\u7801\uff1asecret\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 4\nServer version: 5.7.17-0ubuntu0.16.04.2 (Ubuntu)\n\nCopyright (c) 2000, 2016, Oracle and\/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and\/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType &#039;help;&#039; or &#039;\\h&#039; for help. Type &#039;\\c&#039; to clear the current input statement.\n\nmysql&gt; \n\nvagrant@homestead:~$ psql -V\npsql (PostgreSQL) 9.5.6\nvagrant@homestead:~$ psql -U homestead -h localhost\nPassword for user homestead:     \/\/\u9ed8\u8ba4\u5bc6\u7801\uff1asecret\npsql (9.5.6)\nSSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)\nType &quot;help&quot; for help.\n\nhomestead=# \\l\n                                  List of databases\n   Name    |   Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   \n-----------+-----------+----------+-------------+-------------+-----------------------\n homestead | homestead | UTF8     | en_US.UTF-8 | en_US.UTF-8 | \n postgres  | postgres  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | \n template0 | postgres  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\n           |           |          |             |             | postgres=CTc\/postgres\n template1 | postgres  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\n           |           |          |             |             | postgres=CTc\/postgres\n(4 rows)\n\nhomestead=# \n\nvagrant@homestead:~$ redis-server -v\nRedis server v=3.2.8 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=11aa79fd2425bed9\nvagrant@homestead:~$ redis-cli -v\nredis-cli 3.2.8\n\nvagrant@homestead:~$ memcached -i\nmemcached 1.4.25<\/code><\/pre>\n<h3>\u90e8\u7f72\u6d4b\u8bd5<\/h3>\n<p><a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/yz.app\/\">http:\/\/yz.app\/<\/a><\/p>\n<p><a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/homestead.app\/\">http:\/\/homestead.app\/<\/a><\/p>\n<p><a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/192.168.10.10\/\">http:\/\/192.168.10.10\/<\/a><\/p>\n<p><a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/localhost:8000\/\">http:\/\/localhost:8000\/<\/a> \uff08\u4ec5\u5728\u5168\u5c40\u542f\u52a8\u6709\u6548\uff09<\/p>\n<h3>\u4fee\u6539Homestead.yaml\u5e76\u91cd\u65b0\u52a0\u8f7d<\/h3>\n<pre><code class=\"language-yaml\">ip: &quot;192.168.10.10&quot;\nmemory: 2048\ncpus: 1\nprovider: virtualbox\n\nauthorize: ~\/.ssh\/id_rsa.pub\n\nkeys:\n    - ~\/.ssh\/id_rsa\n\nfolders:\n    - map: D:\/Laravel\/www\n      to: \/home\/vagrant\/www\n\nsites:\n    - map: homestead.app\n      to: \/home\/vagrant\/www\/index\n    - map: yz.app\n      to: \/home\/vagrant\/www\/yezhou\/public\n\ndatabases:\n    - homestead<\/code><\/pre>\n<p>\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e<\/p>\n<pre><code class=\"language-bash\">> vagrant provision\n> vagrant reload  \/\/\u67d0\u4e9b\u60c5\u51b5\u4e0b\u9700\u8981\u91cd\u542f\u865a\u62df\u673a\n> vagrant reload --provision  \/\/\u6216\u8005\u52a0\u8f7d\u66f4\u65b0\u91cd\u542f<\/code><\/pre>\n<h3>\u5b89\u88c5Laravel<\/h3>\n<pre><code class=\"language-bash\">vagrant@homestead:~$ composer config -g repo.packagist composer https:\/\/packagist.phpcomposer.com\nvagrant@homestead:~$ composer global require &quot;laravel\/installer&quot;\nvagrant@homestead:~$ laravel -V\nLaravel Installer 1.3.5\nvagrant@homestead:~$ cd www\/\nvagrant@homestead:~\/www$ laravel new yezhou\nvagrant@homestead:~\/www$ cd yezhou\/\nvagrant@homestead:~\/www\/yezhou$ php artisan -V\nLaravel Framework 5.4.18<\/code><\/pre>\n<h3>Laravel\u6d4b\u8bd5<\/h3>\n<p>\u6b64\u65f6\u518d\u6253\u5f00\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"http:\/\/yz.app\/\">http:\/\/yz.app\/<\/a><\/p>\n<p>\u5373\u53ef\u770b\u5230\u719f\u6089\u7684Laravel\u9875\u9762~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vagrant\u811a\u672c\u5b89\u88c5 Vagrant\u547d\u4ee4\u53ea\u80fd\u8bc6\u522bVagrantfile\uff0c\u901a\u8fc7Homestead\/Vagran [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[140],"class_list":["post-434","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-homestead"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=434"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/434\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}