Home > PHP Framework > ThinkPHP > body text

About Laradocke running TP project

藏色散人
Release: 2020-10-13 10:18:11
forward
2695 people have browsed it

The following is the thinkphp framework tutorial column to introduce to you about the Laradocke running TP project, I hope it will be helpful to friends in need!

About Laradocke running TP project

1. When laradock comes up for the first time, the build process is very slow

Due to the problem of pulling the container The image is overseas by default, so before docker-compose up the container, look for the following text in the .env file

CHANGE_SOURCE=``false

and then change false to false true, and look for the following text

#UBUNTU_SOURCE=aliyun

Remove the # in front, that is, remove the comment, and change the default foreign mirror source to the domestic one with the fastest speed The mirror source of aliyun

Then change the time zone of the workspace to China time zone, find the following text

WORKSPACE_TIMEZONE=UTC

Change UTC to PRC

Then execute the command

docker-compose up -d nginx mariadb

Choose the container you need to start

Compare it yourself After the build time, under 20M bandwidth, if the mirror source is not changed, it can be as fast as one hour or as slow as one day. After the change, it only takes 10min

2. laradock is starting An error is reported during the container build workspace process

If the relevant text "raw.githubusercontent.com" appears, bind the domain name to the ip in local hosts

Take linux as an example

vim ``/etc/hosts

Enter "199.232.28.133 raw.githubusercontent.com" in the file

3. Composer install is slow

After installing laradock, use git to pull the tp5 framework from the third-party hosting warehouse in the worksapce container, and then install the framework dependencies. At this time, composer install is very slow. If you need to replace the domestic source, execute the following command

composer config -g repo.packagist composer https:``//packagist``.phpcomposer.com

4. Composer ignores the version number to install

If composer install encounters an error message Your requirements could not be resolved to an installable set of packages., you can ignore the version number for installation. , execute the following command

composer ``install --ignore-platform-reqs

5. Composer installs the database migration tool for tp5

The migration tool for tp5.0 is 1., and for tp5.1 is 2.. If the version number is not specified, the latest one will be installed by default. Migration tool, execute the following command

composer require topthink``/think-migration``=1.*

##6. When configuring the database connection in tp5 in laradock, the host fills in the container name

I use the mariadb container, so the following configuration

'host'=>'mariadb'

7. tp5 gives full permissions to runtime

##hmod -r runtime 777

8. TP5 captures exceptions thrown by mysqlAdd a backslash in front of the catch parameter Exception to indicate that the capture will start from the lowest Exception

catch``(\Exception)

9. When doing the image upload interface, mkdir reported an error no permission In order to facilitate the reference of pictures, I specified the picture storage directory as public/uploads, but an error was reported. It can be solved by giving public full permissions

chmod -r public 777

10. Permission verification for the back-end interfaceoauth2 is a very good authorization mechanism. PHP has a good library https://github.com/thephpleague/ oauth2-server, but it is very helpless. Unlike laravel, which has passport, it also supports Drupal, cakephp and other frameworks

It is also good to use Json-web-token https://github.com/lcobucci/jwt

11. Cross-domain processingIn tags.php in the application directory, add the file that is executed when the application is initialized. For example, I put the cross-domain The domain is placed in the applicationapi/behavior/CORS.php file, and header

// Application initialization``'app_init'

is issued during the application initialization process => [` `'app\\api\\behavior\\CORS'``], Cross-domain files

<?php
namespace app\api\behavior; use think\Response; class CORS{ public function appInit(&$params)
    { header(&#39;Access-Control-Allow-Origin: *&#39;);
    header("Access-Control-Allow-Headers: token,Origin, X-Requested-With, Content-Type, Accept");
    header("Access-Control-Allow-Methods:GET, POST"); 
        if (request()->isOptions()) {
            exit();
        }
    }}
Copy after login

12. git push/pull requires identity verification, enter the user name and password multiple times

In the Linux environment, in the warehouse directory Execute

git config --global credential.helper store

##13. git push stuck

Set to send packets without borders, and set the HTTP request buffer to be larger

git config --global sendpack.sideband false git config --global http.postBuffer 524288000

14. nginx does not support tp5 pathinfo

Change the .conf file configuration corresponding to the project

<?php
namespace app\api\behavior; use think\Response; class CORS
{ public function appInit(&$params)
    { header(&#39;Access-Control-Allow-Origin: *&#39;);
    header("Access-Control-Allow-Headers: token,Origin, X-Requested-With, Content-Type, Accept");
    header("Access-Control-Allow-Methods:GET, POST"); 
        if (request()->isOptions()) {
            exit();
        }
    }
}
Copy after login

Change Former location ~ .php$ {

 location ~ \.php { 
    try_files $uri /index.php =404;
    fastcgi_pass php-upstream;
    fastcgi_index index.php;
    fastcgi_buffers 16 16k;
    fastcgi_buffer_size 32k;
    # 添加部分↓↓↓↓
    # Set var PATH_INFO
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    #  添加部分↑↑↑↑
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;   
    #fixes timeouts
    fastcgi_read_timeout 600;
    include fastcgi_params;}
Copy after login

I will find time to learn the specific options

14. Docker configuration domestic source

sudo tee /etc/docker/daemon.json <<-'EOF'

##vim /etc/docker/daemon.json

Enter the following content, the address can be selected by yourself

{
  "registry-mirrors": ["https://uxk0ognt.mirror.aliyuncs.com"]
  }
Copy after login
#Then execute the following instructions

systemctl daemon-reload

systemctl restart docker

##NoteAs we all know, cloning from github has always been It is relatively slow. You can choose to use Code Cloud to import commonly used warehouses into your own Code Cloud workspace in advance. When you need to use it, clone it through Code Cloud                  

                                             

The above is the detailed content of About Laradocke running TP project. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!