Deploy ThinkPHP Framework

Forward

Cloud Help supports automatic identification and automatic deployment of source code and various frameworks. We can directly submit the repository address of github, or submit the code to the Gridworkz git code repository.

Code Construction

Cloud Gang will download and build dependencies according to the configuration of composer.json. As we give the example below, we recommend that you use the version of php5.6 or higher to better support ThinkPHP5.

Example of composer.json file:

{
    "name": "topthink/think",
    "description": "the new thinkphp framework",
    "type": "project",
    "keywords": [
        "framework",
        "thinkphp",
        "ORM"
    ],
    "homepage": "http://thinkphp.com/",
    "license": "Apache-2.0",
    "authors": [
        {
            "name": "gdevs",
            "email": "gdevs@gridworkz.com"
        }
    ],
    "require": {
        "php": ">=5.6.0",
        "topthink/framework": "^5.0.4",
        "topthink/think-captcha": "^1.0.7",
        "topthink/think-testing": "^1.0"
    }, 
    "extra": {
        "think-path": "thinkphp"
    },
    "config": {
        "preferred-install": "dist"
    }
}

If there is a composer.lock file in the root directory of the code, be sure to delete it, otherwise the platform will read the version information from here. Gridworkz will automatically generate this file during the build process.

Multiple composer.json

The approximate structure of a project is as follows:

index.php
composer.json
app/
vendor/
vendor/topthink/
vendor/topthink/think-captcha/
vendor/topthink/think-captcha/
vendor/topthink/think-captcha/composer.json

By default, composer.json is the main configuration file and does not rely on loading the vendor/topthink/think-captcha/composer.json file in the secondary directory. Need to be added in the main configuration file composer.json in the root directory

"config": {
        "preferred-install": "dist"
    },
# Add as follows:
"scripts":{
	"composer install": "vendor/topthink/think-captcha"
    }

Web Server Selection

You don’t need to install and configure your own web server. Cloud Gang will automatically provide apache and nginx servers for you to choose from, because the ThinkPHP framework uses .htaccess files to customize the redirection rules of apache, so you should choose apache acts as a web server.

Set Document Root

The entry file is located in public/index.php. The location of the entry file is designed to make application deployment more secure. The public directory is a web-accessible directory, and other files can be placed under non-WEB access directories.

Many user applications do not use the code and directory as the home directory of the Web Server. For example, the ThinkPHP5 framework requires the Document root to be the public directory. This requires us to set the Document root to the public secondary directory in the root directory.

The configuration method is to write a Procfile file in the root directory of the code, the content is as follows:

web: vendor/bin/heroku-php-apache2 public/

This configuration is to tell the platform to use apache as the web server, and use the public directory as the web root directory.