Installation
Composer Install
The easiest way to install CodefyPHP is to use the application template via composer:
composer create-project codefyphp/skeleton project-name
This will install the latest stable version of the CodefyPHP application template in a directory named project-name. You can choose a different directory name if you want.
App Architecture
The architecture is pretty simple:
├── bootstrap
│ ├── app.php
│ ├── phpmig.php
│ └── providers.php
├── codex
├── composer.json
├── config
│ ├── app.php
│ ├── assets.php
│ ├── auth.php
│ ├── cache.php
│ ├── commandbus.php
│ ├── cookies.php
│ ├── cors.php
│ ├── csrf.php
│ ├── database.php
│ ├── filesystem.php
│ ├── headers.php
│ ├── http-cache.php
│ ├── mailer.php
│ ├── querybus.php
│ ├── rbac.php
│ ├── routes.php
│ ├── session.php
│ ├── stubs.php
│ ├── throttle.php
│ └── view.php
├── database
│ ├── codefy.sqlite
│ ├── migrations
│ │ ├── 20220925064056_CreateUsersTable.php
│ │ ├── 20230901025725_CreateEventStoreTable.php
│ │ ├── 20240918213932_AddTokenField.php
│ │ └── 20240919094937_AddRoleField.php
│ └── seeders
│ ├── DatabaseSeeder.php
│ └── UserSeeder.php
├── locale
│ ├── codefy.pot
│ ├── en
│ │ ├── codefy-en.mo
│ │ └── codefy-en.po
├── phpcs.xml
├── phpunit.xml
├── public
│ ├── assets
│ │ ├── css
│ │ │ ├── admin.css
│ │ │ ├── authforms.css
│ │ │ ├── bootstrap.min.css
│ │ │ ├── bootstrap.min.css.map
│ │ │ ├── bootstrap.rtl.min.css
│ │ │ ├── bootstrap.rtl.min.css.map
│ │ │ ├── cover.css
│ │ │ └── main.css
│ │ ├── images
│ │ │ ├── CodefyPHP-Banner.png
│ │ │ ├── CodefyPHP-Banner-Small.png
│ │ │ └── mark.png
│ │ └── js
│ │ ├── admin.js
│ │ ├── app.js
│ │ ├── bootstrap.bundle.min.js
│ │ ├── bootstrap.bundle.min.js.map
│ │ ├── color-modes.js
│ │ └── modes.js
│ ├── favicon.png
│ ├── index.php
├── README.md
├── resources
│ └── views
│ ├── app-layout.phtml
│ ├── backend
│ │ ├── admin-layout.phtml
│ │ ├── auth-layout.phtml
│ │ ├── index.phtml
│ │ ├── login.phtml
│ │ ├── partials
│ │ │ ├── x-create-user-modal.phtml
│ │ │ └── x-edit-user-modal.phtml
│ │ ├── profile.phtml
│ │ ├── register.phtml
│ │ └── users.phtml
│ ├── cache
│ ├── frontend
│ ├── home.phtml
│ └── partials
│ └── desktop-nav.phtml
├── routes
│ ├── api
│ │ └── rest.php
│ └── web
│ ├── admin.php
│ ├── auth.php
│ ├── register.php
│ └── web.php
├── src
│ ├── Application
│ │ ├── Console
│ │ │ ├── Commands
│ │ │ └── Kernel.php
│ │ ├── Http
│ │ │ ├── Controller
│ │ │ │ ├── AdminController.php
│ │ │ │ ├── AuthController.php
│ │ │ │ ├── HomeController.php
│ │ │ │ ├── ProfileController.php
│ │ │ │ └── RegisterController.php
│ │ │ ├── Middleware
│ │ │ └── Route
│ │ │ └── TestRoute.php
│ │ ├── Provider
│ │ │ ├── ApiRouteServiceProvider.php
│ │ │ ├── AppServiceProvider.php
│ │ │ ├── DatabaseServiceProvider.php
│ │ │ ├── MiddlewareServiceProvider.php
│ │ │ ├── Psr16ServiceProvider.php
│ │ │ ├── RbacServiceProvider.php
│ │ │ ├── ViewServiceProvider.php
│ │ │ └── WebRouteServiceProvider.php
│ │ ├── Service
│ │ │ ├── DatabaseService.php
│ │ │ └── Paginator.php
│ │ └── Shared
│ │ └── ValueObject
│ │ ├── TransactionUlid.php
│ │ ├── UlidIdentity.php
│ │ └── UuidIdentity.php
│ ├── Domain
│ │ └── User
│ │ ├── Command
│ │ │ ├── CreateUserCommandHandler.php
│ │ │ ├── CreateUserCommand.php
│ │ │ ├── DeleteUserCommandHandler.php
│ │ │ ├── DeleteUserCommand.php
│ │ │ ├── UpdateUserCommandHandler.php
│ │ │ ├── UpdateUserCommand.php
│ │ │ ├── UpdateUserPasswordCommandHandler.php
│ │ │ └── UpdateUserPasswordCommand.php
│ │ ├── Dto
│ │ │ ├── DestroyUserData.php
│ │ │ ├── StoreUserData.php
│ │ │ ├── UpdateUserData.php
│ │ │ └── UpdateUserPassword.php
│ │ ├── Enum
│ │ │ └── UserRole.php
│ │ ├── Event
│ │ │ ├── EmailAddressWasChanged.php
│ │ │ ├── NameWasChanged.php
│ │ │ ├── PasswordWasChanged.php
│ │ │ ├── RoleWasChanged.php
│ │ │ ├── UserWasCreated.php
│ │ │ └── UserWasDeleted.php
│ │ ├── Query
│ │ │ ├── FindUserByEmailQueryHandler.php
│ │ │ ├── FindUserByEmailQuery.php
│ │ │ ├── FindUserByIdQueryHandler.php
│ │ │ ├── FindUserByIdQuery.php
│ │ │ ├── FindUserByTokenQueryHandler.php
│ │ │ ├── FindUserByTokenQuery.php
│ │ │ ├── FindUsersQueryHandler.php
│ │ │ └── FindUsersQuery.php
│ │ ├── Repository
│ │ │ └── UserAggregateRepository.php
│ │ ├── Service
│ │ │ ├── UserProjection.php
│ │ │ └── UserService.php
│ │ ├── User.php
│ │ ├── Validator
│ │ │ ├── DestroyUserValidator.php
│ │ │ ├── StoreUserValidator.php
│ │ │ ├── UpdateUserPasswordValidator.php
│ │ │ └── UpdateUserValidator.php
│ │ └── ValueObject
│ │ ├── UserId.php
│ │ ├── Username.php
│ │ └── UserToken.php
│ └── Infrastructure
│ ├── Persistence
│ │ ├── PdoTransactionalEventStore.php
│ │ └── Repository
│ │ ├── EventSourcedUserRepository.php
│ │ └── PdoAuthUserRespository.php
│ └── Projection
│ └── ExpressiveDbalUserProjection.php
├── storage
│ ├── app
│ │ └── public
│ ├── email
│ ├── framework
│ │ ├── cache
│ │ ├── cookies
│ │ ├── media
│ │ ├── sessions
│ │ └── views
│ └── logs
└── tests
├── ExampleTest.php
└── Pest.php
Apache
If you are using an Apache server for development, you need to set up your virtual host. Follow this example:
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/myproject/public"
ServerName codefy.local
ErrorLog "/opt/lampp/htdocs/myproject/storage/logs/error_log"
CustomLog "/opt/lampp/htdocs/myproject/storage/logs/access_log" common
<Directory "/opt/lampp/htdocs/myproject/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The public folder under myproject is the root of you project where the .htaccess file is located.
Nginx
If you are using an Nginx server for development, you need to set you virtualhost config similar to this example:
server {
listen 80;
server_name codefy.local;
root /opt/lampp/htdocs/myproject/public;
index index.php index.html index.htm;
location / {
try_files $uri /index.php;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm:
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
# With php-cgi:
# fastcgi_pass 127.0.0.1:9000;
}
error_page 404 /index.php;
# deny access to hidden files such as .htaccess
location ~ /\. {
deny all;
}
}
Configuration
Once you have a server setup, you will need to perform some initial configuration before continuing below.
Encryption Key
Before proceeding, you need to generate the encryption key file by running the following command on the terminal:
php codex generate:key:file
Result:
Next you can create your database, run migrations, and seed your SQLite database by running the following commands:
php codex migrate && php codex db:seed
Once you make the server configuration changes, restart the server. Then, in a browser, visit the url http://codefy.local and you should see a successful installation:
-
Rename
.env.exampleto.envand change the variables to match your dev environment -
Next, open
config/auth.phpto change the url's to match your install -
Then run the commands
php codex migrate && php codex db:seedto run the database migrations and seed the database. The default password for all accounts istUB2sQoPuuX*3pycL0HGYMs2#!. -
If you don't seed the database, visit the url http://codefy.local/register/ to register your first account
then visit http://codefy.local/login/ to log in with the new credentials, and you will be redirected to the backend's dashboard.
the profile page is where you can update your profile.
This is a very simple app to get you started. Check out the code in the src directory which makes up the majority of the admin backend, event store, and domain functionality.
DDEV
As an alternative to above, DDEV is an easy to use and manage tool for local web development. Check out the Get Started with DDEV section on their website for a setup based on your operating system or setup. You will need to adapt the above settings to fit your DDEV setup.
Once you have DDEV installed and working, below are a few additions and/or changes you need to make if you are using an Apache setup.
.ddev/config.yaml
name: Codefy
type: php
docroot: public
php_version: "8.4"
webserver_type: apache-fpm
xdebug_enabled: false
additional_hostnames: []
additional_fqdns: []
database:
type: mariadb
version: "10.11"
use_dns_when_possible: true
composer_version: "2"
web_environment: []
corepack_enable: false
.ddev/php/php.ini
[PHP]
max_execution_time = 240;
apc.enabled=Off
opcache.enable=0
opcache.enable_cli=0
opcache.validate_timestamps=1
opcache.revalidate_freq=0
I have apc and opcache disabled, but you may enable it if it makes sense for your setup.
.ddev/commands/web/codex
To use the codex command line, you will need to create a file in .ddev/commands/web and name it codex
cd .ddev/commands/web && touch codex
Open the newly created codex and add the following to the file and save:
Restart DDEV to apply changes:
ddev restart
Now you should be able to run terminal commands like so:
ddev codex migrate:status
.ddev/php/php-cli.ini
If you run into deprecated messages appearing in the terminal when running codex commands, create a new .ddev/php/php-cli.ini file and add the following contents and then save.
.ddev/web-build/codefy.cron
To run the scheduler, do the following:
Open codefy.cron and add the following:
Restart DDEV to apply changes:
ddev restart




