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