Deploying an Anchor application involves a few common steps to ensure your application runs securely and efficiently in a production environment.
Ensure your server meets the following requirements:
- PHP: >= 8.2
- Extensions:
- BCMath
- Ctype
- JSON
- Mbstring
- OpenSSL
- PDO
- Tokenizer
- XML
- cURL
git clone https://github.com/beniyke/anchor-skeleton.git /var/www/your-appcd /var/www/your-app
composer install --optimize-autoloader --no-devcd /var/www/your-app
php dockSelect the "Standalone" option when prompted.
Ensure essential system packages and functional modules are installed for production.
# Core: Background job processing
php dock package:install Queue --system --force
# Core: System notifications (Drivers)
php dock package:install Notify --system --force
# Security: Authorization (RBAC/ABAC)
php dock package:install Permit --packages --force
# Analytics: Activity & Audit Tracking
php dock package:install Activity --packages --force
# Communication: In-app Notifications
php dock package:install Notification --packages --forceCopy the .env.example file to .env and configure your production environment variables.
cp .env.example .env
nano .envEnsure APP_ENV is set to production and APP_DEBUG is set to false.
Generate a new application key to ensure session and encryption security.
php dock key:generateEnsure the web server user (e.g., www-data) has write permissions to the storage directory and any other directories where the application needs to write files.
chown -R www-data:www-data /var/www/your-app
chmod -R 775 /var/www/your-app/storageHere is an example Nginx configuration for an Anchor application:
server {
listen 80;
server_name example.com;
root /var/www/your-app;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}If you are using Apache, ensure mod_rewrite is enabled. You can use the following .htaccess file in your public directory:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>When using managed mode (Composer), the composer install command with --optimize-autoloader already handles this.
Clear any existing application cache.
php dock cache:flushRun your database migrations to ensure the production database schema is up to date.
php dock migration:runIf your application uses queues, you will need to configure a process monitor like Supervisor to keep your queue workers running.
Example Supervisor configuration:
[program:anchor-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/your-app/dock worker:start --queue=default --memory=128
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/your-app/storage/logs/worker.log