如何在Windows上使用Homestead安装Laravel-简单方法

汝臻
2023-12-01

The laravel documentation recommends using Homestead (a pre-packaged all in one vagrant box that includes Ubuntu 16.04, PHP 7.1, Nginx, Composer) to install laravel. Setting up a laravel project is easy, once you have homestead running on your machine.

laravel 文档建议使用Homestead(预先包装在一个无所事事的盒子中,其中包括Ubuntu 16.04,PHP 7.1,Nginx,Composer)来安装laravel。 一旦您的机器上运行了宅基地,设置laravel项目就很容易了。

In this article, we will be looking at a simple approach to installing laravel on a windows system.

在本文中,我们将研究在Windows系统上安装laravel的简单方法。

先决条件 (Prerequisites)

To get started, install the following;

首先,安装以下内容;

Git : Git will serve as an SSH client and we will be using Git Bash shell as our command line throughout the setup. Click here to download and install git on your system.

Git :Git将充当SSH客户端,在整个安装过程中,我们将使用Git Bash shell作为命令行。 单击此处下载并在您的系统上安装git。

Sublime text: This will serve as the text editor for building application. Click here to download and install sublime text. Or you can install any text editor of your choice like VS code, and atom.

Sublime text :它将用作构建应用程序的文本编辑器。 单击此处下载并安装崇高文本。 或者,您可以安装您选择的任何文本编辑器,例如VS代码atom

After installing git, open git bash and generate an ssh key pair. To achieve this, go to the home directory and run the command:

安装git后,打开git bash并生成一个ssh密钥对。 为此,请转到主目录并运行以下命令:

ssh-keygen -t rsa -C "youremail@mail.com"

主要安装 (Main Installation)

Step one: To get started with the installation, we will have to download and install virtual box. Click here to download and install the windows installation setup.

第一步 :要开始安装,我们将必须下载并安装virtual box。 单击此处下载并安装Windows安装设置。

Step two: At this point, we will install vagrant which will serve as a container for homestead . Download and install vagrant for Windows.

第二步 :在这一点上,我们将安装vagrant,它将用作宅基地的容器。 下载并安装Windows版的vagrant

Step three: Having installed virtual box and vagrant, we can add laravel to the vagrant box. Now open the Git Bash, and in the home directory, run this command:

第三步 :安装了虚拟盒子和无业游民之后,我们可以将laravel添加到无业游民的盒子中。 现在打开Git Bash,然后在主目录中运行以下命令:

vagrant box add laravel/homestead

Wait for it to download. Select the option for virtualbox, in my case, it is 2. Press enter and wait for it to download the box.

等待下载。 选择virtualbox的选项,在我的例子中是2。按Enter键并等待其下载。

Step four: Install homestead in your home directory, by running this command:

第四步:运行以下命令,将homestead安装在主目录中:

git clone https://github.com/laravel/homestead.git Homestead

Once this is done, using git bash change directory to the Homestead folder and run this command:

完成此操作后,使用git bash将目录更改到Homestead文件夹并运行以下命令:

init.bat

配置宅基地 (Configure homestead)

Now we are ready to configure homestead. Open sublime text, go to file, open folder and select the homestead folder. It is located on C:/Homestead. Open the Homestead.yaml file as shown in the diagram below

现在我们可以配置家园了。 打开崇高文本,转到文件,打开文件夹并选择homestead文件夹。 它位于C:/ Homestead。 如下图所示打开Homestead.yaml文件

Our focus will be on folders and sites section in the Homestead.yaml file.

我们的重点将放在Homestead.yaml文件中的“文件夹和站点”部分。

-map: ~/Code

-map:〜/代码

Simply means the folder on your local machine for your projects.

只是意味着您本地计算机上的项目文件夹。

to: /home/vagrant/Code

到:/ home / vagrant / Code

Simply means the folder on the virtual machine, which will sync to the directory on the local machine.

只是表示虚拟机上的文件夹,它将同步到本地计算机上的目录。

Create a folder (I named mine sites) for your projects in the home directory of your local machine. Mine is located at C:/Users/username/sites.

在本地计算机的主目录中为您的项目创建一个文件夹(我将其命名为我的站点)。 我的位于C:/ Users /用户名/ sites。

In the Homestead.yaml file, change the –map: ~/Code to -map: ~/sites.

在Homestead.yaml文件中,将–map:〜/ Code更改为-map:〜/ sites。

Also change the /home/vagrant/Code to /home/vagrant/sites

还将/ home / vagrant / Code更改为/ home / vagrant / sites

现在安装Laravel (Now Install Laravel)

Now download the laravel installer by running this command:

现在,通过运行以下命令下载laravel安装程序:

Composer global require “laravel/installer”

Once that is done, run this command:

完成后,运行以下命令:

vagrant up

then this command:

然后这个命令:

vagrant ssh

will show the sites folder that was created on the local machine

将显示在本地计算机上创建的sites文件夹

Change directory into the sites folder and you are ready to start your laravel project.

将目录更改为sites文件夹,即可开始启动laravel项目。

Run this command:

运行以下命令:

laravel new testsite

and wait for it to download. Yippee! We are ready to start

并等待其下载。 pp! 我们准备开始

“building something amazing”!
“打造惊人的东西”!

配置Nginx站点 (Configure the Nginx site)

To access our laravel project on our web browser, we simply configure the sites property

要在网络浏览器上访问laravel项目,我们只需配置sites属性

“The sites property allows you to easily map a “domain” to a folder on your Homestead environment.” — doc

“ sites属性使您可以轻松地将“域”映射到Homestead环境中的文件夹。” — doc

Let’s create a domain for our test site . Open notepad as an administrator, go to file and open hosts that is C:/Windows/System32/Drivers/etc/hosts and assign the 127.0.0.1 to testsite.dev

让我们为测试站点创建一个域。 以管理员身份打开记事本,转到文件并打开C:/ Windows / System32 / Drivers / etc / hosts主机,然后将127.0.0.1分配给testsite.dev

On the homestead.yaml file, change the homestead.app to testsite.dev and /home/vagrant/Code/Laravel/public to /home/vagrant/sites/public and issue the command:

在homestead.yaml文件上,将homestead.app更改为testsite.dev,将/ home / vagrant / Code / Laravel / public更改为/ home / vagrant / sites / public并发出以下命令:

vagrant provision

Now open your web browser and enter testsite.dev:8000. Your browser will display the laravel page as shown on the cover photo.

现在打开您的Web浏览器并输入testsite.dev:8000。 您的浏览器将显示laravel页面,如封面照片所示。

If this article was helpful, kindly share it on social media so others can see it.

如果这篇文章有帮助,请在社交媒体上分享,以便其他人可以看到。

翻译自: https://www.freecodecamp.org/news/a-simplified-approach-to-installing-laravel-using-homestead-on-windows-f5fc50e59af0/

 类似资料: