Knowledgebase

Securing a Laravel or Custom PHP Application Print

  • securityabuse, security, php, permissions, cpanel, domain, https, database, password, caching
  • 0

Frameworks are secure by default in most respects, but deployment mistakes undo that.

DOCUMENT ROOT

Point the domain's document root at the application's /public folder, not the project root. If the project root is served, your .env file, vendor folder, storage and source code are all publicly reachable.

Change it in cPanel > Domains > Manage > Document Root.

THE .ENV FILE

It holds database credentials, mail passwords and application keys. It must never be reachable over HTTP. Verify by visiting https://yourdomain.com/.env and confirming you get a Forbidden or Not Found, never content.

DEBUG MODE

Set APP_DEBUG=false and APP_ENV=production in .env on any live site. Debug mode exposes environment variables, file paths and stack traces to anyone who triggers an error.

PERMISSIONS

storage and bootstrap/cache need to be writable, at 755, not 777.

OTHER ITEMS

Remove the .git folder from the server. Run composer install with --no-dev on production. Keep dependencies updated and run an audit periodically. Use the framework's built-in CSRF protection on every state-changing form. Set a strong, unique APP_KEY and do not reuse it between environments.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot