cPanel

Install Magento 2 on cPanel hosting

Install Magento 2 (Adobe Commerce open source) on cPanel with Composer and the command line: PHP version and extensions, database, OpenSearch requirement, cron jobs and production mode.

AdvancedcPanel hosting3 min read

Magento 2 is a powerful but heavy shop platform. You can run it on cPanel if the account has SSH or Terminal access, enough memory and a search engine (OpenSearch) to connect to. This guide covers a Magento 2 install on cPanel step by step.

Before you start

  • SSH access or cPanel → Advanced → Terminal.
  • PHP 8.2 or 8.3 with the extensions bcmath, ctype, curl, dom, gd, intl, mbstring, openssl, pdo_mysql, soap, sodium, xsl and zip.
  • A memory_limit of at least 2G for the CLI.
  • Access to an OpenSearch (or Elasticsearch) server. Magento 2.4 will not install without one, and most shared plans do not include it. If you cannot get one, use a VPS instead: see Magento 2 on a VPS.
  • Magento Marketplace access keys (public and private key) from your Adobe Commerce Marketplace account.

Set the PHP version and extensions

  1. Go to cPanel → Software → Select PHP Version (CloudLinux) or MultiPHP Manager.
  2. Choose PHP 8.2 or 8.3 for the domain and tick the extensions listed above.
  3. Under Options, set memory_limit to 2048M or higher and max_execution_time to 1800.

More detail is in select the PHP version and extensions in cPanel.

Create the database

In cPanel → Databases → Manage My Databases, create a database and a user, then add the user to the database with ALL PRIVILEGES. Note the full prefixed names, e.g. cpuser_magento.

Download Magento with Composer

Install into a folder outside public_html, then point the domain's document root at its pub folder:

cd ~ && composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2

Enter the Marketplace public key as the username and the private key as the password when asked. If Composer runs out of memory, prefix the command with COMPOSER_MEMORY_LIMIT=-1. Other problems are covered in fix common Composer errors.

Run setup:install

cd ~/magento2 && php bin/magento setup:install --base-url=https://shop.example.com/ --db-host=localhost --db-name=cpuser_magento --db-user=cpuser_mguser --db-password='DbPassword' --admin-firstname=Admin --admin-lastname=User --admin-email=you@example.com --admin-user=admin --admin-password='AdminPass123!' --language=en_US --currency=USD --timezone=UTC --use-rewrites=1 --search-engine=opensearch --opensearch-host=your-opensearch-host --opensearch-port=9200

At the end, the installer prints the admin URI, such as /admin_1abc2d. Save it.

Point the domain to the pub folder

In cPanel → Domains, edit the domain's document root to magento2/pub. Serving from pub keeps the app code out of reach of browsers.

Add the Magento cron jobs

php bin/magento cron:install

Or add php /home/cpuser/magento2/bin/magento cron:run every minute in cPanel → Advanced → Cron Jobs. Without cron, indexes, emails and scheduled tasks stop working.

Switch to production mode

php bin/magento deploy:mode:set production

This compiles code and deploys static files. It takes several minutes and a lot of memory.

Troubleshooting

  • Could not validate a connection to OpenSearch: the search host is wrong or unreachable from the server.
  • Allowed memory size exhausted: raise the CLI memory_limit, or run php -d memory_limit=-1 bin/magento ….
  • Unstyled pages: static files were not deployed. Run php bin/magento setup:static-content:deploy -f.

For more errors, see fix common Magento 2 errors.

FAQ

Can Magento 2 run on shared cPanel hosting?

Only if the plan allows enough memory, SSH and a reachable OpenSearch server. For most stores, a VPS is the more reliable choice.

Why can't I install Magento with Softaculous?

Magento 2.4 needs Composer and a search engine. One-click installers often cannot provide these on shared hosting, so the manual Composer install is more reliable.

Where is the Magento admin URL?

It is printed at the end of setup:install. You can also find it later with php bin/magento info:adminuri.

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.