This Docker Compose setup provides:
- Apache web server with PHP 8.4
- PostgreSQL 15 database server
- Pre-configured networking between services
- Apache/PHP: http://localhost:8081
- PostgreSQL: localhost:5435
-
Build and start the services:
docker-compose up -d --build
-
Access the web application: Open your browser and go to: http://localhost:8081
-
Connect to PostgreSQL:
- Host: localhost
- Port: 5435
- Database: myapp
- Username: postgres
- Password: password
phpWorkspace/
├── docker-compose.yml # Main Docker Compose configuration
├── Dockerfile # Custom PHP image with PostgreSQL support
├── src/ # PHP application files
│ └── index.php # Sample PHP file with PostgreSQL test
├── init-scripts/ # PostgreSQL initialization scripts
│ └── init.sql # Sample database schema and data
└── apache-config/ # Apache configuration files (optional)
- Database Name: myapp
- Username: postgres
- Password: password
- Internal Network: Services communicate via Docker network
- External Access: Available on port 5435
- Start services:
docker-compose up -d - Stop services:
docker-compose down - View logs:
docker-compose logs - Rebuild:
docker-compose up -d --build - Access database:
docker-compose exec db psql -U postgres -d myapp
The PHP container includes:
- PHP 8.4 with Apache
- PostgreSQL PDO extension
- Apache mod_rewrite enabled
The setup includes a sample users table with test data. You can modify the init-scripts/init.sql file to customize the initial database structure.