创建安装路径/root/data/docker_data/typecho
1 2 3
| mkdir -p /root/data/docker_data/typecho
cd /root/data/docker_data/typecho
|
安装nano,unzip
1 2
| yum install nano -y yum install -y zip unzip
|
创建数据库mysql
1 2 3
| cd /root/data/docker_data/typecho
nano mysql.env
|
复制粘贴数据库环境信息
1 2 3 4
| MYSQL_ROOT_PASSWORD=root_pass MYSQL_DATABASE=typecho MYSQL_USER=username MYSQL_PASSWORD=password
|
创建php文件夹和Dockerfile
1 2 3 4 5 6 7
| cd /root/data/docker_data/typecho
mkdir php
cd php
nano Dockerfile
|
复制粘贴下面代码到Dockerfile
1 2 3 4 5
| FROM php:7.3.29-fpm RUN apt-get update \ && docker-php-ext-install pdo_mysql \ && echo "output_buffering = 4096" > /usr/local/etc/php/conf.d/php.ini \ && echo "date.timezone = PRC" >> /usr/local/etc/php/conf.d/php.ini
|
创建nginx文件夹和反代配置default.conf
1 2 3 4 5 6 7
| cd /root/data/docker_data/typecho
mkdir nginx
cd nginx
nano default.conf
|
复制粘贴如下反代配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| server { listen 80 default_server; root /var/www/html; index index.php;
access_log /var/log/nginx/typecho_access.log main; if (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; } location / { index index.html index.htm index.php;
if (!-e $request_filename) { rewrite . /index.php last; } }
location ~ \.php(.*)$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
|
下载typecho源代码(暂时最新版本1.2.0)
1 2 3 4 5 6 7 8 9
| mkdir typecho cd /root/data/docker_data/typecho/typecho
wget https://github.com/typecho/typecho/releases/download/v1.2.0/typecho.zip
apt install zip -y
unzip typecho.zip
|
对uploads及其下文件授权,或者对usr及其下文件授权
1 2 3
| chmod -R 777 uploads
chmod -R 777 usr
|
创建docker-compose.yml文件
1 2 3
| cd /root/data/docker_data/typecho
nano docker-compose.yml
|
复制粘贴如下代码到docker-compose.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| version: "3"
services: nginx: image: nginx ports: - "8223:80" restart: always environment: - TZ=Asia/Shanghai volumes: - ./typecho:/var/www/html - ./nginx:/etc/nginx/conf.d - ./logs:/var/log/nginx depends_on: - php networks: - web
php: build: php restart: always expose: - "9000" volumes: - ./typecho:/var/www/html environment: - TZ=Asia/Shanghai depends_on: - mysql networks: - web
mysql: image: mysql:5.7 restart: always environment: - TZ=Asia/Shanghai expose: - "3306" volumes: - ./mysql/data:/var/lib/mysql - ./mysql/logs:/var/log/mysql - ./mysql/conf:/etc/mysql/conf.d env_file: - mysql.env networks: - web
networks: web:
|
ctrl+o保存,ctrl+x退出,按y保存,enter确认
查看端口是否被占用
如果出现:
1
| -bash: lsof: command not found
|
运行:
如果端口没有被占用,可以启动docker-compose
访问typecho后台: 0.0.0.0:8223/admin
数据库地址:mysql
数据库用户名:username
数据库密码:password
数据库名:typecho
在/root/data/docker_data/typecho/typecho
创建 touch config.inc.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| <?php // site root path define('__TYPECHO_ROOT_DIR__', dirname(__FILE__));
// plugin directory (relative path) define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins');
// theme directory (relative path) define('__TYPECHO_THEME_DIR__', '/usr/themes');
// admin directory (relative path) define('__TYPECHO_ADMIN_DIR__', '/admin/');
// register autoload require_once __TYPECHO_ROOT_DIR__ . '/var/Typecho/Common.php';
// init \Typecho\Common::init();
// config db $db = new \Typecho\Db('Pdo_Mysql', 'typecho_'); $db->addServer(array ( 'host' => 'mysql', 'port' => 3306, 'user' => 'username', 'password' => 'password', 'charset' => 'utf8mb4', 'database' => 'typecho', 'engine' => 'InnoDB', ), \Typecho\Db::READ | \Typecho\Db::WRITE); \Typecho\Db::set($db);
|
文章内容和代码来源于网络,如有侵权请联系站长立即删除。