前言
FastAdmin基于ThinkPHP和Bootstrap的快速后台开发框架。最近要开发一个管理系统,决定采用FastAdmin,记录一下部署开发过程。本文主要记录项目初始化,快速搭建过程。
环境准备
根据官方文档要求,需要lnmp环境。打算采用docker启动,方便迁移。具体安装docker和docker-compose的过程,参考以前的文章。
docker和docker-compose一键安装脚本
项目代码
去官网下载最新版本的FastAdmin源文件
下载链接
配置
docker-compose.yml
整体项目启动文件,对应官方要求版本。
version: "3"
services:
web:
image: nginx:latest
ports:
- "80:80"
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- ./app:/www/web
- ./services/nginx/conf:/etc/nginx
- /var/log/lnmp/nginx:/www/web_logs
networks:
- lnet
depends_on:
- php
php:
build:
context: ./services/php/7.4/docker/
restart: always
cap_add:
- SYS_PTRACE
volumes:
- /etc/localtime:/etc/localtime:ro
- ./app:/www/web
- ./services/php/7.4/etc/php.ini:/usr/local/etc/php/conf.d/php.ini
- ./services/php/7.4/etc/php-fpm.conf:/usr/local/etc/php-fpm.conf
- ./services/php/7.4/etc/www.conf:/usr/local/etc/php-fpm.d/www.conf
- /var/log/lnmp/php/:/logs/
networks:
- lnet
mariadb:
image: mariadb:10.3
ports:
- "3306:3306"
volumes:
- /etc/localtime:/etc/localtime:ro
- ./services/mariadb/10.3/my.cnf:/etc/mysql/my.cnf
- ./data/mariadb/:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: mariadb@123
TIME_ZONE: Asia/Shanghai
restart: always
networks:
- lnet
networks:
lnet:
driver: bridge
default.conf
nginx的配置文件
server {
listen 80;
server_name abm.mytest.com;
root /www/web/public;
index index.php index.html index.htm;
access_log /www/web_logs/access.log wwwlogs;
error_log /www/web_logs/error.log notice;
server_tokens off;
client_max_body_size 50m;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location / {
if (!-e $request_filename) {
rewrite ^(.+?\.php)(/.+)$ /$1?s=$2 last; # 管理后台
rewrite ^/(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fcgi.conf;
fastcgi_buffers 8 4K;
fastcgi_buffer_size 4K;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 12h;
}
}
上传解压
将源码上传到项目app目录下,并解压。创建用户并授权。
useradd -u 1010 www-data -s /usr/sbin/nologin
chown -R www-data app
创建数据库
先启动项目,然后登录数据库,建库并授权。
CREATE DATABASE `fastadmin` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
create user 'fauser'@'%' IDENTIFIED BY 'fauserxxx';
grant all privileges on fastadmin.* to 'fauser'@'%';
flush privileges;
安装
项目启动后,通过浏览器访问nginx配置的域名+/install.php安装即可。
FAQ
ajax/lang 404 错误
还是伪静态的问题, 修改nginx关于伪静态的配置
location / {
if (!-e $request_filename) {
rewrite ^(.+?\.php)(/.+)$ /$1?s=$2 last; # 加上这一句配置试试
rewrite ^/(.*)$ /MnFRkafVCN.php?s=/$1 last;
break;
}
}
评论 (0)