Installing OpenCart with Composer

New versions of OpenCart are now available on packagist and therefore can be managed with composer. In the following an installation of OpenCart via command line is described. An installation with this approach is primary for development purposes. Additionally, one could install a webserver like Apache or similar, which however is not covered in this guide. This approch was tested on linux, however should work also on Mac and Windows with a respective Shell.

To get started a new OpenCart project can be created with the composer create-project command.

composer create-project opencart/opencart

After executing this command would result in a opencart directory inside the directory the command was executed. One could rename the directory with e.g. the respective project name:

mv opencart my-opencart-project

For fully installing a OpenCart instance a MySQL database is required. This can be either achieved with PHPMyAdmin (or similar e.g. MySQL Workbench) or also via command line.

mysql -u root -p -e “create database opencart_project_name;”

Instead of the root user also another user could be choosen, however the respective rights to create a new database are required. Also the opencart_project_name database name could be different, depending on your project name or naming conventions.

After the database is created, basically all requirements for a successful OpenCart installation are given. The next and final step is to run the cli installer provided by OpenCart. This installer needs to be executed with the opencart project directory as working directory. So simply navigate into the directory.

cd my-opencart-project

So finally the the cli installer can be executed. The following parameters are required to use the installer:

  • db_hostname: defaults to localhost
  • db_username: database username, which has respective permissions
  • db_password
  • db_database: database for the OpenCart instance
  • db_driver: defaults to msqli, probably the only one working
  • db_port: defaults to mysql default port 3306
  • username: user which is created for the OpenCart backend
  • password
  • email
  • http_server: should be set to http://localhost:8000/ for our test environment (don’t forget the trailing slash)

So the command would look something like this:

php upload/install/cli_install.php install --db_hostname localhost --db_username root --db_password root --db_database my_opencart_project --username admin --password admin --email somebody@somewhere.com --http_server http://localhost:8000/

To get a running instance you can just navigate into the upload directory and start a build-in php webserver there.

cd upload
php -S localhost:8000

Opening your favourite web browser and entering http://localhost:8000 should bring up a fully functional OpenCart instance.

All the above steps and additional features are represented inside a github project. This repo can be used as a template for new projects. (https://github.com/beyondit/opencart-project-template)