Skip to content

Commit 005bd9e

Browse files
committed
Add env options and db-import
1 parent 70da5e5 commit 005bd9e

File tree

2 files changed

+166
-18
lines changed

2 files changed

+166
-18
lines changed

README.md

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,36 @@ After installation, you can access:
7373
- 🗄️ **phpMyAdmin**: http://localhost:8081
7474
- 📧 **Mailpit** (email testing): http://localhost:8025
7575

76+
## 🚀 Quick Reference
77+
78+
Essential commands for common tasks:
79+
80+
```bash
81+
# Start environment
82+
make up
83+
84+
# Import external database
85+
make db-import file=/path/to/database.sql.gz
86+
87+
# Fix URLs after import
88+
make sr old=http://oldsite.com new=http://localhost:8080
89+
90+
# Fix permissions if needed
91+
make fix-permissions
92+
93+
# Check what theme is active
94+
make wp cmd="theme list"
95+
96+
# Install and activate a theme
97+
make wp cmd="theme install themename --activate"
98+
99+
# Check site health
100+
make health
101+
102+
# View logs for troubleshooting
103+
make logs
104+
```
105+
76106
## 📖 Complete Command Reference
77107

78108
### 🏗️ Environment Management
@@ -126,10 +156,13 @@ git push -u origin main
126156
|---------|-------------|---------|
127157
| `make backup` | Create database backup | `make backup` |
128158
| `make restore file=<backup>` | Restore from backup | `make restore file=backup-20240116-143022.sql.gz` |
159+
| `make db-import file=<path>` | Import external database | `make db-import file=/path/to/database.sql.gz` |
129160
| `make list-backups` | List available backups | `make list-backups` |
130161

131162
**Backup files are stored in the `backups/` directory and are automatically compressed and timestamped.**
132163

164+
**Import tip:** Use `make db-import` to import any database file from your system. It will be copied to the backups directory and imported automatically.
165+
133166
### 🛠️ WordPress Management (WP-CLI)
134167

135168
| Command | Description | Example |
@@ -192,10 +225,19 @@ my-awesome-project/
192225
Edit the `.env` file to customize your environment:
193226

194227
```bash
228+
# PHP Version (latest WordPress with specific PHP version)
229+
PHP_VERSION=8.4 # Options: 8.1, 8.2, 8.3, 8.4
230+
231+
# Upload and Memory Limits
232+
PHP_UPLOAD_MAX_FILESIZE=128M # Maximum file upload size
233+
PHP_POST_MAX_SIZE=128M # Maximum POST request size
234+
PHP_MEMORY_LIMIT=512M # PHP memory limit
235+
PMA_UPLOAD_LIMIT=128M # phpMyAdmin upload limit
236+
195237
# Ports (change if needed)
196238
WP_PORT=8080 # WordPress port
197-
PMA_PORT=8081 # phpMyAdmin port
198-
MAILPIT_HTTP_PORT=8025 # Mailpit web interface
239+
PMA_PORT=8081 # phpMyAdmin port
240+
MAILPIT_HTTP_PORT=8025 # Mailpit web interface
199241

200242
# WordPress URL
201243
WP_URL=http://localhost:8080
@@ -206,6 +248,11 @@ DB_USER=wordpress
206248
DB_PASSWORD=wordpress_secure_[random]
207249
```
208250

251+
After changing any `.env` values, restart the environment:
252+
```bash
253+
make restart
254+
```
255+
209256
### PHP Configuration
210257

211258
PHP settings are configured for development in `.docker/php/php.ini`:
@@ -265,21 +312,24 @@ make logs
265312
make restart
266313
```
267314

268-
### Health Check
315+
**After importing a database:**
316+
```bash
317+
# Fix URLs to match your local environment
318+
make sr old=http://youroldsite.com new=http://localhost:8080
319+
320+
# If you get a blank page, check theme files exist
321+
make wp cmd="theme list"
322+
323+
# Activate a different theme if needed
324+
make wp cmd="theme activate twentytwentyfour"
325+
```
269326

270-
Run the health check script to diagnose issues:
327+
**Health Check:**
271328
```bash
329+
# Run comprehensive health check
272330
./health-check.sh
273331
```
274332

275-
### Development Setup
276-
277-
1. Fork the repository
278-
2. Create a feature branch: `git checkout -b feature/amazing-feature`
279-
3. Commit your changes: `git commit -m 'Add amazing feature'`
280-
4. Push to the branch: `git push origin feature/amazing-feature`
281-
5. Open a Pull Request
282-
283333
## 📋 Requirements
284334

285335
- **Docker**: 20.10 or higher
@@ -289,6 +339,16 @@ Run the health check script to diagnose issues:
289339
- **Memory**: At least 2GB RAM available for Docker
290340
- **Disk Space**: At least 2GB free space
291341

342+
## 🤝 Contributing
343+
344+
Contributions are welcome! To contribute:
345+
346+
1. Fork the repository
347+
2. Create a feature branch: `git checkout -b feature/amazing-feature`
348+
3. Commit your changes: `git commit -m 'Add amazing feature'`
349+
4. Push to the branch: `git push origin feature/amazing-feature`
350+
5. Open a Pull Request
351+
292352
## 📄 License
293353

294354
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

setup.sh

100644100755
Lines changed: 94 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ MAILPIT_SMTP_PORT=1025
7676
WP_URL=http://localhost:8080
7777
TZ=Europe/Paris
7878
79+
# PHP Version (supported: 8.1, 8.2, 8.3, 8.4, or latest)
80+
PHP_VERSION=8.4
81+
82+
# Upload and Memory Limits
83+
PHP_UPLOAD_MAX_FILESIZE=128M
84+
PHP_POST_MAX_SIZE=128M
85+
PHP_MEMORY_LIMIT=512M
86+
PMA_UPLOAD_LIMIT=128M
87+
7988
# Database
8089
DB_NAME=wordpress
8190
DB_USER=wordpress
@@ -86,9 +95,6 @@ DB_ROOT_PASSWORD=root_secure_$(openssl rand -hex 8)
8695
HOST_UID=$HOST_UID
8796
HOST_GID=$HOST_GID
8897
89-
# phpMyAdmin
90-
PMA_UPLOAD_LIMIT=128M
91-
9298
# WordPress Config
9399
WP_DEBUG=true
94100
WP_DEBUG_LOG=true
@@ -112,7 +118,7 @@ sed -i.bak -e 's/password=wordpress_secure_[a-f0-9]*/password=your_secure_passwo
112118
cat > docker-compose.yml << 'DOCKER_EOF'
113119
services:
114120
wordpress:
115-
image: wordpress:latest
121+
image: "wordpress:php${PHP_VERSION:-8.4}"
116122
ports:
117123
- "${WP_PORT:-8080}:80"
118124
environment:
@@ -121,6 +127,10 @@ services:
121127
WORDPRESS_DB_PASSWORD: ${DB_PASSWORD:-wordpress}
122128
WORDPRESS_DB_NAME: ${DB_NAME:-wordpress}
123129
WORDPRESS_DEBUG: ${WP_DEBUG:-true}
130+
# PHP Configuration via environment
131+
PHP_UPLOAD_MAX_FILESIZE: ${PHP_UPLOAD_MAX_FILESIZE:-128M}
132+
PHP_POST_MAX_SIZE: ${PHP_POST_MAX_SIZE:-128M}
133+
PHP_MEMORY_LIMIT: ${PHP_MEMORY_LIMIT:-512M}
124134
WORDPRESS_CONFIG_EXTRA: |
125135
define('WP_DEBUG_LOG', ${WP_DEBUG_LOG:-true});
126136
define('WP_DEBUG_DISPLAY', ${WP_DEBUG_DISPLAY:-false});
@@ -209,7 +219,7 @@ services:
209219
210220
# Persistent wpcli container (no more "Creating 2/2" spam)
211221
wpcli:
212-
image: wordpress:cli-php8.2
222+
image: wordpress:cli-php8.4
213223
working_dir: /var/www/html
214224
command: tail -f /dev/null
215225
environment:
@@ -266,7 +276,7 @@ DOCKER_EOF
266276
cat > Makefile << 'MAKEFILE_EOF'
267277
# WordPress Development Environment
268278
.DEFAULT_GOAL := help
269-
.PHONY: help up down install clean shell db-shell logs plugin theme backup restore list-backups fix-permissions wait-db wp sr cron-run prune-backups phpinfo test health restart plugin-repo plugin-clone plugin-list theme-repo theme-clone
279+
.PHONY: help up down install clean shell db-shell logs plugin theme backup restore db-import list-backups fix-permissions wait-db wp sr cron-run prune-backups phpinfo test health restart plugin-repo plugin-clone plugin-list theme-repo theme-clone
270280
271281
# Stop "make[1]: on entre/quitte le répertoire ..." messages
272282
MAKEFLAGS += --no-print-directory
@@ -458,6 +468,26 @@ restore: ## Restore database (usage: make restore file=backup.sql[.gz])
458468
echo "✅ Database restored from $$PATH_IN" \
459469
'
460470
471+
db-import: ## Import external database (usage: make db-import file=/path/to/database.sql[.gz])
472+
@if [ -z "$(file)" ]; then \
473+
echo "❌ Usage: make db-import file=/path/to/database.sql[.gz]"; \
474+
echo "Example: make db-import file=/home/user/mysite.sql.gz"; \
475+
exit 1; \
476+
fi
477+
@if [ ! -f "$(file)" ]; then \
478+
echo "❌ File not found: $(file)"; \
479+
exit 1; \
480+
fi
481+
@if ! $(DOCKER_COMPOSE) ps db | grep -q "Up" 2>/dev/null; then \
482+
echo "❌ Database container is not running. Please start it first:"; \
483+
echo " make up"; \
484+
exit 1; \
485+
fi
486+
@echo "📦 Importing database from $(file)..."
487+
@FILENAME=$$(basename "$(file)"); \
488+
cp "$(file)" "backups/$$FILENAME" && \
489+
echo "✅ Copied to backups/$$FILENAME"; \
490+
$(MAKE) restore file="$$FILENAME"
461491
462492
list-backups: ## List available backups
463493
@echo "📁 Available backups:"
@@ -490,6 +520,8 @@ MAKEFILE_EOF
490520
mkdir -p .docker/php .docker/mysql-init .docker/mysql-logs
491521
cat > .docker/php/php.ini << 'PHP_EOF'
492522
; Development PHP Configuration
523+
; NOTE: PHP upload/memory limits are set via .env file
524+
; The docker-compose.yml passes PHP_UPLOAD_MAX_FILESIZE, PHP_POST_MAX_SIZE, PHP_MEMORY_LIMIT
493525
; Memory and execution
494526
memory_limit = 512M
495527
max_execution_time = 300
@@ -646,6 +678,9 @@ make backup
646678
# Restore from backup
647679
make restore file=backup-20240116-143022.sql.gz
648680
681+
# Import external database (from anywhere on your system)
682+
make db-import file=/path/to/database.sql.gz
683+
649684
# List available backups
650685
make list-backups
651686
```
@@ -676,6 +711,47 @@ make sr old=http://old.local new=http://new.local
676711
- **phpMyAdmin**: http://localhost:8081
677712
- **Mailpit** (dev profile): http://localhost:8025
678713
714+
## Configuration
715+
716+
Edit the `.env` file to customize your environment:
717+
718+
### PHP Version
719+
```bash
720+
# Specify PHP version (8.1, 8.2, 8.3, 8.4)
721+
PHP_VERSION=8.4
722+
```
723+
724+
### Upload and Memory Limits
725+
```bash
726+
# Customize PHP limits
727+
PHP_UPLOAD_MAX_FILESIZE=128M
728+
PHP_POST_MAX_SIZE=128M
729+
PHP_MEMORY_LIMIT=512M
730+
PMA_UPLOAD_LIMIT=128M # phpMyAdmin upload limit
731+
```
732+
733+
### Ports
734+
```bash
735+
# Change if ports are already in use
736+
WP_PORT=8080
737+
PMA_PORT=8081
738+
MAILPIT_HTTP_PORT=8025
739+
```
740+
741+
### Database
742+
```bash
743+
# Auto-generated secure passwords
744+
DB_NAME=wordpress
745+
DB_USER=wordpress
746+
DB_PASSWORD=wordpress_secure_[random]
747+
DB_ROOT_PASSWORD=root_secure_[random]
748+
```
749+
750+
After changing `.env`, restart the environment:
751+
```bash
752+
make restart
753+
```
754+
679755
## File Structure
680756
```
681757
my-project/
@@ -1015,6 +1091,18 @@ echo " make plugin-clone repo=<git-url> # Clone existing plugin"
10151091
echo " make plugin-list # List all plugins"
10161092
echo " ./plugin-status.sh # Detailed plugin status"
10171093
echo ""
1094+
blue "💾 Database Management:"
1095+
echo " make backup # Create database backup"
1096+
echo " make restore file=backup.sql.gz # Restore from backup"
1097+
echo " make db-import file=/path/to/db.sql.gz # Import external database"
1098+
echo " make list-backups # List available backups"
1099+
echo ""
1100+
blue "⚙️ Configuration (edit .env file):"
1101+
echo " PHP_VERSION=8.4 # PHP version (8.1, 8.2, 8.3, 8.4)"
1102+
echo " PHP_UPLOAD_MAX_FILESIZE=128M # Upload size limit"
1103+
echo " PHP_MEMORY_LIMIT=512M # PHP memory limit"
1104+
echo " Then run: make restart"
1105+
echo ""
10181106
blue "🌐 Access URLs:"
10191107
echo " WordPress: ${WP_URL:-http://localhost:8080}"
10201108
echo " phpMyAdmin: http://localhost:${PMA_PORT:-8081}"

0 commit comments

Comments
 (0)