Environment Types
Environment Overview
| Environment | Purpose | Trigger |
|---|---|---|
| Integration | Development, feature testing | Branch push |
| Staging | Pre-production validation | Merge to staging branch |
| Production | Live store | Merge to main branch |
Integration Environments
# Create integration environment
magento-cloud environment:create feature/checkout
# List environments
magento-cloud environment:list
# Get environment info
magento-cloud environment:info feature/checkout
# View environment URL
magento-cloud environment:url feature/checkout
Staging Environment
# Activate staging
magento-cloud environment:activate staging
# Sync data to staging
magento-cloud snapshot:create --environment staging
# Restore staging
magento-cloud snapshot:restore --environment staging
Production Environment
# Production is activated from main branch
git checkout main
git merge feature/checkout
git push origin main
# Check production status
magento-cloud environments:info production
Key Takeaway
Each environment type serves different purposes. Integration for development, staging for validation, production for live traffic.
Environment Configuration
Environment Variables
# Set environment-specific variables
magento-cloud variable:create \
--name env:ENABLE_DEBUG \
--value 1 \
--level environment \
--environment feature/checkout
# Set project-level variables
magento-cloud variable:create \
--name env:MAGENTO_CLOUD_PROJECT_ID \
--value $PROJECT_ID \
--level project
# List variables
magento-cloud variable:list --environment staging
Environment-Specific Services
# .magento/services.yaml (project level)
mysql:
type: mysql:10.6
disk: 2048
# Override for staging
# staging branch .magento/services.yaml
mysql:
type: mysql:10.6
disk: 1024 # Smaller disk for staging
Environment Routes
# .magento/routes.yaml
'http://{default}/':
type: upstream
upstream: magento:php
# Integration environment URL
# https://feature-checkout-projectid.us-3.magentosite.cloud/
# Staging URL
# https://staging-projectid.us-3.magentosite.cloud/
Configuration Management
# Set config for specific environment
magento-cloud variable:create \
--name env:STORE_NAME \
--value "My Store" \
--environment staging
# Use in app/etc/env.php
$storeName = getenv('STORE_NAME');
Key Takeaway
Environment variables configure settings per environment. Override services and routes for different environments. Use project-level variables for shared settings.
Environment Deployment
Branch Deployment
# Create feature branch
git checkout -b feature/new-checkout
# Make changes
git add .
git commit -m "feat(checkout): add new checkout flow"
git push origin feature/new-checkout
# Cloud creates integration environment automatically
# URL: https://feature-new-checkout-projectid.us-3.magentosite.cloud/
Promote to Staging
# Merge to staging branch
git checkout staging
git merge feature/new-checkout
git push origin staging
# Cloud deploys to staging environment
# URL: https://staging-projectid.us-3.magentosite.cloud/
Deploy to Production
# Merge to main branch
git checkout main
git merge staging
git push origin main
# Cloud deploys to production
# URL: https://www.example.com/
Deployment Commands
# Check deployment status
magento-cloud environments:info
# View deployment log
magento-cloud environment:log
# View build log
magento-cloud builds:list
# SSH and check status
magento-cloud ssh
bin/magento cache:status
Key Takeaway
Git push triggers deployment. Feature branches create integration environments. Merge to staging for validation, then to main for production.
Environment Troubleshooting
Common Issues
# Check environment status
magento-cloud environments:info
# View error logs
magento-cloud environment:log
# SSH and check logs
magento-cloud ssh
bin/magento cache:status
var/log/system.log
tail -f var/log/exception.log
Build Failures
# Check build log
magento-cloud builds:list
magento-cloud builds:log <build-id>
# Common issues
# 1. Composer dependencies
composer install --prefer-dist
# 2. DI compilation
bin/magento setup:di:compile
# 3. Static content deploy
bin/magento setup:static-content:deploy -f
Deploy Failures
# Check deploy log
magento-cloud environment:log
# Common issues
# 1. Database connection
bin/magento setup:install --dry-run
# 2. Setup upgrade
bin/magento setup:upgrade --dry-run
# 3. Cache issues
bin/magento cache:flush
Performance Issues
# Check Redis
redis-cli info stats
# Check Elasticsearch
curl -s localhost:9200/_cluster/health
# Check MySQL
mysqladmin status
# Check PHP-FPM
ps aux | grep php-fpm
Debug Mode
# Enable developer mode
bin/magento deploy:mode:set developer
# Enable verbose logging
bin/magento config:set dev/log/verbosity 4
# Clear cache
bin/magento cache:flush
Key Takeaway
Check environment status, view logs, and verify services. Common issues: build failures, deploy failures, performance problems. Use SSH for direct debugging.
Quiz
1. What triggers integration environment creation?
2. How do you promote to staging?
3. What is the staging URL format?
4. How to check deployment logs?
5. What is the production deployment trigger?
Flashcards
Question
Integration environment trigger?
Click to reveal answer
Answer
Push to feature branch
Question
Staging promotion method?
Click to reveal answer
Answer
Merge to staging branch
Question
Production deployment trigger?
Click to reveal answer
Answer
Merge to main branch
Question
How to check environment info?
Click to reveal answer
Answer
magento-cloud environment:info
Question
How to view deployment logs?
Click to reveal answer
Answer
magento-cloud environment:log
Question
Staging URL format?
Click to reveal answer
Answer
https://staging-projectid.region.magentosite.cloud/
Question
How to set environment variables?
Click to reveal answer
Answer
magento-cloud variable:create --name NAME --value VALUE --environment ENV
Question
How to SSH into environment?
Click to reveal answer
Answer
magento-cloud ssh
Revision Notes
Key Takeaways
- 1. Integration environments created from feature branches
- 2. Merge to staging for pre-production validation
- 3. Merge to main for production deployment
- 4. Use magento-cloud CLI for environment management
- 5. Environment variables configure per-environment settings
Interview Tips
- • Explain environment hierarchy and promotion
- • Describe environment variable configuration
- • Discuss deployment triggers and process
- • Explain troubleshooting approaches
Cheat Sheet
Cloud Environments
Hierarchy:
Integration -> Staging -> Production
Triggers:
Feature branch -> Integration
Merge to staging -> Staging
Merge to main -> Production
CLI:
magento-cloud environment:list
magento-cloud environment:info
magento-cloud environment:log
magento-cloud variable:create
URLs:
Integration: https://branch-projectid.region.magentosite.cloud/
Staging: https://staging-projectid.region.magentosite.cloud/