How To: Configure the Environment for CS-Cart/Multi-Vendor

With our Ansible playbooks it only takes a few commands and adjustments to the configuration file to set up the environment for CS-Cart or Multi-Vendor. The playbooks will configure the web server for you automatically.

Note

If you don’t want to use Ansible playbooks, configure your server manually to meet CS-Cart system requirements.

Step 1. Install Ansible

Important

Our playbooks don’t handle package conflicts—if a package can’t be installed, you’ll get an error. That’s why we advise using the playbooks on clean OS installations only.

Depending on your server’s operating system, run the following commands one by one to install Ansible:

  • On CentOS 6:

    sudo yum -y install epel-release
    
    sudo yum install -y gcc git openssl-devel libffi-devel libselinux-python python-crypto python-jinja2 python-paramiko sshpass
    
    sudo rpm -ihv https://releases.ansible.com/ansible/rpm/release/epel-6-x86_64/ansible-2.4.1.0-1.el6.ans.noarch.rpm
    
  • On CentOS 7:

    sudo yum -y install epel-release
    
    sudo yum install -y gcc git openssl-devel libffi-devel libselinux-python python-crypto python-jinja2 python-paramiko sshpass
    
    sudo rpm -ihv https://releases.ansible.com/ansible/rpm/release/epel-7-x86_64/ansible-2.4.1.0-1.el7.ans.noarch.rpm
    

Step 2. Configure main.json

Once you have installed Ansible, you can download and run one of our playbooks to configure the server. Follow these steps:

  1. Clone the repository with our playbooks, so that you can run them:

    mkdir ~/playbooks && git clone https://github.com/cscart/server-ansible-playbooks ~/playbooks
    

    The command above creates a copy of this repository in the home directory on your server. That way you’ll always be able to find the directory with the playbooks by simply using the cd ~/playbooks command.

  2. Create main.json, a file that will be used by our playbooks to configure the environment.

    cp ~/playbooks/config/advanced.json  ~/playbooks/config/main.json
    

    The command above simply copies an existing file called advanced.json and pastes it as main.json in the same directory (~/playbooks/config). At this point, the file contains only the example configuration that you’ll need to change.

  3. Edit the main.json file in the ~/playbooks/config/ directory on your server according to your needs. By default, the file looks like this:

    {
        "stores_dir": "/var/www/html",
        "stores":
        {
            "example.com":
            {
                "cart":
                {
                    "storefronts": ["example.org", "example.ru"]
                },
                "database":
                {
                    "name": "cscart",
                    "user": "cscart",
                    "password": "cscart"
                }
            }
        }
    }
    
    • stores_dir—the directory that will contain the folders with your CS-Cart installations.

    • stores—an array with the data of your CS-Cart installations.

      • example.com—the domain name of your CS-Cart installation. It is also the name of the folder where that installation will be located. In this example we’ll have one CS-Cart installation located in /var/www/html/example.com.

      • storefronts—an array with the domain names of additional CS-Cart storefronts. If there are no additional storefronts, leave the array empty. For example: "storefronts": [].

      • database—the credentials of the MySQL database that will be created by the playbook for that particular CS-Cart installation:

        • name—the name of the database.

        • user—the name of the MySQL user account that will work with the database.

          Warning

          DON’T set root as a user, or else root won’t be able to access or create any other databases.

        • password—the password of the MySQL user specified above.

    If you work with your server via SSH (for example, if you are following our guide to install CS-Cart on DigitalOcean), then you can use a command-line text editor to modify main.json according to your needs. We recommend nano, because it’s the easiest to use:

    1. On CentOS you’ll need to install nano first. Run the following command:

      yum install nano
      
    2. Open the file you want to edit:

      nano ~/playbooks/config/main.json
      
    3. Now you’ll be able to edit the file. Navigate around it with arrow keys and work with the file like you usually do in a text editor. The example below is what we got after editing main.json for installing CS-Cart on DigitalOcean. That configuration is intended for a single CS-Cart or Multi-Vendor installation with no additional storefronts.

      Important

      Replace the domain name with your own and change the database credentials that will be created.

      {
          "stores_dir": "/var/www/html",
          "stores":
          {
              "doctorzoid.tk":
              {
                  "cart":
                  {
                      "storefronts": []
                  },
                  "database":
                  {
                      "name": "doctorzoid_tk",
                      "user": "doctorzoid_tk",
                      "password": "0NkpV5t9VcUYpKtM"
                  }
              }
          }
      }
      
    4. Press Ctrl + X to exit the editor. You’ll be asked if you want to save the changes. Press the Y button to do so, then press Enter to confirm the name of the file that you want to modify.

Step 3. Run a Playbook

Depending on the PHP version and the web server you want to use, run one of the playbooks by using a command below. If the playbook runs without errors, you will be able to install CS-Cart or Multi-Vendor after that.

  • lamp.yml: nginx + apache + mysql + php5.6

    cd ~/playbooks/ && ansible-playbook -e @config/main.json -c local -i inventory lamp.yml
    
  • lemp.yml: nginx + mysql + php5.6

    cd ~/playbooks/ && ansible-playbook -e @config/main.json -c local -i inventory lemp.yml
    
  • lemp7.yml: nginx + mysql + php7.0

    cd ~/playbooks/ && ansible-playbook -e @config/main.json -c local -i inventory_php7 lemp7.yml
    
  • lvemp7.yml: varnish + nginx + mysql + php7.0

    cd ~/playbooks/ && ansible-playbook -e @config/main.json -c local -i inventory_varnish lvemp7.yml