- Get either nginx or apache2. You can use the built in PHP web server for testing as well.
- Install PHP 8.0
- Make sure you have composer installed
- It is recommended that you install and use the divergence command line tool to bootstrap your project. If you wish to do this manually feel free to look in the section ahead.
A video of this process is available below.
composer global require divergence/cli` mkdir project cd project composer init divergence init
-
Make sure you initialize with composer first.
-
In your terminal run this from inside your project directory
composer require divergence/divergence
-
Copy some directories to bootstrap your project
cp -R vendor/divergence/divergence/public ./ cp -R vendor/divergence/divergence/views ./ cp -R vendor/divergence/divergence/bootstrap ./ cp -R vendor/divergence/divergence/config ./
-
Run
php -S localhost:8080 -t ./public/
from your project root directory. -
Visiting
localhost:8080
in your browser should show a phpinfo dump. -
Make a source directory for yourself
mkdir src
-
Open your
composer.json
and add this config to give yourself a namespace"autoload": { "psr-4": { "project\\": "src/" } },
Remember that your namespace will be whatever you put in for "project". For more details see composer's documentation.
- Open
config/db.php
and give your new project some MySQL database credentials. - You can also use the divergence command line tool for this.
- Create a new class
App
in your classes directory with the filenameApp.php
. Simply extend\Divergence\App
<?php namespace project; class App extends \Divergence\App { }
- Edit
bootstrap/app.php
and change theuse
at the top to use your new namespace in this caseproject\App
.<?php use project\App as App;
- Make a directory in your classes folder called
Controllers
and make a new file namedSiteRequestHandler.php
with these contents:<?php namespace project\Controllers; class SiteRequestHandler extends \Divergence\Controllers\SiteRequestHandler { }
- Make sure
bootstrap/router.php
has your app startup$app->handleRequest();
server {
listen 80;
listen [::]:80;
. . .
root /var/www/yourproject/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
. . .
}
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/yourproject/public
. . .
<Directory /var/www/yourproject/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
. . .
</VirtualHost>