Black Friday Sale: 50% off all plans!
Use code BLACKFRIDAY50

Header

Deploying a Magento 2 Project with DeployHQ

This guide will walk you through creating a new Magento 2 project and deploying it using DeployHQ.

Creating a New Magento 2 Project

Before setting up DeployHQ, you'll need to create your Magento 2 project. Follow these steps:

  1. Ensure you have Composer installed on your local machine.

  2. Open a terminal and navigate to the directory where you want to create your project.

  3. Run the following command to create a new Magento 2 project:

   composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition <install-directory-name>

Replace <install-directory-name> with your desired project name.

  1. When prompted, enter your Magento Marketplace authentication keys. If you don't have these, you can get them from your Magento Marketplace account.

  2. Once the installation is complete, navigate into your project directory:

   cd <install-directory-name>
  1. Initialize a Git repository and commit your files:
   git init
   git add .
   git commit -m "Initial Magento 2 project setup"
  1. Create a new repository on GitHub or your preferred Git hosting service, and push your local repository to it.

Setting Up DeployHQ

DeployHQ is a service that simplifies deploying applications to your servers. You can define configurations, custom commands, and automate deployments on pushing code.

Creating a Project in DeployHQ

  1. Sign up for a DeployHQ account if you haven't already.
  2. Log in to DeployHQ.
  3. Go to Projects > New Project.
  4. Follow the wizard and choose the repository where you pushed your Magento 2 project.
  5. If you encounter issues connecting, refer to DeployHQ's support page.

Configuring a Server

Now, tell DeployHQ where your Magento 2 application will reside:

  1. Go to Servers > New Server.
  2. Choose a memorable name and select SSH as the protocol.
  3. Enter your server's IP address in the Hostname field.
  4. Set the Username to a dedicated deployment user (e.g., deployhq).
  5. Check the "Use SSH key rather than password for authentication?" box.
  6. Set the Deployment Path to where your Magento 2 application will reside (e.g., /var/www/your-magento-project).
  7. Enable "Perform zero-downtime deployments on this server."
  8. Enter "production" in the Environment field and enable automatic deploy.
  9. Click Save.

Setting Up the Deployment User

On your server, create a dedicated user for deployments:

sudo adduser deployhq
sudo usermod -a -G www-data deployhq

Set up SSH access for this user:

su - deployhq
mkdir ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys

Paste DeployHQ's public key into this file, save and exit. Then set the correct permissions:

chmod 600 ~/.ssh/authorized_keys

Config Files (Optional)

To manage sensitive configuration files:

  1. Go to Config Files in DeployHQ and click New Config File.
  2. Copy the contents of your env.php or other configuration files into the config file content field.

Setting Up SSH Commands

Configure commands to execute on the server after deployment:

  1. Go to SSH Commands and click New SSH Command.
  2. Add the following commands in order:

a. Set Permissions: cd %path% && find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +

b. Update Composer Dependencies: cd %path% && composer install --no-dev --optimize-autoloader

c. Clear Cache: cd %path% && php bin/magento cache:flush

d. Update Database Schema: cd %path% && php bin/magento setup:upgrade

e. Compile DI and Generate Static Content: cd %path% && php bin/magento setup:di:compile && php bin/magento setup:static-content:deploy -f

f. Set Production Mode: cd %path% && php bin/magento deploy:mode:set production

Deploying Your Project

You're now ready to deploy:

  1. Click "Deploy Project" in the DeployHQ header.
  2. Ensure the correct server and revisions are selected.
  3. Click "Deploy" to start the deployment process.

Congratulations! You've now automated your Magento 2 project deployments with DeployHQ.

Tree

Proudly powered by Katapult. Running on 100% renewable energy.