How to Install Drupal Commerce on macOS

In this tutorial, we will guide you on how to install Drupal Commerce on macOS. Drupal Commerce is an open-source e-commerce platform built on Drupal, a content management system.

Prerequisites

Before we start installing Drupal Commerce, make sure your system meets the following requirements:

Step 1: Install Composer

To install Drupal Commerce, we need to install Composer first. Composer is a dependency manager for PHP.

  1. Open the Terminal app on your Mac.

  2. Type the following command and press Enter to start the installation of Composer:

    $ curl -sS https://getcomposer.org/installer | php
    
  3. After the installation is done, move the composer.phar file to the /usr/local/bin directory with this command:

    $ mv composer.phar /usr/local/bin/composer
    
  4. Verify that you have installed Composer by typing this command:

    $ composer -v
    

    If the output displays the version of Composer, it means that Composer is installed correctly.

Step 2: Create a database

We need to create a database to store the Drupal Commerce website's data. We can use MySQL or MariaDB to create a database.

  1. Open the Terminal app on your Mac.

  2. Log in to the mysql client:

    $ mysql -u root -p
    
  3. Enter your MySQL root user password, if prompted.

  4. Create a new database with this command:

    mysql> CREATE DATABASE commerce_db;
    

    Replace "commerce_db" with any name you want to give your database.

  5. Create a new user with a password:

    mysql> CREATE USER 'commerce_user'@'localhost' IDENTIFIED BY 'password';
    

    Replace "commerce_user" with any name you want to give your user, and "password" with a strong password.

  6. Grant all privileges to the user:

    mysql> GRANT ALL PRIVILEGES ON commerce_db.* TO 'commerce_user'@'localhost';
    

    This command gives all privileges to the user for the commerce_db database, which means the user has full control over the database.

  7. Exit the mysql client:

    mysql> exit;
    

Step 3: Install Drupal Commerce

Now, we can install Drupal Commerce using Composer.

  1. Open the Terminal app on your Mac.

  2. Navigate to your Web Server's Document Root directory, where you want to install Drupal Commerce.

  3. Use the following command to download the latest version of Drupal Commerce:

    $ composer create-project drupalcommerce/project-base mysite --stability dev --no-interaction
    

    This command installs Drupal Commerce in a folder called mysite in your current working directory.

  4. Wait for the installation to finish, It may take a while.

  5. Modify the settings.php file and configure it to connect to the database.

    $ cp mysite/web/sites/default/default.settings.php mysite/web/sites/default/settings.php
    $ nano mysite/web/sites/default/settings.php
    

    Update the database settings in the settings.php file:

    'database' => [
        'default' => [
            'database' => 'commerce_db',
            'username' => 'commerce_user',
            'password' => 'password',
            'host' => 'localhost',
            'port' => '',
            'driver' => 'mysql',
            'prefix' => '',
        ],
     ],
    

    Save and close the file.

  6. Change the permissions of the files and settings.php directories to make them writable by the web server:

    $ chmod -R a+w mysite/web/sites/default/files
    $ chmod a+w mysite/web/sites/default/settings.php
    
  7. Open your web browser and navigate to http://localhost/mysite/web/.

  8. Follow the on-screen instructions to complete the installation process.

  9. Once the installation is complete, you can start building your Drupal Commerce website.

Conclusion

Congratulations! You have successfully installed Drupal Commerce on your macOS system. If you encounter any issues during installation, you can refer to the Drupal Commerce official documentation to solve them.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!