A PHP web application with Apache ready to deploy on Convox.
This example demonstrates how to deploy a dynamic PHP application on Convox. It showcases server-side rendering, API endpoints, environment variable usage, and includes common PHP extensions for database connectivity.
Deploy to Convox Cloud for a fully-managed platform experience, or to your own Convox Rack for complete control over your infrastructure. Either way, you'll get automatic SSL, load balancing, and zero-downtime deployments out of the box.
-
Create a Cloud Machine at console.convox.com
-
Create the app:
convox cloud apps create php -i your-machine-name- Deploy the app:
convox cloud deploy -a php -i your-machine-name- View your app:
convox cloud services -a php -i your-machine-nameVisit your URL to see the PHP application!
- Create the app:
convox apps create php- Deploy the app:
convox deploy -a php- View your app:
convox services -a phpVisit your URL to see the PHP application!
- PHP 8.3 with Apache web server
- Dynamic Routing - Simple PHP router for multiple pages
- API Endpoints - JSON API examples at
/api/statusand/api/time - Environment Variables - Access Convox environment variables
- Database Ready - PDO and MySQLi extensions pre-installed
- Modern UI - Responsive design with Convox branding
.
├── Dockerfile # PHP 8.3 with Apache
├── convox.yml # Convox configuration
└── public/ # Web root
├── index.php # Main router
├── style.css # Styles
├── .htaccess # Apache routing rules
└── pages/ # Page templates
├── home.php
├── info.php
├── api_status.php
└── api_time.php
/- Homepage with server information/info- PHP configuration details (phpinfo)/api/status- JSON API endpoint with system status/api/time- JSON API endpoint with current time- Any other route - 404 page
This example includes PDO and MySQLi extensions. To add a database:
resources:
database:
type: mysql
options:
storage: 10
services:
web:
resources:
- database// Database URL is automatically provided
$db_url = getenv('DATABASE_URL');
// Parse and connect using PDO or MySQLiThe application can access Convox-provided environment variables:
APP- Application nameRACK- Rack nameSERVICE- Service nameBUILD- Build IDRELEASE- Release ID
convox cloud scale web --count 2 --cpu 500 --memory 1024 -a php -i your-machine-nameconvox scale web --count 2 --cpu 500 --memory 1024 -a phpCloud:
convox cloud logs -a php -i your-machine-nameRack:
convox logs -a phpCloud:
convox cloud run web "php -m" -a php -i your-machine-nameRack:
convox run web "php -m" -a phpCloud:
convox cloud run web bash -a php -i your-machine-nameRack:
convox run web bash -a phpTo add Composer dependencies, update the Dockerfile:
FROM php:8.3-apache
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Copy composer files
COPY composer.json composer.lock ./
RUN composer install --no-dev --optimize-autoloader
# Rest of Dockerfile...Add to Dockerfile:
RUN docker-php-ext-install opcache gd zip
RUN pecl install redis && docker-php-ext-enable redisThis example uses vanilla PHP. To use a framework like Laravel or Symfony:
- Copy your framework files to the project
- Update the document root in Dockerfile if needed
- Ensure
.envfiles are properly configured - Add any required PHP extensions
- Enable OPcache for production
- Use PHP-FPM for better performance under load
- Configure Apache MPM settings for your workload
- Use Redis/Memcached for session storage in scaled deployments