The pits encountered when installing yii2 advanced on Ubuntu

1. Install Composer

https://www.yiichina.com/doc/guide/2.0/start-installation
Install via Composer

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

solution

sudo vim /etc/php/7.2/cli/php.ini
zlib.output_compression = ON

Successful installation

2. Install yii2 advanced version#

Install yii2

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

Error:

Replacement source:

composer config repo.packagist composer https://packagist.phpcomposer.com

Error:

Add parameter -g global

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

Install yii2 again

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

Change the network connection mode, bridge mode

Install php-mbstring

sudo apt-get install php-mbstring

Report network connection timeout

Open the installation package address in the browser
http://ppa.launchpad.net/ondrej/php/ubuntu/pool/main/p/php7.2/php7.2-mbstring_7.2.9-1+ubuntu16.04.1+deb.sury.org+1_amd64.deb
Can not access,
It is found that another replicated virtual machine is also turned on. It is suspected that the IP address conflicts. After turning off the other virtual machine, you can open this address


Install again, report an error:

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

Execution: sudo apt-get install phpunitsudo apt-get install php7.2-xml

Install again, the installation is successful

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

3. Configure nginx

sudo vim /etc/nginx/sites-available/default
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        /home/jay/yii-application/frontend/web/;
  index       index.php;

  access_log  /home/jay/yii-application/log/frontend-access.log;
  error_log   /home/jay/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        /home/jay/yii-application/backend/web/;
  index       index.php;
    
  access_log  /home/jay/yii-application/log/backend-access.log;
  error_log   /home/jay/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;}}

Restart nginx

sudo service nginx reload
sudo service nginx restart

View error log

journalctl -xe

file does not exist
" /home/jay/yii-application/log/frontend-access.log" failed (2: No such file or directory)

Solution: Create a log folder

nignx 403

Solution: Initialize yii-application

~ /yii-application$ php init

Configure hosts

Open http://backend.test
Error 502

Install php-fpm
sudo apt-get install php7.2-fpm

There is a problem with the php-fpm listening address, which needs to be consistent with the nginx listening address 127.0.0.1:9000
sudo vim /etc/php/7.2/fpm/pool.d/www.conf

Restart php7.2-fpm

sudo service php7.2-fpm restart

Open http://backend.test to jump to the login page

http://frontend.test/ Jump to the welcome page

check php info
Create a test.php file in the /home/jay/yii-application/frontend/web directory

Run http://frontend.test/test.php

4. Configure mysql

Check whether the mysql service is open, localhost:mysql means the service is open

sudo netstat -tap | grep mysql

start service

/etc/init.d/mysql start

stop service

/etc/init.d/mysql stop

Connect mysql

mysql -u root -p

Report an error

Switch to root user

sudo su root

Connect to mysql, the connection is successful

mysql -u root -p

See what databases are there

mysql> show databases

View the database configured by yii2:

Create yii2advanced database

mysql> create database yii2advanced

Login error, php mysql driver is not installed

Install php mysql extension

sudo apt-get install php7.2-mysql

Log in again and report an error:

SQLSTATE[HY000][1698] Access denied for user 'root'@'localhost'

Modify username and password

mysql -u root -p yii2advanced
mysql> select plugin from mysql.user where user ='root';
mysql>  update mysql.user set plugin='mysql_native_password';
mysql> UPDATE mysql.user SET authentication_string=PASSWORD('abc123_') WHERE user='root';
mysql>  flush privileges;
mysql>  exit

Connect to mysql again

 mysql -u root -p yii2advanced

Enter abc123_
Successful landing

#5. Access database
login
Report The table does not exist: {{%user}} not found
Create user table

CREATE TABLE IF NOT EXISTS `user`(`id` INT UNSIGNED AUTO_INCREMENT,`status`varchar(100),`username`varchar(100),`password`varchar(50),`email`varchar(50),`password_hash`varchar(200),`password_reset_token`varchar(200),`auth_key`varchar(50),`created_at`varchar(50),`updated_at`varchar(50),
 PRIMARY KEY(`id`))ENGINE=InnoDB DEFAULT CHARSET=utf8;

Registration error:

Setting unknown property: common\models\User::password_hash

gii generated code
http://127.0.0.1/index.php?r=gii

Error:

Unable to write the file /yii-application/backend/models/Test.php'.

Setting permissions

sudo chmod -R 0777 backend

CURD

Generated successfully

View file directory

Visit http://backend.test/index.php?r=test/index

phpMyAdmin query user table error

$ sudo vim /usr/share/phpmyadmin/libraries/sql.lib.php
turn up

( count($analyzed_sql_results['select_expr'] == 1)
1
Change it to be the same as the following sentence~

( count($analyzed_sql_results['select_expr']) == 1

Registered, successfully logged in

The data is inserted into the database

Author: [** Jackson0714 **] (http://www.cnblogs.com/jackson0714/)
Source: http://www.cnblogs.com/jackson0714/
About the author: focus on project development on the Microsoft platform. If you have any questions or suggestions, please enlighten me!
Copyright statement: The copyright of this article belongs to the author and the blog garden, welcome to reprint, but this statement must be retained without the author’s consent, and a link to the original text should be given in an obvious place on the article page.
Hereby declare: All comments and private messages will be replied as soon as possible. Also welcome everyone in the garden to correct mistakes and make progress together. Or Direct Private Message me

Recommended Posts

The pits encountered when installing yii2 advanced on Ubuntu
Error when installing Python module on Ubuntu
Solve the problem of installing VMwareTools on Ubuntu 18.04
The latest method of installing Mongodb on Ubuntu 16.04
Solve the problem of installing Theano on Ubuntu19
Solutions to the black screen when installing ubuntu (3 types)
The problem of installing GD plug-in OFF on ubuntu dream weaving DEDE
Install the latest Python 3.6 version on Ubuntu
Detailed tutorial on installing python3.7 for ubuntu18
Install the flat theme latabulous on Ubuntu 16.04
Install NeoVim on Ubuntu: the easiest way
Detailed tutorial for installing CUDA9.0 on Ubuntu 16.04
Detailed tutorial for installing phpMyAdmin on Ubuntu 18.04
Small tutorial: List the disks on Ubuntu
How to modify the hostname on Ubuntu 20.04
Install the CPU version of Caffe on Ubuntu
The ultimate guide to install gooderp on ubuntu
Turn off and turn on the firewall in ubuntu
How to run the parsing server on Ubuntu 14.04
How to check the installed JDK on Ubuntu
How to install the latest MySQL on Ubuntu 18.04