Ukylin/ubuntu20.04 install ThinkPHP6

1. Install the applications required for the Lamp environment (apache, mysql, php)

$ sudo apt install apache2
$ sudo apt install mysql-server  #
$ sudo apt install php

Two, install composer

$ sudo apt install composer     #安装
$ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer    #添加下载源

Three, install ThinkPHP6

$ cd /home/hollowman/www   #切换到需要下载配置ThinkPHP6的php环境目录
$ composer create-project topthink/think hollowman21   #下载ThinkPHP6到自定义的应用根目录hollowman21中

Update ThinkPHP6 core

$ cd /home/hollowman/www/hollowman21   #切换到应用更目录hollowman21
$ composer update topthink/framework   #执行更新操作

注意: The directory where the installation and update commands are located is different, the update must be performed under the root directory of your application

Directory structure after installation

hollowman21  WEB部署目录(或者子目录)
├─app           应用目录
│  ├─controller      控制器目录
│  ├─model           模型目录
│  ├─ ...            更多类库目录
│  │
│  ├─common.php         公共函数文件
│  └─event.php          事件定义文件
│
├─config                配置目录
│  ├─app.php            应用配置
│  ├─cache.php          缓存配置
│  ├─console.php        控制台配置
│  ├─cookie.php         Cookie配置
│  ├─database.php       数据库配置
│  ├─filesystem.php     文件磁盘配置
│  ├─lang.php           多语言配置
│  ├─log.php            日志配置
│  ├─middleware.php     中间件配置
│  ├─route.php          URL和路由配置
│  ├─session.php        Session配置
│  ├─trace.php          Trace配置
│  └─view.php           视图配置
│
├─view            视图目录
├─route                 路由定义目录
│  ├─route.php          路由定义文件
│  └─ ...
│
├─public                WEB目录(对外访问目录)
│  ├─index.php          入口文件
│  ├─router.php         快速测试文件
│  └─.htaccess          用于apache的重写
│
├─extend                扩展类库目录
├─runtime               应用的运行时目录(可写,可定制)
├─vendor                Composer类库目录
├─.example.env          环境变量示例文件
├─composer.json         composer 定义文件
├─LICENSE.txt           授权说明文件
├─README.md             README 文件
├─think                 命令行入口文件

Fourth, configure apache

1. Modify the global configuration file /etc/apache2/apache2.conf

$ sudo vim /etc/apache2/apache2.conf 
<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>
#在上面代码的下方添加下面的代码
<Directory /home/hollowman/www/hollowman21>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

2. Modify the site configuration file /etc/apache2/sites-available/000-default.conf (the file name may be different)

$ sudo vim /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
...
</VirtualHost>
#在上面代码的下方添加下面代码
<VirtualHost *:80>
	serverAdmin [email protected]
	ServerName hollowman.com
	DocumentRoot /home/hollowman/www/hollowman21/public

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Fourth, modify the hosts file

Because the domain name is used above, if you want to test on your own computer, you need to correspond the ip address to the domain name

sudo vim /etc/hosts
#追加如下代码
127.0.0.1   hollowman.com

You can also execute this command to achieve the same effect:echo '127.0.0.1 hollowman.com' >> /etc/hosts

5. Open the browser and enter hollowman.com to find that the familiar tp6 initial interface comes out.

Insert picture description here