Deploy Laravel for GitLab CI/CD
View on GitHub

Step 4: Fill in the variables

Fill in the variables in the .gitlab-ci.yml file:

The six workflow variables
  • base_directory

    This is the directory on the server that contains your project. More specifically, it is the directory that contains the "current" directory. For example:

    • If you set the base directory to "/var/www/project"
    • Then your webroot will be "/var/www/project/current/public"

    You can also use a tilde (~) as an alias for your home directory, for example: "~/project".

    If your project is already deployed but doesn't have a "current" directory yet (as in, your previous deployments didn't use a zero-downtime directory structure), just keep going. A later step will tell you how to migrate your current project.

    • ssh_user
    • ssh_host
    • ssh_port

    These three variables tell the script how to connect to your server.

  • private_ssh_key

    Add your private key as a repository variable. In the GitLab sidebar, go to "Settings > CI/CD". Create a variable called "PRIVATE_SSH_KEY" for your private key.

    Don't forget to add the corresponding public key to your server.

  • ssh_known_hosts

    This variable is optional, the deployment will still work if you leave this variable empty. This known hosts value will verify we are actually connecting to your server and not to an impersonator. This variable prevents man-in-the-middle attacks (which, let's be real, is not a common issue).

    Run the command ssh-keyscan <ssh_host> in your terminal. Copy and paste the full output of that command in a repository secret called "SSH_KNOWN_HOSTS". Make sure you run this command for the same host as your "ssh_host" variable.

  • php_executable

    This is the command that the deployment script will use the run PHP on your server. Most servers use the default "php" value. Servers configured with Laravel Forge might use an alias such as "php8.2" to run a specific version of PHP.