【vmwarevm】Ubuntu+Homestead+Laravel
==========
Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-54-generic x86_64)
* Homestead v9.0.0 released
* Settler v8.0.0 released
==========
$ cd~
$ cd .composer/
$ ls
auth.json cache composer.json composer.lock config.json vendor
$ cd vendor/
$ ls
autoload.php bin composer doctrine guzzlehttp hirak illuminate laravel nategood nesbot psr ralouphie symfony
$ composer update
==========
$ git --version
git version 2.17.1
$ composer --version
Composer version 1.8.6 2019-06-11 15:03:05
查看`composer`当前使用仓库源
composer config -g repo
修改`composer`默认仓库为使用`
composer config -g repositories.packagist composer http://packagist.phpcomposer.com
$ vi /home/vagrant/.composer/config.json
{
"config": {"secure-http": false},
"repositories": {
"packagist": {
"type": "composer",
"url": "http://packagist.phpcomposer.com"
}
}
}
==========
$ cd~
git clone https://github.com/laravel/homestead.git Homestead
$ cd Homestead/
$ git checkout v6.1.0
$ bash init.sh
Homestead initialized!
配置 Homestead
$ sudo vi Homestead.yaml
配置提供器
Homestead.yaml 中的 provider 参数设置决定了你用的是哪一个 Vagrant 提供器:virtualbox、vmware_fusion、vmware_workstation 或者 parallels。你可以根据自己的喜好来设置提供器:
provider:vmware_fusion
配置共享文件夹
Homestead.yaml 文件的 folders 属性里列出所有与 Homestead 环境共享的文件夹。这些文件夹中的文件若有变更,它们会保持本地机器与 Homestead 环境之间同步。你可以根据需要配置多个共享文件夹:
folders:
- map: ~/codeLaravel
to: /home/codeLaravel
配置 Nginx 站点
sites 属性将 域名 映射到 homestead 环境中的文件夹。Homestead.yaml 文件中已包含示例站点配置。同样的,你也可以增加多个站点到你的 Homestead 环境中。 Homestead 可以同时为多个 Laravel 应用提供虚拟化环境:
sites:
- map: homestead.test
to: /home/codeLaravel/public
必须将在 Nginx 站点中所添加的「域名」也添加到服务器的 hosts 上。 hosts 文件会将 Homestead 站点的请求重定向到 Homestead Box 中。在 Mac 或 Linux 上,该文件位于 /etc/hosts。添加的内容如下所示:
192.168.10.10 homestead.app
要将 Homestead 直接安装到项目中,需要使用 Composer:
$ cd ~
$ mkdir -p code
$ cd code
$ composer require laravel/homestead --dev
Warning: Accessing packagist.phpcomposer.com over http which is an insecure protocol.
Warning: Accessing packagist.phpcomposer.com over http which is an insecure protocol.
Warning: Accessing packagist.phpcomposer.com over http which is an insecure protocol.
Using version ^9.0 for laravel/homestead
./composer.json has been created
Warning: Accessing packagist.phpcomposer.com over http which is an insecure protocol.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 9 installs, 0 updates, 0 removals
- Installingsymfony/polyfill-ctype (v1.11.0): Loading from cache
- Installingsymfony/yaml (v4.3.3): Loading from cache
- Installingsymfony/process (v4.3.3): Loading from cache
- Installingpsr/container (1.0.0): Loading from cache
- Installingsymfony/service-contracts (v1.1.5): Loading from cache
- Installingsymfony/polyfill-php73 (v1.11.0): Loading from cache
- Installingsymfony/polyfill-mbstring (v1.11.0): Loading from cache
- Installingsymfony/console (v4.3.3): Loading from cache
- Installinglaravel/homestead (v9.0.7): Loading from cache
symfony/service-contracts suggests installing symfony/service-implementation
symfony/console suggests installing symfony/event-dispatcher
symfony/console suggests installing symfony/lock
symfony/console suggests installing psr/log (For using the console logger)
Writing lock file
Generating autoload files
Homestead 安装完后,可以使用 make 命令在项目根目录中生成 Vagrantfile 与 Homestead.yaml 文件。make 命令会自动配置 Homestead.yaml 文件中的 sites 及 folders 指令。
$ php vendor/bin/homestead make
Homestead Installed!
==========
虚拟机启动成功后,通过下面命令来新建一个名为 Laravel 的项目
$ cd ~/Code
$ composer create-project laravel/laravel Laravel --prefer-dist "5.8.*"
完成之后,访问 http://homestead.test 你能看到如下图所示界面,这是 Laravel 为我们生成默认界面。
【参考】
https://learnku.com/courses/laravel-essential-training/5.8/the-first-application-hello-laravel/4057
==========
==========