DEV Community

Mahesh Prajapati
Mahesh Prajapati

Posted on

How to Install Magento 2 on Shared Hosting ?

Because of its resource requirements and server limitations, Magento 2 might be difficult to install on shared hosting. If the hosting environment satisfies Magento's minimal criteria, it is feasible.

Pre-Installation Checklist

1. Verify Hosting Requirements:

  • PHP version: 7.4+ (or the latest version supported by Magento).
  • MySQL version: 5.7+ or MariaDB 10.4+.
  • Elasticsearch: May not be available on shared hosting (required for Magento 2.4+).
  • PHP Extensions: intl, soap, bcmath, gd, mbstring, xsl, cURL, zip, etc.
  • Composer Support: Some shared hosting providers include Composer, or you can use it locally.

2. Secure FTP and Database Access:

  • FTP credentials for uploading files.
  • A database (MySQL/MariaDB) created through cPanel.

3. Magento Package:

  • Download the Magento 2 ZIP file from the Magento Downloads page.

4. Domain or Subdomain:

  • Ensure your domain or subdomain points to the shared hosting account.

Step-by-Step Installation

1. Upload Magento Files

  • Download the Magento 2 ZIP package.
  • Extract it locally and upload the contents to your server using FTP or cPanel's File Manager.

2. Set File Permissions

  • After uploading, set the correct permissions: Folders: 755 Files: 644
  • Some shared hosting environments might require additional permission adjustments for pub, var, and generated directories.

3. Create a Database

  • Log in to cPanel.
  • Go to MySQL Databases:
  • Create a new database.
  • Create a new user and assign it to the database with ALL PRIVILEGES.

4. Configure Magento Installation

Navigate to your domain or subdomain in a browser (e.g., https://yourdomain.com).

The Magento Setup Wizard will start:

  • Readiness Check: Ensure your hosting meets the requirements.
  • Add Database Details: Enter the database name, username, and password.

Web Configuration:

  • Specify the Base URL (e.g., https://yourdomain.com).
  • Enable/disable HTTPS based on your SSL setup.
  • Admin Account: Create an admin username, password, and email.
  • Installation Path: Magento will configure itself.

5. Post-Installation Tasks

  • Set File Permissions Again:
chmod -R 775 pub var generated
chmod u+x bin/magento

Enter fullscreen mode Exit fullscreen mode

You may need to do this via SSH or ask your hosting provider for assistance.

  • Run Indexers (Optional): If SSH access is available:
php bin/magento indexer:reindex
php bin/magento cache:flush
Enter fullscreen mode Exit fullscreen mode

Without SSH, Magento automatically handles this after installation.


6. Fix Common Shared Hosting Issues

  • Cron Jobs: Configure cron jobs via cPanel for Magento's background processes. Example:
*/5 * * * * php /home/username/public_html/bin/magento cron:run
Enter fullscreen mode Exit fullscreen mode
  • Elasticsearch Workaround: Magento 2.4+ requires Elasticsearch. If not available, use an earlier Magento version (like 2.3.x) or request Elasticsearch from your hosting provider.

Troubleshooting Tips

  • Slow Performance: Shared hosting is limited in resources; consider upgrading to VPS or cloud hosting.
  • Readiness Check Fails: Ensure all required PHP extensions are installed/enabled. Contact your hosting provider for assistance.
  • Composer Errors: Use Composer locally to install dependencies, then upload the files to the server.

Magento 2 may work on shared hosting for small-scale stores or testing environments. For a production site, VPS or dedicated hosting is highly recommended for better performance, security, and scalability.

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay