Laravel Homestead: Convenient local development environment
Want to get started with Homestead quickly? Please check the quick tips. For more details, please continue reading.
Simply put, Laravel Homestead is:
An official pre-packaged Vagrant "box" provides you with an excellent development environment without installing PHP, web server and any other server software on your local machine.
In other words, it automatically completes what we did manually through Vagrant and PuPHPet in previous articles (such as those articles).
So, how is it different from the normal Vaprobash/Vagrant/PuPHPet settings? let's see.
Unlike other popular solutions to simplify Vagrantfile settings, Homestead rarely fails to start and can be fixed in minutes if it fails. If you've dealt with GUI Vagrant solutions, you've probably noticed how rare it is to get everything running after the first vagrant up. There are always problems such as outdated or overly updated Puppets, outdated Ubuntu repositories, or some other mysterious bug that requires a lot of "forum searches" to resolve. Homestead simply...works.
Homestead is installed on Ubuntu 14.04 with PHP 5.5, so it's as new as possible and won't go into beta/RC territory, Nginx (because we're all giving up Apache now, right?), MySQL and Postgres, so you're Heroku (their default is Heroku Postgres), Node (for all static resource compilation requirements, background tasks, and other less important businesses), Redis, Memcached, and Beanstalkd (for all caching and queueing requirements), Laravel Envoy (for all remote server task requirements) and Fabric Hipchat extensions so that you can deploy applications through Hipchat (also known as chatops).
Homestead is official, which is made by Taylor Otwell, the father of Laravel, meaning it is automatically considered to meet certain standards. While the Laravel community is not without controversy (who cares what a class is called? If a revolutionary new framework calls a model potato, look or rocket, as long as the potato/looking/rocket can work, that's totally OK), Taylor is involved, The uniqueness of this gives it the simplicity and quality that it needs very much in today's PHP world. We've seen too many open source projects ruined by team egos, avid contributors or incompetent all-rounders, and I personally think Taylor's almost exclusive involvement in Laravel's improvements are to make it stand out from other projects and really make it quality Reasons for competing with Phalcon.
Homestead is his own project, known as the "official local development environment", and he will do everything he can to maintain its high quality and ensure it is always effective. Any shortcomings will affect his reputation. In today's PHP, the best guarantee of long-term reliability of a project is that it is owned (mainly) by someone who cares a lot about quality.
Setting up Homestead is easy. Follow the instructions on the documentation page, you just need to add the Homestead box to your Vagrant (if you haven't already) and clone the repo.
There is another extra step we are not used to - setting up SSH. This is also very simple, you need to edit your Homestead.yaml file after cloning the repo. Just point the relevant line to your SSH key and that's fine. In my case, I had to change the following:
<code>--- ip: "192.168.10.10" memory: 2048 cpus: 1 authorize: /Users/me/.ssh/id_rsa.pub keys: - /Users/me/.ssh/id_rsa folders: - map: /Users/me/Code to: /home/vagrant/Code sites: - map: homestead.app to: /home/vagrant/Code/Laravel/public variables: - key: APP_ENV value: local</code>
to
<code>--- ip: "192.168.10.10" memory: 2048 cpus: 1 authorize: C:\Users\Bruno\.ssh\id_rsa.pub keys: - C:\Users\Bruno\.ssh\id_rsa folders: - map: D:\VM\vagrant_boxes\homestead\Homestead to: /home/vagrant/Code sites: - map: homestead.app to: /home/vagrant/Code/Laravel/public variables: - key: APP_ENV value: local</code>
After we run vagrant up, everything should be ready:
As you can see, my process produced some errors, but it still ended up running well:
Homestead opens certain important ports by default, which makes it a breeze to manage and maintain databases and other installed software on virtual machines from the host. For example, to connect to an installed MySQL database using MySQL Workbench installed on the host (in my case Windows), you simply enter the required credentials into the connection window:
The default MySQL and Postgres ports are simply attached with a zero (for example, MySQL is 33060 instead of 3306), which allows you to connect to localhost (127.0.0.1:33060) and grant access to the database on the virtual machine.
The potential drawback of this is that you cannot run multiple boxes at the same time without changing the port due to conflicts. It would be even better if the database connection is just open and can be connected to the VM's IP as usual, but this is easy to fix - just look at some of my previous vagrantfiles to see how it looks.
Since Homestead is official, you can rest assured that if you encounter any problems, there will be a huge community to help at any time. You will have the same starting point as everyone using Homestead, and the problem will automatically become easier to diagnose.
Adding new sites (virtual hosts) is a breeze because of the ease of adjusting configuration files when fine-tuning Homestead - you don't even have to deal with a single virtual host configuration in nginx files.
By default, the Homestead.yaml file registers a single virtual host named "homestead.app" which serves as the default site for the virtual machine server configuration. You can access the virtual machine's IP address in your browser (regular port 80: https://www.php.cn/link/173e2619a507a324eb10f969df13a372:
<code>--- ip: "192.168.10.10" memory: 2048 cpus: 1 authorize: /Users/me/.ssh/id_rsa.pub keys: - /Users/me/.ssh/id_rsa folders: - map: /Users/me/Code to: /home/vagrant/Code sites: - map: homestead.app to: /home/vagrant/Code/Laravel/public variables: - key: APP_ENV value: local</code>
You have registered a new virtual host. Then, if you add the name of that new site to your hosts file (on any platform), you can access the new site by name through your browser, you only need to access it via port 8000: https ://www.php.cn/link/e1490523b8cd2c130b29656613850cf8.
This process allows you to add as many virtual hosts to the virtual machine as needed, thereby providing services for multiple projects from a single box.
In some missing features, I will list the following:
Laravel Homestead is by far one of the best and most stable PHP Vagrant environments. It starts very fast, contains few dependencies that can break at runtime and configure a modern, latest PHP environment for hacking to start immediately.
Are you using it? Please let us know.
Laravel Homestead is a pre-packaged Vagrant box that provides an excellent development environment without installing PHP, web servers and any other server software on the local machine. It is very beneficial because it provides a consistent development environment on multiple operating systems. This means that all team members can use the same environment, whether they are using Mac, Windows, or Linux.
To install Laravel Homestead, you first need to install VirtualBox 6.x, VMWare, Parallels, or Hyper-V as providers. Then, install Vagrant. After the installation is complete, you can add the Laravel Homestead box to your Vagrant installation using the command "vagrant box add laravel/homestead". Finally, you can install Homestead by cloning the repository to your host.
Laravel Homestead requires Vagrant and a hypervisor such as VirtualBox, VMWare, or Parallels. It also requires at least 1GB of RAM, but it is recommended to allocate 2GB or more if possible. The host should have a 64-bit processor and sufficient disk space to store your project files and databases.
Laravel Homestead is configured through the Homestead.yaml file. This file allows you to map project directories to your Homestead environment, configure shared folders, and set up Nginx sites. You can also specify PHP version, database type, and other settings in this file.
To update Laravel Homestead, you can use the "vagrant box update" command. This will update the Vagrant box to the latest version. However, remember to back up your Homestead.yaml file and any other important data before updating, as the update process may overwrite these files.
Yes, Laravel Homestead is not limited to Laravel projects. You can use it with any PHP project that can run on a PHP 7.4 or PHP 8.0 server. This includes frameworks such as Symfony, CakePHP, Yii, etc.
Laravel Homestead offers a variety of troubleshooting tools. You can use the "vagrant up" command with the "-debug" flag to get the detailed log. You can also SSH into the Homestead box and check for any errors in the Nginx, PHP and MySQL logs.
Laravel Homestead is pre-installed with MySQL, Postgres, SQLite and Memcached. You can connect to these databases using the default credentials provided in the Homestead documentation. You can also connect to these databases using tools such as Sequel Pro or MySQL Workbench.
Yes, Laravel Homestead supports running multiple projects. You can map multiple project directories in the Homestead.yaml file and configure a separate Nginx site for each project. Each project has its own URL and is accessible independently.
To uninstall Laravel Homestead, you can use the "vagrant destroy" command. This will remove the Homestead box and all its data from your machine. However, remember to back up any important data before running this command, as it will delete all your project files and databases.
The above is the detailed content of 6 Reasons to Move to Laravel Homestead. For more information, please follow other related articles on the PHP Chinese website!