Grav CMS Deployment and Usage Guide
This guide provides comprehensive instructions for deploying and using Grav, a modern, flat-file CMS.
1. Prerequisites
Before installing Grav, ensure you have the following software and tools:
- PHP: Version 7.3.6 or higher.
- Required PHP Modules: Refer to the official Grav documentation for a complete list, which typically includes
gd,curl,zip,mbstring,xml,opcache.
- Required PHP Modules: Refer to the official Grav documentation for a complete list, which typically includes
- Web Server:
- Apache: Ensure
mod_rewriteis enabled. Refer to Apache requirements. - Nginx: Configure
try_filesfor Grav's routing. - IIS: Refer to IIS requirements.
- Apache: Ensure
- Composer (Optional, for
create-projector specific dependency management): Download Composer. - Git (Optional, for cloning from GitHub): Download Git.
2. Installation
Grav offers several methods for installation. Choose the one that best suits your needs.
Option 1: Downloading a Grav Package (Recommended for beginners)
This is the simplest way to get started as it provides a ready-to-use Grav instance.
- Navigate to the official Grav downloads page: https://getgrav.org/downloads.
- Download the desired Grav package (e.g., "Grav Core + Admin Plugin" for a full-featured setup).
- Extract the downloaded ZIP archive to your web server's document root (e.g.,
~/webroot/grav).- On Linux/macOS:
unzip grav-admin-vX.Y.Z.zip -d ~/webroot/grav - On Windows: Use a tool like 7-Zip or the built-in extractor.
- On Linux/macOS:
- Grav is now installed and ready to run.
Option 2: Using Composer
This method is ideal for developers who prefer managing dependencies with Composer.
- Open your terminal or command prompt.
- Navigate to your web server's document root (e.g.,
cd ~/webroot). - Execute the Composer command to create a new Grav project:
Replacecomposer create-project getgrav/grav ~/webroot/grav~/webroot/gravwith your desired installation path.
Option 3: From GitHub (For Developers)
This method provides the latest development version and requires manual dependency installation.
- Open your terminal or command prompt.
- Navigate to your web server's document root (e.g.,
cd ~/webroot). - Clone the Grav repository:
git clone https://github.com/getgrav/grav.git - Navigate into the newly created Grav directory:
cd grav - Install plugin and theme dependencies using the Grav CLI application:
bin/grav install
3. Configuration
Grav uses YAML files for configuration. The main configuration files are located in the user/config/ directory.
- System Configuration:
user/config/system.yaml - Site Configuration:
user/config/site.yaml
Common Configuration Adjustments
- Base URL: Grav automatically detects the base URL, but you can explicitly set it in
user/config/system.yamlunderhome.base_urlif needed. - Caching: Grav utilizes Doctrine Cache (as seen in
system/src/Grav/Framework/Flex/FlexDirectory.php). Caching settings can be adjusted inuser/config/system.yaml. - Languages: Configure supported languages in
user/config/system.yamlunder thelanguagessection. Grav'sLanguageclass (fromsystem/src/Grav/Common/Language/Language.php) handles language detection and management. - Admin Plugin (if installed): Access the admin panel at
http://your-grav-site.com/adminto manage most configurations through a user-friendly interface. Initial setup will prompt for an admin user creation.
Environment Variables
While Grav primarily uses YAML for configuration, you can override certain settings using environment variables. This is particularly useful for production deployments.
For example, to override a system setting like cache.enabled, you might set an environment variable GRAV_CACHE_ENABLED=false. Refer to the Grav documentation for specific environment variable mappings.
4. Build & Run
Grav is a PHP application and does not require a separate "build" step in the traditional sense. Running it involves serving the PHP files through a web server.
Local Development
- Ensure Web Server is Running: Make sure your Apache, Nginx, or IIS server is configured to serve the Grav installation directory.
- Access in Browser: Open your web browser and navigate to the URL where Grav is installed (e.g.,
http://localhost/gravorhttp://grav.test).
Production
For production environments, ensure your web server is properly configured for security and performance.
- Web Server Configuration:
- Apache: Ensure
.htaccessfiles are enabled andAllowOverride Allis set for the Grav directory. - Nginx: Configure the
location /block to handle Grav's routing, typically usingtry_files $uri $uri/ /index.php?$query_string;.
- Apache: Ensure
- Permissions: Set appropriate file permissions for the Grav installation. The
cache,logs,images,assets, anduserdirectories usually require write permissions for the web server user. A common recommendation ischmod -R 755 .for directories andchmod -R 644 .for files, with specific write permissions for the aforementioned directories. - Caching: Ensure caching is enabled and configured for optimal performance in
user/config/system.yaml. - Error Reporting: Disable
display_errorsin yourphp.iniand rely on logging for errors.
5. Deployment
Grav's flat-file nature makes it highly portable. Appropriate deployment platforms include:
- Shared Hosting: Most shared hosting providers support PHP and common web servers (Apache/Nginx), making Grav an excellent fit. Simply upload the Grav files.
- VPS/Dedicated Servers: For more control and performance, deploy Grav on a Virtual Private Server (VPS) or dedicated server. This allows for fine-tuning PHP and web server configurations.
- Containerization (Docker): Create a Docker image for Grav, bundling PHP, Nginx/Apache, and Grav itself. This provides consistent environments across development and production.
- Example Dockerfile (simplified):
FROM php:8.1-apache # Install PHP extensions RUN docker-php-ext-install pdo_mysql gd opcache exif mbstring zip # Enable mod_rewrite RUN a2enmod rewrite # Copy Grav files COPY . /var/www/html/ # Set permissions RUN chown -R www-data:www-data /var/www/html/cache \ /var/www/html/logs \ /var/www/html/images \ /var/www/html/assets \ /var/www/html/user EXPOSE 80
- Example Dockerfile (simplified):
- Managed Hosting (e.g., Platform.sh, Kinsta, Cloudways): These platforms often have optimized PHP environments and can simplify Grav deployments with Git integration.
Deployment Steps (General)
- Prepare Grav Installation: Ensure all plugins and themes are installed (
bin/grav install) and configurations are set. - Transfer Files:
- FTP/SFTP: For shared hosting, upload the entire Grav directory.
- Git Pull: On a VPS or containerized environment, clone the repository or pull updates.
- Deployment Tools: Use tools like rsync, Capistrano, or custom deployment scripts for automated deployments.
- Set Permissions: Adjust file and directory permissions on the server to allow the web server to write to necessary folders (
cache,logs,images,assets,user). - Configure Web Server: Ensure your web server (Apache, Nginx, IIS) is correctly configured to point to Grav's root directory and handle URL rewriting.
- Run GPM Commands (if needed): After deployment, you might need to run
bin/gpm updateto update Grav, plugins, and themes.
6. Troubleshooting
- Blank Page / 500 Error:
- Check PHP Version: Ensure your PHP version meets the 7.3.6+ requirement.
- PHP Error Logs: Check your web server's PHP error logs for detailed messages.
- Permissions: Verify that Grav's
cache/,logs/,images/,assets/, anduser/directories have write permissions for the web server user. - PHP Memory Limit: Increase
memory_limitinphp.iniif you encounter memory-related errors.
- Page Not Found (404) Errors:
mod_rewrite(Apache): Ensuremod_rewriteis enabled in Apache andAllowOverride Allis set for the Grav directory in your Apache configuration.- Nginx
try_files: Verify your Nginx configuration includes the correcttry_filesdirective. - Base URL: Check
user/config/system.yamlforhome.base_urlif you're using a subdirectory installation.
- Admin Panel Not Loading / Issues:
- Clear Cache: Navigate to your Grav root and run
bin/grav clear-cache. - Plugin Conflicts: Temporarily disable recently installed plugins by renaming their folders in
user/plugins/.
- Clear Cache: Navigate to your Grav root and run
- GPM (Grav Package Manager) Issues:
- Connectivity: Ensure your server has outbound internet access to reach
getgrav.org. allow_url_fopen: Check ifallow_url_fopenis enabled inphp.ini.curlextension: Ensure the PHPcurlextension is installed and enabled.
- Connectivity: Ensure your server has outbound internet access to reach
- "Whoops!" Error Page: This is Grav's default error page. Check the
logs/grav.logfile for specific error details. - Slow Performance:
- Caching: Ensure Grav's caching is enabled and working (
user/config/system.yaml). - PHP Opcache: Verify
opcacheis enabled and configured inphp.ini. - Image Processing: Large images without proper optimization can slow down pages. Grav's
Gregwar Image Library(mentioned in the README) can help with dynamic image manipulation, but pre-optimizing images is best.
- Caching: Ensure Grav's caching is enabled and working (
For further assistance, consult the comprehensive Grav documentation at learn.getgrav.org or join the Discord Chat Server.