Methods for defining the environment

Source: Internet
Author: User
I don't know how everyone defines the running environment of their own projects. I am talking about the environment: Online (master), testing (beta), Development (dev), local (local) this is like setting the host of the machine. {code ...} I don't know what is better than this one... I don't know how everyone defines the running environment of their own projects. I am talking about the environment: Online (master), testing (beta), Development (dev), local (local) this is done by setting the host of the machine.

// Select if (gethostname () = 'tbj-test') {define ('env _ mode', 'dev');} elseif (gethostname () === 'tbjbeta ') {define ('env _ mode', 'beta');} elseif (strpos (gethostname (), 'tbj-') === 0) {define ('env _ mode', 'local');} else {define ('env _ mode', 'online ');}

I don't know what is better than this?

Reply content:

I don't know how everyone defines the running environment of their own projects. I am talking about the environment: Online (master), testing (beta), Development (dev), local (local) this is done by setting the host of the machine.

// Select if (gethostname () = 'tbj-test') {define ('env _ mode', 'dev');} elseif (gethostname () === 'tbjbeta ') {define ('env _ mode', 'beta');} elseif (strpos (gethostname (), 'tbj-') === 0) {define ('env _ mode', 'local');} else {define ('env _ mode', 'online ');}

I don't know what is better than this?

I have two solutions:
First, write it in the configuration file. However, this method is not easy to use, especially when the project has a version library that requires continuous integration, it will be more troublesome.
Second, it is identified by specific files. For example, there isrelease.lockThe program detects this file as an online version, and can ignore these identification files when entering the version library.

Almost, it is on the server, custom environment variables
For example, laravel is in the nginx configuration file.

fastcgi_param  APP_ENV            testing;

Then, the suffix of the. env file is loaded according to the environment variable, and The. env. testing configuration file is loaded.
So now we are more accustomed to using this form.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.