Laravel
Prerequisites
Section titled “Prerequisites”- OpenLiteSpeed with PHP 8.2+ (see Install PHP)
- Required PHP extensions:
mbstring,xml,bcmath,curl,zip,tokenizer,json,openssl - Composer installed
- MySQL, MariaDB, PostgreSQL, or SQLite
Install Laravel
Section titled “Install Laravel”cd /var/wwwcomposer create-project laravel/laravel example.comcd example.com
# Set permissionschown -R nobody:nobody storage bootstrap/cachechmod -R 775 storage bootstrap/cacheConfigure the .env File
Section titled “Configure the .env File”cp .env.example .envphp artisan key:generateEdit .env:
APP_NAME="My App"APP_ENV=productionAPP_DEBUG=falseAPP_URL=https://example.com
DB_CONNECTION=mysqlDB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=laravelDB_USERNAME=laraveluserDB_PASSWORD=strong_password_here
CACHE_DRIVER=redisSESSION_DRIVER=redisQUEUE_CONNECTION=redisVirtual Host Configuration
Section titled “Virtual Host Configuration”Laravel’s entry point is public/index.php. The OLS document root must point to the public/ directory:
virtualhost example { vhRoot /var/www/example.com configFile conf/vhosts/example/vhconf.conf allowSymbolLink 1 enableScript 1 restrained 1
docRoot $VH_ROOT/public/
index { indexFiles index.php, index.html }
scripthandler { add lsapi:lsphp php }
rewrite { enable 1 autoLoadHtaccess 1 }}Rewrite Rules
Section titled “Rewrite Rules”Laravel requires all requests to be routed through index.php.
Option A: OLS Native Rewrite (in vhconf.conf)
Section titled “Option A: OLS Native Rewrite (in vhconf.conf)”rewrite { enable 1 rules <<<END_rules RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] END_rules}Option B: .htaccess (with LiteHTTPD)
Section titled “Option B: .htaccess (with LiteHTTPD)”Laravel ships with a public/.htaccess file that works with the LiteHTTPD module:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L]</IfModule>And in public/.htaccess:
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L]</IfModule>Context for Static Assets
Section titled “Context for Static Assets”Serve static assets directly without PHP processing:
context /build/ { location $VH_ROOT/public/build/ allowBrowse 1
extraHeaders { set Cache-Control "public, max-age=31536000, immutable" }}
context /storage/ { location $VH_ROOT/storage/app/public/ allowBrowse 1}Create the storage symlink:
php artisan storage:linkPHP Settings for Laravel
Section titled “PHP Settings for Laravel”memory_limit = 256Mmax_execution_time = 300upload_max_filesize = 64Mpost_max_size = 64M
; OPcacheopcache.enable = 1opcache.memory_consumption = 256opcache.max_accelerated_files = 20000opcache.validate_timestamps = 0With the LiteHTTPD module, you can also set per-directory overrides in .htaccess:
php_value memory_limit 512Mphp_value max_execution_time 600Production Optimization
Section titled “Production Optimization”# Cache configurationphp artisan config:cache
# Cache routesphp artisan route:cache
# Cache viewsphp artisan view:cache
# Optimize autoloadercomposer install --optimize-autoloader --no-devQueue Workers
Section titled “Queue Workers”For Laravel queues, use systemd to manage the worker:
[Unit]Description=Laravel Queue WorkerAfter=network.target
[Service]User=nobodyGroup=nobodyWorkingDirectory=/var/www/example.comExecStart=/usr/local/lsws/lsphp84/bin/php artisan queue:work redis --sleep=3 --tries=3 --max-time=3600Restart=alwaysRestartSec=5
[Install]WantedBy=multi-user.targetsystemctl enable --now laravel-workerTask Scheduling
Section titled “Task Scheduling”Add to the nobody user’s crontab:
* * * * * cd /var/www/example.com && /usr/local/lsws/lsphp84/bin/php artisan schedule:run >> /dev/null 2>&1Troubleshooting
Section titled “Troubleshooting”500 Internal Server Error:
- Check
storage/logs/laravel.log - Verify
storage/andbootstrap/cache/are writable by the OLS user - Run
php artisan config:clearif configuration cache is stale
404 on all routes:
- Verify rewrite rules are active (either in vhconf.conf or .htaccess)
- Ensure
docRootpoints to thepublic/directory
Session/cache issues:
- Verify Redis is running if using Redis driver
- Check file permissions on
storage/framework/sessions/andstorage/framework/cache/