|
|
@@ -39,7 +39,7 @@ chmod +x build.sh
|
|
|
### 4. Access Application
|
|
|
- **Frontend**: http://localhost
|
|
|
- **API**: http://localhost/api
|
|
|
-- **Database**: localhost:3306 (user: inventory_db, pass: mDw(HF]Cub.UM2*7)
|
|
|
+- **Database**: External database (configured in .env)
|
|
|
|
|
|
## 🏗️ Architecture
|
|
|
|
|
|
@@ -48,7 +48,7 @@ The Docker setup creates a single container that includes:
|
|
|
- **Apache Web Server** with PHP 8.1
|
|
|
- **Vue.js Frontend** (built and served)
|
|
|
- **PHP Backend API** with all endpoints
|
|
|
-- **MySQL Database** (separate container)
|
|
|
+- **External Database** (user-provided MySQL/MariaDB)
|
|
|
- **Redis Cache** (optional)
|
|
|
|
|
|
### Container Structure
|
|
|
@@ -60,24 +60,23 @@ inventory-app (main container)
|
|
|
├── Uploads (/var/www/html/uploads)
|
|
|
└── Configuration
|
|
|
|
|
|
-inventory-db (MySQL container)
|
|
|
-└── MySQL 8.0 Database
|
|
|
-
|
|
|
inventory-redis (optional)
|
|
|
└── Redis 7 Cache
|
|
|
+
|
|
|
+External Database (user-provided)
|
|
|
+└── MySQL/MariaDB Database
|
|
|
```
|
|
|
|
|
|
## ⚙️ Configuration
|
|
|
|
|
|
### Environment Variables (.env)
|
|
|
```bash
|
|
|
-# Database Configuration
|
|
|
-DB_HOST=db # Docker service name
|
|
|
+# Database Configuration (External)
|
|
|
+DB_HOST=your-external-db-host # Your database server
|
|
|
DB_PORT=3306
|
|
|
DB_NAME=inventory_db
|
|
|
-DB_USER=inventory_db
|
|
|
-DB_PASS=mDw(HF]Cub.UM2*7
|
|
|
-DB_ROOT_PASSWORD=rootpassword
|
|
|
+DB_USER=your-db-username
|
|
|
+DB_PASS=your-db-password
|
|
|
|
|
|
# Application Port
|
|
|
APP_PORT=80 # Web server port
|
|
|
@@ -108,13 +107,7 @@ UPLOADS_PATH=./uploads
|
|
|
- **Image**: Built from Dockerfile
|
|
|
- **Ports**: 80:80
|
|
|
- **Features**: PHP backend + Vue.js frontend
|
|
|
-
|
|
|
-### db
|
|
|
-- **Purpose**: MySQL database
|
|
|
-- **Image**: mysql:8.0
|
|
|
-- **Ports**: 3306:3306
|
|
|
-- **Volume**: Persistent data storage
|
|
|
-- **Initialization**: Auto-loads database schema
|
|
|
+- **Database**: Connects to external database via environment variables
|
|
|
|
|
|
### redis (optional)
|
|
|
- **Purpose**: Caching layer
|
|
|
@@ -122,6 +115,32 @@ UPLOADS_PATH=./uploads
|
|
|
- **Ports**: 6379:6379
|
|
|
- **Volume**: Persistent data storage
|
|
|
|
|
|
+## 🗄️ External Database Setup
|
|
|
+
|
|
|
+### Database Requirements
|
|
|
+- **MySQL 8.0+** or **MariaDB 10.5+**
|
|
|
+- **Network Access**: Container must be able to reach database host
|
|
|
+- **Schema**: Run `backend/migrate_complete.sql` to create database schema
|
|
|
+- **Permissions**: User needs CREATE, SELECT, INSERT, UPDATE, DELETE privileges
|
|
|
+
|
|
|
+### Database Setup Steps
|
|
|
+```bash
|
|
|
+# 1. Create database
|
|
|
+mysql -u root -p -e "CREATE DATABASE inventory_db;"
|
|
|
+
|
|
|
+# 2. Create user
|
|
|
+mysql -u root -p -e "CREATE USER 'inventory_db'@'%' IDENTIFIED BY 'your_password';"
|
|
|
+
|
|
|
+# 3. Grant permissions
|
|
|
+mysql -u root -p -e "GRANT ALL PRIVILEGES ON inventory_db.* TO 'inventory_db'@'%';"
|
|
|
+
|
|
|
+# 4. Import schema
|
|
|
+mysql -u inventory_db -p inventory_db < backend/migrate_complete.sql
|
|
|
+
|
|
|
+# 5. Flush privileges
|
|
|
+mysql -u root -p -e "FLUSH PRIVILEGES;"
|
|
|
+```
|
|
|
+
|
|
|
## 📁 File Structure
|
|
|
|
|
|
```
|
|
|
@@ -134,7 +153,7 @@ inventory/
|
|
|
│ ├── api/ # PHP API endpoints
|
|
|
│ ├── config/ # Configuration files
|
|
|
│ ├── models/ # PHP models
|
|
|
-│ └── migrate_complete.sql # Database schema
|
|
|
+│ └── migrate_complete.sql # Database schema (for external DB)
|
|
|
├── frontend/
|
|
|
│ ├── src/ # Vue.js source code
|
|
|
│ ├── dist/ # Built frontend (generated)
|
|
|
@@ -182,14 +201,17 @@ docker-compose build inventory-app
|
|
|
|
|
|
### Database Management
|
|
|
```bash
|
|
|
-# Access database shell
|
|
|
-docker-compose exec db mysql -u inventory_db -p
|
|
|
+# Access external database
|
|
|
+mysql -h your-external-db-host -u your-db-username -p inventory_db
|
|
|
|
|
|
-# Backup database
|
|
|
-docker-compose exec db mysqldump -u inventory_db inventory_db > backup.sql
|
|
|
+# Backup external database
|
|
|
+mysqldump -h your-external-db-host -u your-db-username inventory_db > backup.sql
|
|
|
+
|
|
|
+# Restore external database
|
|
|
+mysql -h your-external-db-host -u your-db-username inventory_db < backup.sql
|
|
|
|
|
|
-# Restore database
|
|
|
-docker-compose exec -T db mysql -u inventory_db inventory_db < backup.sql
|
|
|
+# Test connection from container
|
|
|
+docker-compose exec inventory-app php -r "echo 'Testing DB connection...';"
|
|
|
```
|
|
|
|
|
|
### Container Management
|
|
|
@@ -215,14 +237,24 @@ docker-compose up -d
|
|
|
|
|
|
#### 1. Database Connection Failed
|
|
|
```bash
|
|
|
-# Check database status
|
|
|
-docker-compose logs db
|
|
|
-
|
|
|
-# Restart database
|
|
|
-docker-compose restart db
|
|
|
+# Check application logs
|
|
|
+docker-compose logs inventory-app
|
|
|
|
|
|
-# Wait for database to be ready
|
|
|
-docker-compose exec db mysqladmin ping -h localhost
|
|
|
+# Test database connectivity from container
|
|
|
+docker-compose exec inventory-app ping your-external-db-host
|
|
|
+
|
|
|
+# Test database connection manually
|
|
|
+docker-compose exec inventory-app php -r "
|
|
|
+try {
|
|
|
+ \$pdo = new PDO('mysql:host=your-external-db-host;dbname=inventory_db', 'your-db-username', 'your-db-password');
|
|
|
+ echo 'Database connection successful';
|
|
|
+} catch (Exception \$e) {
|
|
|
+ echo 'Database connection failed: ' . \$e->getMessage();
|
|
|
+}
|
|
|
+"
|
|
|
+
|
|
|
+# Verify database schema exists
|
|
|
+mysql -h your-external-db-host -u your-db-username -p inventory_db -e "SHOW TABLES;"
|
|
|
```
|
|
|
|
|
|
#### 2. Frontend Not Loading
|
|
|
@@ -263,8 +295,7 @@ docker-compose exec inventory-app service apache2 restart
|
|
|
|
|
|
The application includes health checks:
|
|
|
- **inventory-app**: Tests `/api/company.php` endpoint
|
|
|
-- **db**: Tests MySQL connectivity
|
|
|
-- **redis**: Tests Redis connectivity
|
|
|
+- **redis**: Tests Redis connectivity (optional)
|
|
|
|
|
|
View health status:
|
|
|
```bash
|