PHP website automation configuration implementation method (mandatory), php mandatory

Source: Internet
Author: User
Tags php template

PHP website automation configuration implementation method (mandatory), php mandatory

Yii2 is always used as a project, and automatic configuration is used, but it has not been configured on its own. I checked the yii initialization code at noon and found it was php!

Yii2

Initialize project code

Therefore, we certainly can use php for Project Creation. So I created a new folder named autoConfig, which created an init and wrote the following code:

if(!file_exists('./uploads/')){ if(!mkdir('./uploads/')){  echo 'fail to make ./uploads/ file!'; }else{  echo 'make ./uploads/ success!'; }}

That is, a simple code for automatically creating the uploads folder. When the uploads Folder does not exist, the uploads folder is automatically created. Run the following command on the terminal:

Automatic Configuration Creation

Open the directory of the same level and find that the uploads folder has been created. Therefore, if we want to create configuration information, we can directly use php code for configuration, there is nothing very advanced.

I will write another demo2:

Objectives:

1. Create the uploads directory in the root directory of the website.

2. Copy the config. php template from the common directory to the admin directory.

3. generate an install. lock file in the root directory.

4. After the website is initialized, you must delete install. lock from the root directory. Otherwise, the initialization cannot be repeated.

Now, let's take a look at our current directory structure:

Modify the init Code as follows:

<? Php // set the persistent Connection to visually view the execution status of each step. header ("Connection: Keep-Alive"); header ("Proxy-Connection: Keep-Alive "); set_time_limit (0);/* checks whether Initialization is repeated */if (file_exists ('. /install. lock') {echo 'system has been initialized. to reinitialize the system, delete install. lock '. "<br>";}/* Create the uploads folder */if (! File_exists ('./uploads/') {if (! Mkdir ('. /uploads/') {echo' the uploads folder cannot be created in the root directory '. "\ n";} else {echo 'uploads folder created successfully '. "\ n";}/* Create/admin/config. PHP file */if (! File_exists ('. /admin/config. php ') {if (copy ('. /common/config. php ','. /admin/config. php ') {echo 'admin/config. php created successfully! '. "\ N";} else {echo 'admin/config. php creation failed! '. "\ N" ;}}/* generate the install lock. lock */touch ('Install. lock'); echo 'configuration is complete. If any configuration fails, manually execute '. "\ n"; clearstatcache () ;}?>

Run the following command on the terminal:

Effect:

Obviously, admin/config. php has been created, the uploads directory has been created, and install. lock has been created. PHP's automated configuration is so simple!

The above PHP website automation configuration implementation method (mandatory) is all the content shared by the editor. I hope to give you a reference, and hope you can provide more support to the customer's house.

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.