docker下LNMP環境搭建

知风阁發表於2024-05-13

更新系統

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

https://github.com/kejilion/docker/blob/main/LNMP-docker-compose.yml

NGINX配置

https://github.com/kejilion/nginx/blob/main/nginx5.conf

測試專案

wordpress

cd /home/web && wget https://cn.wordpress.org/wordpress-6.2.2-zh_CN.zip && sudo apt-get install -y unzip && unzip wordpress-6.2.2-zh_CN.zip -d html && rm wordpress-6.2.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 apt update && docker exec php apt install -y libmariadb-dev-compat libmariadb-dev libzip-dev libmagickwand-dev imagemagick

docker exec php docker-php-ext-install mysqli pdo_mysql zip exif gd intl bcmath opcache

docker exec php pecl install imagick && docker exec php sh -c 'echo "extension=imagick.so" > /usr/local/etc/php/conf.d/imagick.ini'

docker exec -it php sh -c 'echo "upload_max_filesize=50M \n post_max_size=50M" > /usr/local/etc/php/conf.d/uploads.ini'

重啟php

docker restart php

可以去訪問你的域名了,完成wp安裝嚮導後再輸入下面的命令!

跳過FTP更新主題外掛的限制

echo "define('FS_METHOD', 'direct');" >> /home/web/html/wp-config.php

相關文章