It is recommended to use the evolved version of the Docker environment, deviny/phpenv.
https://www.ccc.tc/article/deviny-phpenv-summary
Below the dividing line is the old data.
Foreword:
For me, Laravel is an extremely fast-evolving PHP framework and a framework for all-round solutions.
For example, this site uses the Facebook login function, which is implemented through Laravel's official package socialite.
The framework can help us with a lot of things, such as queues, file storage, authentication mechanism, etc., the framework is all provided to us, why do we do it ourselves?
Through the various functions provided by the Laravel framework, we can do many things for us.
The minimum environment requirements for PHP in previous versions of Laravel are listed below: (Note: PHP is no longer installed by default in the latest version of MacOS)
Laravel version | PHP requirements |
---|---|
Laravel 4.2 | PHP>=5.4 |
Laravel 5.0 | PHP>=5.4, PHP<7 |
Laravel 5.1 | PHP>=5.5.9 |
Laravel 5.2 | PHP>=5.5.9 |
Laravel 5.3 | PHP>=5.6.4 |
Laravel 5.4 | PHP>=5.6.4 |
Laravel 5.5 | PHP>=7.0 |
Since the evolution of Laravel is really fast, and the system requirements are getting higher and higher from generation to generation, of course, the official development and execution environments such as Homestead and Valte are also provided for us to use.
Let me tell you first, I am not a hater, since this article mentions the need to use Docker to build a Laravel development environment,
Of course I have a little personal opinion on Homestead and Valte:
Personally, the Vagrant used by Homestead is really a bit outdated. In fact, the concept of Vagrant is very good.
At least I have used him on my own project, but after using Docker,
I can use one word to describe my view on this situation, which is "Ji Sheng Yu He Sheng Liang", although Vagrant and Docker are of course different,
This article will not discuss it, but for the use in the development environment,
Docker just wins with its second-level startup speed and its microservice architecture.
Let’s talk about Valte again. Valate needs to run on Mac, and use homebrew to install some things that Mac OS does not provide, such as a new version of PHP.
The execution speed is of course super fast, but the flexibility is insufficient.
After the installation, it eats up my port 80. What I want to run is not only Laravel, but I may need to switch to a lower version of PHP to operate. Code solution,
Do you need to use brew to install some things with Valte, database adjustment or php version change, or self-extending PHP plug-ins? It doesn’t seem so flexible to me.
Relatively speaking, with Docker, we can choose the image that others have built for us. If necessary, we can also expand and build the image environment we need. We only need to adjust the configuration file of the Dockerfile by ourselves, which is very free: p.
So using Docker to build and execute Laravel's development environment seems to solve my problem of startup speed and flexibility.
About D-Laravel
At present, there are already quite a few docker + laravel development environments. Why do I still have to build one? Is it because I am too full to eat?
If you are a user who is slightly familiar with Docker, you should know that the official version must be marked as official on Dockerhub.
Relatively, it means that he is relatively safe, and I don't have to check whether there is something that shouldn't be buried inside.
And D-Larave is based on the official image official.
The PHP image is also rebuilt with Docker's php official image (because it needs to conform to the Laravel environment),
So you can use it with confidence.
If you are interested in how to rebuild D-Laravel's PHP, you can refer to the video below.
Of course, D-Laravel not only provides docker-compose configuration files, but also provides simplified bash commands.
For beginners of Laravel or Docker, they can create a Laravel development environment very quickly.
And it's not limited to the Laravel development environment, whether you know docker or not, you can use it immediately, and it is quite convenient for daily use.
How to download and use D-Laravel?
However, the main operating and testing environment for D-Laravel is Mac OS.
There should be no problem executing on Linux. If you have problems executing on Linux, you can open a PR to me, thank you.
If you are on Windows 10, you need to confirm that your environment under gitbash has installed a working laravel installer.
The operability here refers to the simple bash commands (./console and ./create) provided by D-Laravel,
If you know how to use docker-compose, there is no problem in executing it on Windows 10, and it can be executed across platforms.
1. First of all, of course, our computer needs to install Docker first, I hope you have installed it.
https://docs.docker.com/docker-for-mac/
2. Download D-Laravel's Repo directly
https://github.com/DevinY/dlaravel
3. Start, it’s as simple as that, enter the dlaravel folder that was unlocked after downloading, and then enter the command:
./create test1
Here is the finished screen:
The above is done, it is simple enough!!
You open your browser, enter the URL
http://test1.dev:32770
You can see the screen of the Laravel project, and the database of test1 and the settings of .env have been automatically built.
During the startup process, the bash program needs to adjust /etc/hosts and add the domain name of test1.dev, so it will ask for the system password, so this is a normal phenomenon, don't worry.
D-Laravel is completely Open Source. If you are still a little scared, you can check by yourself what the host on the bash of create does.
Without any configuration file adjustments, the startup of D-Laravel will be a random port, as shown in the figure above 32770
Laravel's Project will be created in the folder of sites/test1.
If we want to stop, we can use ./console down.
The create command not only helped us build a Laravel Project, but also helped me build a test1 database.
I don't want to use the bash provided by D-Laravel at all. Is there any way to build a Laravel development environment with docker-compose on D-Laravel?
This is of course possible. The bash of create and console only provides a step to simplify the manual setting of Laravel and the official command of docker-compose of Docker.
About manually creating a Laravel Project and starting docker-compose
The following will directly explain how to create it manually. Of course, I hope you need to know,
What are the basic instructions of laravel installer and docker-compose .
In fact, the steps to create manually are not difficult.
1. Under the dlaravel folder, we directly create a laravel project to the sites folder through the laravel installer.
In the picture below, I added a test2 project to the sites folder
2. Manually modify the /etc/hosts file, please use your own editor, root authority is required.
If you don't know how to edit vi, please don't execute the command below, I'm afraid you won't be able to exit the Vim editor, or destroy the hosts file.
sudo vi /etc/hosts
After entering, add at the bottom of the hosts file, 127.0.0.1 test2.dev
Please note that the name must be * .dev , which is the default name of D-Laravel's nginx configuration file. *Represents your project folder name.
127.0.0.1 test2.dev
The alternative, of course, is to use D-Laravel's bash to help you modify it.
./create --host test2
3. Start D-Laravel's docker containers.
-d means to execute containers in the background.
docker-compose up -d
4. As for the establishment of the database and the setting of .env, just enter the sites/test2 by yourself.
I am not very good at writing articles. If you have any questions about the content of the article, please leave a message to me.
For detailed instructions and usage of D-Laravel, please go to the official Repo:
https://github.com/DevinY/dlaravel
No Comment
Post your comment