Installing and Configuring Kirby in the ServBay Environment
What is Kirby?
Kirby is a flexible and powerful file-based content management system (CMS) suitable for building various types of websites. Kirby does not rely on a database but instead uses the file system to store content, making it very lightweight and easy to deploy.
Steps to Install Kirby
In this article, we will introduce how to install and configure Kirby 4.2 using Composer in the ServBay environment.
Step 1: Create the Project Directory
First, create a new project directory in the www
directory of ServBay:
cd /Applications/ServBay/www
mkdir servbay-kirby-app
cd servbay-kirby-app
2
3
Step 2: Create a Kirby Project Using Composer
ServBay already comes with Composer, so we can use Composer directly to create a Kirby project:
composer create-project getkirby/starterkit .
Step 3: Configure the Web Server
Add a New Site
Open ServBay, click on the "Hosts" tab, and add a new site:
- Name:
My Kirby Site
- Domain:
servbay-kirby.local
- Site Type:
PHP
- PHP Version:
8.2
- Document Root:
/Applications/ServBay/www/servbay-kirby-app
- Name:
Save Configuration
Save the configuration.
Step 4: Configure Kirby
Create Content Directory
In the project root directory, the
content
directory has already been created by the Kirby Starterkit.
Step 5: Run Kirby
Access Kirby
Open your browser and navigate to
https://servbay-kirby.local
, where you will see the default Kirby welcome page.
Step 6: Install the Kirby Panel (Optional)
If you want to use the Kirby administration panel, you can follow these steps to install it:
Access the Kirby Panel
Open your browser and navigate to
https://servbay-kirby.local/panel
, where you will see the installation page for the Kirby panel.Create an Admin Account
Follow the on-page prompts to create an admin account, fill in the username, password, and email address, and then click "Create Account."
Using Kirby to Build a Website
Now that you have successfully installed and configured Kirby in the ServBay environment, you can start using it to build your website. Here are some common operations:
Create Pages and Content
Create a Page
Create a new page directory in the
content
directory. For example, create anabout
page:bashmkdir content/about echo "Title: About Us\n----\nThis is the about page." > content/about/about.txt
1
2Edit Templates
Create or edit template files in the
site/templates
directory. For example, create anabout.php
template:php<!-- site/templates/about.php --> <h1><?= $page->title() ?></h1> <p><?= $page->text() ?></p>
1
2
3
Configure the Navigation Menu
Edit Templates
Edit the main template file in the
site/templates
directory, for example,default.php
, to add a navigation menu:php<!-- site/templates/default.php --> <nav> <ul> <?php foreach ($site->children()->listed() as $item): ?> <li> <a href="<?= $item->url() ?>"><?= $item->title() ?></a> </li> <?php endforeach ?> </ul> </nav>
1
2
3
4
5
6
7
8
9
10
Customize Styles and Scripts
Add Styles
Create CSS files in the
assets/css
directory and reference them in the template files. For example, createstyle.css
:css/* assets/css/style.css */ body { font-family: Arial, sans-serif; }
1
2
3
4Reference the CSS file in the template file:
php<!-- site/templates/default.php --> <link rel="stylesheet" href="<?= url('assets/css/style.css') ?>">
1
2Add Scripts
Create JavaScript files in the
assets/js
directory and reference them in the template files. For example, createscript.js
:javascript// assets/js/script.js document.addEventListener('DOMContentLoaded', function() { console.log('Hello, Kirby!'); });
1
2
3
4Reference the JavaScript file in the template file:
php<!-- site/templates/default.php --> <script src="<?= url('assets/js/script.js') ?>"></script>
1
2
Through the above steps, you have successfully installed and configured Kirby in the ServBay environment and started using it to build your website. Kirby's flexibility and file-based architecture make it an ideal choice for building various types of websites.