How to Migrate Apache Websites to Caddy
ServBay provides Caddy, Nginx, and Apache as web server options, allowing users to choose the one that best suits their project requirements. For most PHP frameworks and CMS platforms, ServBay has already configured the URL rewrite rules for Caddy and Nginx by default, meaning you typically don’t need to make any additional configurations.
This guide will walk you through migrating an Apache-configured website to run on the Caddy server provided by ServBay in a local development environment. We’ll use popular Laravel and WordPress projects as examples.
About ServBay's Apache Support
ServBay fully supports Apache as a web server. If you want to switch ServBay’s default web server to Apache or learn how to configure Apache sites within ServBay, please refer to this documentation: How to Switch the Default Web Server to Apache. This article focuses on migrating existing Apache-configured websites to the Caddy environment within ServBay.
Overview
Migrating a website from one web server to another involves adapting configuration files and assets. ServBay enables users to use Caddy as their web server and provides out-of-the-box support for most PHP frameworks and CMS platforms. This means ServBay automatically handles essential configurations, including rewrite rules. Therefore, migrating an Apache-configured website to Caddy within ServBay is generally straightforward—the main task is to properly "add the website" in ServBay.
Pre-Migration Checklist
Before starting any migration, make sure you:
- Backup Files: Create a full backup of all your website files, including code, images, uploads, and all content in the site's root directory.
- Backup the Database: Export and back up your website's database. ServBay supports multiple databases such as MySQL, PostgreSQL, MongoDB, etc. Use appropriate tools for backup.
- Confirm ServBay Installation: Ensure ServBay is installed and running successfully on your macOS system.
- Check Caddy Package Activation: In the ServBay application, make sure the Caddy package is enabled.
Migrating a Laravel Website to Caddy
Let’s assume you have a Laravel website with the following Apache configuration:
Typical Apache Configuration Example (Outside of ServBay)
Here's a sample Apache VirtualHost configuration for a Laravel website outside of ServBay. Note that the DocumentRoot
is set to the public
directory and AllowOverride All
enables rewrite rules in the .htaccess
file.
<VirtualHost *:80>
ServerName laravel.demo
DocumentRoot /path/to/your/laravel/public
<Directory /path/to/your/laravel/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# PHP handling is usually set up here, for example via FPM or mod_php
# FilesMatch \.php$>
# SetHandler "proxy:unix:/path/to/php-fpm.sock|fcgi://localhost"
# </FilesMatch>
</VirtualHost>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Running This Laravel Website in ServBay (Using Caddy)
With ServBay, you do NOT need to manually write or convert the above Apache configuration into Caddy syntax. ServBay is designed to simplify local development configuration. For popular frameworks like Laravel, ServBay automatically creates the appropriate Caddy configuration for you when you add the website, including pointing to the public
directory and handling rewrite rules.
How to do it:
- Copy your entire Laravel project to a subdirectory under ServBay’s web root, such as
/Applications/ServBay/www/your-laravel-project
. Make sure thepublic
directory is located inside this path. - Open the ServBay application.
- Go to the “Websites” management section.
- Click the “Add Website” button.
- In the configuration window that opens:
- Domain: Enter the domain you wish to use for accessing the site, such as
laravel.servbay.demo
. ServBay will add this to your local hosts file automatically. - Document Root: Click the browse button and select the
public
directory of your Laravel project, for example/Applications/ServBay/www/your-laravel-project/public
. - Web Server: Select
Caddy
. - PHP Version: Choose the PHP version required for your project.
- Application Type: Select
Laravel
. This is crucial for ServBay’s automatic configuration.
- Domain: Enter the domain you wish to use for accessing the site, such as
- Click “Save” or “Add”.
After completing these steps, ServBay will automatically generate the relevant Caddy configuration for laravel.servbay.demo
, directing traffic to the public
folder, handling URL rewriting, and forwarding PHP requests accordingly. You can now access your Laravel site in the browser at http://laravel.servbay.demo
.
Example Caddy Configuration (For Reference Only — ServBay Generates This Automatically)
For your understanding, here's a hypothetical Caddy configuration that matches Laravel’s needs. Remember, you don’t need to create or edit this file yourself.
laravel.servbay.demo {
# Set the site's root directory to the public folder
root * /Applications/ServBay/www/your-laravel-project/public
# Configure PHP FastCGI processing
# ServBay automatically sets the correct socket path based on your PHP version and configuration
php_fastcgi unix//Applications/ServBay/tmp/php-cgi.sock
# Enable static file serving
file_server
# Main rewrite rule for Laravel: If the request is not for a real file or directory, rewrite to index.php
@notStatic {
not {
file {
try_files {path} {path}/ /index.php?{query}
}
}
}
rewrite @notStatic /index.php
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Migrating a WordPress Website to Caddy
Let’s assume you have a WordPress website with the following Apache configuration:
Typical Apache Configuration Example (Outside of ServBay)
Here's a sample Apache VirtualHost configuration for a WordPress website not using ServBay. WordPress typically sets the document root to the installation directory and relies on rewrite rules in the .htaccess
file for features like pretty permalinks.
<VirtualHost *:80>
ServerName wordpress.demo
DocumentRoot /path/to/your/wordpress
<Directory /path/to/your/wordpress>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# PHP handling is usually set up here
# FilesMatch \.php$>
# SetHandler "proxy:unix:/path/to/php-fpm.sock|fcgi://localhost"
# </FilesMatch>
</VirtualHost>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Running This WordPress Website in ServBay (Using Caddy)
Just like with Laravel, running WordPress under Caddy in ServBay requires no manual configuration of Caddyfiles. ServBay automatically detects WordPress requirements and generates the necessary configuration.
How to do it:
- Copy all your WordPress project files to a subdirectory under ServBay’s web root, such as
/Applications/ServBay/www/your-wordpress-site
. Ensure that files and directories such asindex.php
,wp-admin
,wp-includes
, etc. are all present. - Open the ServBay application.
- Go to the “Websites” management section.
- Click the “Add Website” button.
- In the pop-up configuration window:
- Domain: Enter the domain you wish to use—e.g.,
wordpress.servbay.demo
. - Document Root: Click browse and select the root directory of your WordPress project, such as
/Applications/ServBay/www/your-wordpress-site
. - Web Server: Select
Caddy
. - PHP Version: Choose the PHP version your project requires.
- Application Type: Select
WordPress
.
- Domain: Enter the domain you wish to use—e.g.,
- Click “Save” or “Add”.
ServBay will generate the corresponding Caddy configuration for wordpress.servbay.demo
, handling the document root, URL rewriting (for pretty permalinks), and PHP request forwarding. You can now access your WordPress site at http://wordpress.servbay.demo
, with permalink functionality working correctly.
Example Caddy Configuration (For Reference Only — ServBay Generates This Automatically)
Here’s what a standard Caddy configuration for WordPress would look like. You do not need to create or edit this file yourself.
wordpress.servbay.demo {
# Set the site's root directory
root * /Applications/ServBay/www/your-wordpress-site
# Configure PHP FastCGI processing
php_fastcgi unix//Applications/ServBay/tmp/php-cgi.sock
# Enable file serving
file_server
# Main rewrite rule for WordPress: enable permalinks
# If the request is not for a real file or directory, rewrite to index.php
@notStatic {
not {
file {
try_files {path} {path}/ /index.php?{query}
}
}
}
rewrite @notStatic /index.php
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Summary
Migrating existing Laravel or WordPress sites from an Apache environment to ServBay's Caddy server is straightforward and efficient. Thanks to ServBay’s built-in support for common application types, you don’t need to translate Apache .htaccess
or VirtualHost configurations into Caddyfile syntax yourself. All you need to do is add your site correctly in the ServBay application’s “Websites” management area, specify your desired domain and document root, select Caddy as your web server, and choose the appropriate application type (Laravel or WordPress). ServBay will automatically generate all the required Caddy configurations for you, including complex rewrite rules.
This level of automation streamlines the migration process and local development setup, allowing you to focus on your code—not server configuration.