LNMP建站

更新系统

apt update -y && apt upgrade -y && apt install -y curl wget sudo socat

安装docker

curl -fsSL https://get.docker.com | sh

curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose

创建目录

cd /home

mkdir web

cd web

mkdir html

mkdir mysql

mkdir certs

touch nginx.conf

nano docker-compose.yml

配置docker-compose

version: '3.8'

services:
nginx:
image: nginx
container_name: nginx
restart: always
ports:
- 80:80
- 443:443
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./certs:/etc/nginx/certs
- ./html:/var/www/html
depends_on:
- php

php:
image: php:fpm
container_name: php
restart: always
volumes:
- ./html:/var/www/html
depends_on:
- mysql

mysql:
image: mysql
container_name: mysql
restart: always
ports:
- 3306:3306
volumes:
- ./mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=webroot
- MYSQL_DATABASE=web
- MYSQL_USER=kejixiaoxin
- MYSQL_PASSWORD=Kejixiaoxinpasswd

申请证书

curl https://get.acme.sh | sh

~/.acme.sh/acme.sh --register-account -m xxxx@gmail.com

~/.acme.sh/acme.sh --issue -d xxx.xxx.xxx --standalone

下载证书

~/.acme.sh/acme.sh --installcert -d xxx.xxx.xxx --key-file /home/web/certs/key.pem --fullchain-file /home/web/certs/cert.pem

NGINX配置

events {
worker_connections 1024;
}

http {

include /etc/nginx/mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

client_max_body_size 1000m;
#上传限制参数1G以内文件可上传

# HTTP server
server {
listen 80;
server_name xxx.xxx.xxx;

# Redirect all HTTP requests to HTTPS
return 301 https://$host$request_uri;
}

# HTTPS server
server {
listen 443 ssl http2;
server_name xxx.xxx.xxx;

# http2 on;

ssl_certificate /etc/nginx/certs/cert.pem;
ssl_certificate_key /etc/nginx/certs/key.pem;

root /var/www/html;
index index.php;

# rewrite ^/vip.php(.*)$ /vip.php?s=$1 last;

try_files $uri $uri/ =404;

# PHP-FPM configuration
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

}

下载源码

maccms10

cd /home/web && wget https://github.com/magicblack/maccms_down/raw/master/maccms10.zip && sudo apt-get install -y unzip && unzip maccms10.zip -d html && rm maccms10.zip && mv /home/web/html/maccms10-master/* /home/web/html/

wordpress

cd /home/web && wget https://cn.wordpress.org/wordpress-6.2-zh_CN.zip && sudo apt-get install -y unzip && unzip wordpress-6.2-zh_CN.zip -d html && rm wordpress-6.2-zh_CN.zip && mv /home/web/html/wordpress/* /home/web/html/

运行

cd /home/web && docker-compose up -d

赋予权限

docker exec -it nginx chmod -R 777 /var/www/html

docker exec -it php chmod -R 777 /var/www/html

安装PHP扩展

docker exec php -it apt update && docker exec php apt install -y libmariadb-dev-compat libmariadb-dev libzip-dev

docker exec php docker-php-ext-install mysqli pdo_mysql zip

重启php

docker restart php

WordPress 安装主题、插件、更新时需要FTP的解决办法

修改wp-config.php文件
对于没有服务器目录操作权限的用户来说,修改wp-config.php文件会比较简单快捷,只需要在wp-config.php文件添加以下代码:

define('FS_METHOD','direct');
可以加到WP_DEBUG那一行后面。

评论

此博客中的热门博文

始终免费的vps!甲骨文云(oracle)抢注册高性能ARM实例!一键脚本部署!

LINUX | 谷歌云开启SSH及设置root密码