Última actividad 1753284966

Bash скрипт, който генерира силни пароли, създава нужните директории и файлове, пита за имена на контейнерите (WordPress и DB), пита за външен порт (по подразбиране 8383), генерира .env, docker-compose.yml, и config/php.ini.

Revisión cb686787f89b4084e0c5c1824de8daba4c8cea88

install_wp.sh Sin formato
1#!/bin/bash
2
3# ====== ВХОДНИ ДАННИ ОТ ПОТРЕБИТЕЛЯ ======
4read -p "👉 Въведи име за контейнера на WordPress [wordpress_app]: " WP_CONTAINER
5WP_CONTAINER=${WP_CONTAINER:-wordpress_app}
6
7read -p "👉 Въведи име за контейнера на базата данни [wordpress_db]: " DB_CONTAINER
8DB_CONTAINER=${DB_CONTAINER:-wordpress_db}
9
10read -p "👉 Въведи външен порт за достъп до WordPress (напр. 8383): " HOST_PORT
11HOST_PORT=${HOST_PORT:-8383}
12
13# ====== ГЕНЕРИРАНЕ НА ПАРОЛИ ======
14MYSQL_ROOT_PASSWORD=$(openssl rand -base64 16)
15MYSQL_DATABASE="wordpress"
16MYSQL_USER="wpuser"
17MYSQL_PASSWORD=$(openssl rand -base64 16)
18
19# ====== СЪЗДАВАНЕ НА ДИРЕКТОРИИ ======
20mkdir -p config wp-content
21
22# ====== .env ФАЙЛ ======
23cat > .env <<EOF
24MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
25MYSQL_DATABASE=${MYSQL_DATABASE}
26MYSQL_USER=${MYSQL_USER}
27MYSQL_PASSWORD=${MYSQL_PASSWORD}
28WORDPRESS_DB_HOST=db:3306
29EOF
30
31# ====== config/php.ini ======
32cat > config/php.ini <<EOF
33upload_max_filesize = 64M
34post_max_size = 64M
35memory_limit = 256M
36EOF
37
38# ====== docker-compose.yml ======
39cat > docker-compose.yml <<EOF
40version: '3.8'
41
42services:
43 db:
44 image: mysql:8.0
45 container_name: ${DB_CONTAINER}
46 restart: always
47 volumes:
48 - db_data:/var/lib/mysql
49 environment:
50 MYSQL_ROOT_PASSWORD: \${MYSQL_ROOT_PASSWORD:-rootpass}
51 MYSQL_DATABASE: \${MYSQL_DATABASE:-wordpress}
52 MYSQL_USER: \${MYSQL_USER:-wpuser}
53 MYSQL_PASSWORD: \${MYSQL_PASSWORD:-wppass}
54 healthcheck:
55 test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
56 interval: 10s
57 timeout: 5s
58 retries: 5
59
60 wordpress:
61 image: wordpress:latest
62 container_name: ${WP_CONTAINER}
63 depends_on:
64 db:
65 condition: service_healthy
66 ports:
67 - "${HOST_PORT}:80"
68 restart: always
69 volumes:
70 - wordpress:/var/www/html
71 - ./wp-content:/var/www/html/wp-content
72 - ./config/php.ini:/usr/local/etc/php/conf.d/custom.ini
73 environment:
74 WORDPRESS_DB_HOST: db:3306
75 WORDPRESS_DB_NAME: \${MYSQL_DATABASE:-wordpress}
76 WORDPRESS_DB_USER: \${MYSQL_USER:-wpuser}
77 WORDPRESS_DB_PASSWORD: \${MYSQL_PASSWORD:-wppass}
78
79volumes:
80 db_data:
81 driver: local
82 wordpress:
83 driver: local
84EOF
85
86# ====== ИЗВОД ======
87echo
88echo "✅ Проектът е инициализиран успешно!"
89echo "📂 Създадени: docker-compose.yml, .env, config/php.ini, wp-content/"
90echo "🌐 Достъп до WordPress: http://localhost:${HOST_PORT}"
91echo
92echo "🔐 Данни за достъп до базата (също записани в .env):"
93echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}"
94echo "MYSQL_USER=${MYSQL_USER}"
95echo "MYSQL_PASSWORD=${MYSQL_PASSWORD}"
96echo
97echo "🚀 Стартирай с: docker compose up -d"