How to Deploy Symfony Application on Plesk Print

  • 0

Here’s a clear step-by-step guide for deploying your Symfony application on a Plesk server that already has PHP and PostgreSQL installed, and your code is hosted on GitHub:


1. Prepare Your Plesk Environment

  1. Login to Plesk.
    Go to your Plesk dashboard.

  2. Create a Domain or Subdomain.

    • Websites & Domains → Add Domain/Subdomain.

  3. Enable Git support in Plesk.

    • Plesk has a Git extension (usually preinstalled).

    • If not, install it from Extensions → Git.


2. Connect Your GitHub Repository

  1. Go to your domain in Plesk → Git.

  2. Add a new repository:

    • Repository URL: Paste your GitHub HTTPS/SSH link.

    • Deployment mode: Choose Automatically deploy on push (if you want auto-deployment).

    • Deployment path: Set to httpdocs or another folder (e.g., httpdocs/myapp).

  3. If using private repo, configure deployment key in GitHub and Plesk.


3. Configure Symfony in Plesk

  1. Set document root:

    • By default, Symfony’s public entry point is /public.

    • In Plesk → Hosting Settings → Document root = httpdocs/public.

  2. Install Composer dependencies:

    You’ll need to rely on Plesk tools inside the GUI:

    • Composer in Plesk GUI

      1. Go to Domains → [Your Domain] → PHP Composer.

      2. Plesk can run composer install for you from the panel without SSH.

      3. You can add custom commands (like cache:clear) as post-deployment hooks.

    • Git Deployment Hook (No SSH Needed)
      In Plesk → Git → Repository Settings, you can set a Deployment Script.
      Example (runs after every deploy):

       
      /usr/bin/php8.1 bin/console cache:clear --env=prod /usr/bin/php8.1 bin/console doctrine:migrations:migrate --no-interaction --env=prod

      (Make sure to pick the right PHP path version in Plesk.)

  3. Set permissions for Symfony cache/logs:

    Use Plesk File Manager to Fix Permissions

    1. Go to Websites & Domains → File Manager.

    2. Navigate to your Symfony project → var/.

    3. Select the cache/ and log/ (or logs/) directories.

    4. Click on Change Permissions (lock icon).

    5. Set:

      • Read + Write for your web user (usually the same as your Plesk subscription user).

      • Read only for others (if option available).

    6. Save changes.

    This will give PHP (your web app) the necessary write access.


4. Configure Environment and Database

  1. Copy .env to .env.local in the project root.

  2. Update DB connection string for PostgreSQL:

     
    DATABASE_URL="pgsql://username:password@localhost:5432/databasename"

5. Configure PHP in Plesk

  1. In Plesk → PHP Settings:

    • Choose PHP version compatible with Symfony (8.1+ recommended).

    • Enable extensions: pgsql, pdo_pgsql, mbstring, xml, intl, ctype, tokenizer, json.

    • Increase memory_limit (e.g., 512M) and max_execution_time (e.g., 120).


6. Configure Web Server (Optional for Performance)

  • If using Apache + Nginx, ensure .htaccess or Nginx rules are correct.

  • Symfony requires index.php fallback. In Nginx, add:

     
    location / { try_files $uri /index.php$is_args$args; }

7. Test Deployment

  • Open your domain in the browser.

  • You should see the Symfony welcome page or your app’s homepage.

  • Check logs if issues occur:


Was this answer helpful?

« Back