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:
- A macOS operating system
- PHP 7.2 or higher
- MySQL 5.7 or higher
- Apache or Nginx Web Server
Step 1: Install Composer
To install Drupal Commerce, we need to install Composer first. Composer is a dependency manager for PHP.
Open the Terminal app on your Mac.
Type the following command and press Enter to start the installation of Composer:
$ curl -sS https://getcomposer.org/installer | phpAfter the installation is done, move the
composer.pharfile to the/usr/local/bindirectory with this command:$ mv composer.phar /usr/local/bin/composerVerify that you have installed Composer by typing this command:
$ composer -vIf 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.
Open the Terminal app on your Mac.
Log in to the
mysqlclient:$ mysql -u root -pEnter your MySQL root user password, if prompted.
Create a new database with this command:
mysql> CREATE DATABASE commerce_db;Replace "commerce_db" with any name you want to give your database.
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.
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.
Exit the
mysqlclient:mysql> exit;
Step 3: Install Drupal Commerce
Now, we can install Drupal Commerce using Composer.
Open the Terminal app on your Mac.
Navigate to your Web Server's Document Root directory, where you want to install Drupal Commerce.
Use the following command to download the latest version of Drupal Commerce:
$ composer create-project drupalcommerce/project-base mysite --stability dev --no-interactionThis command installs Drupal Commerce in a folder called
mysitein your current working directory.Wait for the installation to finish, It may take a while.
Modify the
settings.phpfile 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.phpUpdate the database settings in the
settings.phpfile:'database' => [ 'default' => [ 'database' => 'commerce_db', 'username' => 'commerce_user', 'password' => 'password', 'host' => 'localhost', 'port' => '', 'driver' => 'mysql', 'prefix' => '', ], ],Save and close the file.
Change the permissions of the
filesandsettings.phpdirectories 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.phpOpen your web browser and navigate to
http://localhost/mysite/web/.Follow the on-screen instructions to complete the installation process.
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.