Home >Backend Development >PHP Tutorial >How to Use ServBay to Create and Run a CakePHP Project
CakePHP is an open-source PHP web framework designed to help developers build web applications quickly. It is based on the MVC (Model-View-Controller) architecture and provides a powerful toolkit to simplify common development tasks such as database interactions, form handling, authentication, and session management.
CakePHP is suitable for projects ranging from small applications to large enterprise systems, enabling developers to build high-quality web applications swiftly.
In this article, we will use the PHP environment provided by ServBay to create and run a CakePHP project. We will utilize ServBay's 'Host' feature to set up a web server and configure the project for access with simple steps.
ServBay uses Caddy as the default web server. For users migrating from NGINX and Apache to ServBay, there are some key points to note:
ServBay comes with Caddy pre-configured and optimized. Developers can manage sites through ServBay's 'Host' feature without manually modifying the Caddy configuration file.
In NGINX and Apache, developers typically write their own rewrite rules and .htaccess files for URL rewriting and other configurations. However, ServBay comes with pre-configured Caddy rules, so developers usually do not need to write these rules unless there are special requirements.
ServBay suggests placing websites in the /Applications/ServBay/www directory for easy management.
ServBay has Composer pre-installed, so no separate installation is needed.
Use Composer to create a new CakePHP project:
cd /Applications/ServBay/www mkdir servbay-cakephp-app cd servbay-cakephp-app composer create-project --prefer-dist cakephp/app .
Navigate to the newly created CakePHP project directory:
cd /Applications/ServBay/www/servbay-cakephp-app
In the config/app_local.php file, configure database connection information and other environment variables. Ensure the following configuration is correctly set:
'Datasources' => [ 'default' => [ 'host' => '127.0.0.1', 'username' => 'root', 'password' => 'password', 'database' => 'servbay_cakephp_app', 'url' => env('DATABASE_URL', null), ], ],
Use ServBay's 'Host' feature to access the CakePHP project via the web server. In ServBay's 'Host' settings, add a new host:
For detailed setup steps, please refer to [[Adding Your First Site]].
In the config/routes.php file, add the following code to output "Hello ServBay!":
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
In the src/Controller/PagesController.php file, add the following code:
namespace App\Controller; use Cake\Http\Response; class PagesController extends AppController { public function display() { return new Response(['body' => 'Hello ServBay!']); } }
Open a browser and visit https://servbay-cakephp-test.local. You should see the page output Hello ServBay!.
If you want more specific examples, you can visit the official Help Center.
Got questions? Check out our support page for assistance. Plus, you’re warmly invited to join our Discord community, where you can connect with fellow devs, share insights, and find support.
If you want to get the latest information, follow X(Twitter) and Facebook.
Let’s code, collaborate, and create together!
The above is the detailed content of How to Use ServBay to Create and Run a CakePHP Project. For more information, please follow other related articles on the PHP Chinese website!