1. Install | advanced application template | Yii Chinese document 2.0.x

Posted by hybmg57 on Thu, 27 Jan 2022 05:28:48 +0100

install

requirement

PHP >= 5.6.0

Installing using Composer

If you don't Composer , please follow the instructions in the document Installation Yii Install according to the instructions in section.

After installing Composer, you can install the application using the following command:

composer create-project --prefer-dist yiisoft/yii2-app-advanced advanced

This command installs the advanced application template in a directory called advanced. If necessary, you can choose a different directory name to represent your own project.

Install from archive

Will from yiiframework.com Extract the downloaded archive file to a directory named advanced located directly under the Web root directory. Then follow the instructions given in the next section.

Prepare application

After installing the application, you must perform the following steps to initialize the installed application. These operations only need to be performed once.

  1. Open the console terminal, execute the init command and select dev as the environment.

    /path/to/php-bin/php /path/to/yii-application/init

    If script automation is used, init can be executed in non interactive mode.

    /path/to/php-bin/php /path/to/yii-application/init --env=Production --overwrite=All --delete=All
  2. Create a new database and adjust common / config / main local accordingly components['db '] configuration in PHP.

  3. Open the console terminal and execute the migration command / path / to / PHP bin / PHP / path / to / Yii application / Yii migrate

  4. Set the document root directory of the Web server:

    • For the front end / path / to / Yii application / frontend / Web /, and use the URL http://frontend.test/
    • For the backend / path / to / Yii application / backend / Web /, and use the URL http://backend.test/

    For Apache, use the following configuration:

        <VirtualHost *:80>
            ServerName frontend.test
            DocumentRoot "/path/to/yii-application/frontend/web/"
    
            <Directory "/path/to/yii-application/frontend/web/">
                # use mod_rewrite for pretty URL support
                RewriteEngine on
                # If a directory or a file exists, use the request directly
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                # Otherwise forward the request to index.php
                RewriteRule . index.php
    
                # use index.php as index file
                DirectoryIndex index.php
    
                # ...other settings...
            </Directory>
        </VirtualHost>
    
        <VirtualHost *:80>
            ServerName backend.test
            DocumentRoot "/path/to/yii-application/backend/web/"
    
            <Directory "/path/to/yii-application/backend/web/">
                # use mod_rewrite for pretty URL support
                RewriteEngine on
                # If a directory or a file exists, use the request directly
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                # Otherwise forward the request to index.php
                RewriteRule . index.php
    
                # use index.php as index file
                DirectoryIndex index.php
    
                # ...other settings...
            </Directory>
        </VirtualHost>

    nginx uses the following configuration:

        server {
            charset utf-8;
            client_max_body_size 128M;
    
            listen 80; ## listen for ipv4
            #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
    
            server_name frontend.test;
            root        /path/to/yii-application/frontend/web/;
            index       index.php;
    
            access_log  /path/to/yii-application/log/frontend-access.log;
            error_log   /path/to/yii-application/log/frontend-error.log;
    
            location / {
                # Redirect everything that isn't a real file to index.php
                try_files $uri $uri/ /index.php$is_args$args;
            }
    
            # uncomment to avoid processing of calls to non-existing static files by Yii
            #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
            #    try_files $uri =404;
            #}
            #error_page 404 /404.html;
    
            # deny accessing php files for the /assets directory
            location ~ ^/assets/.*\.php$ {
                deny all;
            }
    
            location ~ \.php$ {
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass 127.0.0.1:9000;
                #fastcgi_pass unix:/var/run/php5-fpm.sock;
                try_files $uri =404;
            }
    
            location ~* /\. {
                deny all;
            }
        }
    
        server {
            charset utf-8;
            client_max_body_size 128M;
    
            listen 80; ## listen for ipv4
            #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
    
            server_name backend.test;
            root        /path/to/yii-application/backend/web/;
            index       index.php;
    
            access_log  /path/to/yii-application/log/backend-access.log;
            error_log   /path/to/yii-application/log/backend-error.log;
    
            location / {
                # Redirect everything that isn't a real file to index.php
                try_files $uri $uri/ /index.php$is_args$args;
            }
    
            # uncomment to avoid processing of calls to non-existing static files by Yii
            #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
            #    try_files $uri =404;
            #}
            #error_page 404 /404.html;
    
            # deny accessing php files for the /assets directory
            location ~ ^/assets/.*\.php$ {
                deny all;
            }
    
            location ~ \.php$ {
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass 127.0.0.1:9000;
                #fastcgi_pass unix:/var/run/php5-fpm.sock;
                try_files $uri =404;
            }
    
            location ~* /\. {
                deny all;
            }
        }
  5. Change the host file to point the domain to your server.

    • Windows: c:\Windows\System32\Drivers\etc\hosts
    • Linux: /etc/hosts

    Add the following line:

    127.0.0.1   frontend.test
    127.0.0.1   backend.test

To log in to the application, you need to register your email address, user name and password. You can then log in to the application at any time with the same email address and password.

Note: if you want to run the advanced template on a single domain, / is the front end and / admin is the back end, see Using advanced project templates on shared hosts.

Installing with Vagrant

This is the simplest installation method, but it takes a long time (about 20 minutes).

This installation method does not require pre installed software (such as Web server, PHP, MySQL, etc.) - just the next step!

Linux/Unix user manual

  1. install VirtualBox

  2. install Vagrant

  3. Create GitHub personal API token

  4. Preparation items:

    git clone https://github.com/yiisoft/yii2-app-advanced.git
    cd yii2-app-advanced/vagrant/config
    cp vagrant-local.example.yml vagrant-local.yml
  5. Place your GitHub personal API token in vagrant local yml

  6. Change directory to project root:

    cd yii2-app-advanced
  7. Execute the following command:

    vagrant plugin install vagrant-hostmanager
    vagrant up

After waiting, you can access the following URL in the browser

Windows user manual

  1. install VirtualBox

  2. install Vagrant

  3. Reset computer

  4. Create GitHub personal API token

  5. Preparation items:

    • download yii2-app-advanced
    • decompression
    • Enter the yii2 app advanced master / vagrant / config folder
    • Rename vagrant local example. YML is vagrant local yml
  6. Place your GitHub personal API token in vagrant local yml

  7. Add the following code to hosts file:

    192.168.83.137 y2aa-frontend.test
    192.168.83.137 y2aa-backend.test
  8. Open the terminal (cmd.exe), switch the path to the project root directory, and execute the following command:

    vagrant plugin install vagrant-hostmanager
    vagrant up

    (bash) here See how to change the directory at the command prompt)

After waiting, you can access the following URL in the browser

This article was first published in LearnKu.com On the website.