Magento

Overview

Magento is an open-source eCommerce web application. This article provides steps to install Magento on a DreamHost domain.

For more information about Magento, please visit their site at:

Magento uses a large amount of server resources. Because of this, you can only install and run Magento on a VPS or Dedicated server. Running it on Shared hosting will cause the site to hit memory limits which can cause slowness and downtime.

For optimal performance (especially for larger stores), a Dedicated server or DreamCompute is recommended due to the presence of a local MySQL instance.

Before you install Magento

  1. Download Magento from their website at:

    Magento provides the option to download the installation file in a .zip, .tar, or .tar.bz2 format. .tar.bz2 is recommended since it's the smallest file to download, but any format will work.

  2. Create a phprc file under your user. Raise the php memory_limit to 756MB, increase the max_execution_time, and enable the intl extension. Here is what your phprc file should look like:
    max_execution_time = 5000
    memory_limit = 756M
    extension=intl.so
  3. Create a database that will be used by Magento. View the following article for further information:
  4. Set your domain to use PHP 7.1 or higher. View the following article for further information:

Installing

  1. Upload the Magento file you downloaded to your web server via FTP.
  2. Log into your server via SSH, then decompress the file on the server.
  3. Confirm the Magento files are in your domain’s web directory.
  4. When you first visit your domain, you'll see it's throwing a 500 error. This is because of the site's .htaccess file. You must now edit that file to remove certain lines.

Editing your .htaccess files

Your .htaccess files have several lines mentioning IfVersion. This requires 'mod_version' to be installed on the server. Since DreamHost servers do not have this module installed, you must manually remove those lines from the .htaccess files. They are located in the following two locations:

example.com/.htaccess

example.com/pub/.htaccess

You can download the edited .htaccess file below for the home directory .htaccess file. NOTE: This is the Magento .htaccess file for version 2.3.0.

  1. Open your .htaccess file via FTP or SSH.
  2. Here is an example of a block you'll see.
    <Files composer.json>
      <IfVersion < 2.4>
        order allow,deny
        deny from all
      </IfVersion>
      <IfVersion >= 2.4>
        Require all denied
      </IfVersion>
    </Files>
  3. Since DreamHost currently runs Apache version 2.2, you'll need to edit each block of code to remove the 2.4 text and <IfVersion> block. So, the above example would turn into this:
    <Files composer.json>
      order allow,deny
      deny from all
    </Files>
  4. Repeat for every block that starts with <IfVersion>.
  5. Save the file and visit your site. It should now load the Magento installation wizard.

The rest of the installation wizard is a site-level configuration and can be referenced in this page:

Troubleshooting

The site does not load after editing the .htaccess file

It's possible that after editing your .htaccess file, visiting your site displays a 500 error. Check your site's error.log file and you may see the following:

mod_fcgid: stderr: PHP Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /home/username/example.com/vendor/magento/framework/Filesystem/Directory/Write.php on line 35

This is due to the version of Magento not being compatible with the version of PHP you're using. If you're using Magento version 2.3.0, make sure you're only using PHP 7.1 or 7.2. That will resolve this error message.

I can't find the installation wizard

If you’re unable to load the Magento installation wizard, you may have the installation file in another location other than the domain’s root web directory. Check to make sure the installation file is not in a subdirectory, and also make sure all files, folders, and subfolders have the correct permission.

Links don't redirect correctly

If you completed the installation and click links such as “my account”, “my wishlist”, ‘my cart”, or “about us”, and find they are not functioning correctly, you probably checked the box ‘Use Web Server (Apache) Rewrites’ during the installation wizard. To fix this, create an .htaccess file in the site's root web directory and enter the following:

Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

 Login error 'Your current session has been expired'

When entering your Magento user/password, you may see the following error:

Your current session has been expired.

The following steps will resolve this:

  1. Log into your database using phpMyAdmin.
  2. In the left pane, click your database name to select it.
  3. In the top menu, click the 'SQL' tab.
  4. Enter the following command:
    INSERT INTO `core_config_data`(`path`, `value`) VALUES ('admin/security/session_lifetime',864000)
    It will look like this:
  5. Click the Go button to run it.
  6. Log into your server via SSH. Make sure you're in your website's directory.
  7. Run the following commands:
    [server]$ rm -rf var/cache/*
    [server]$ rm -rf var/page_cache/*
    [server]$ php bin/magento cache:flush
  8. Refresh your login page. You should now be able to log in.

Errors installing Extensions

You may see the following error when installing an extension.

The following sections explain how to resolve these errors.

Check Cron Scripts

Magento requires 3 different cron jobs to exist. View the following article for instructions on how to create a cron job:

You will need to create three separate cron jobs. In the following examples, change 'username' to your shell username, and 'example.com' to your Magento website.

Cron Job #1

/usr/local/php71/bin/php /home/username/example.com/bin/magento cron:run | grep
  -v "Ran jobs by schedule" >> /home/username/example.com/var/log/magento.cron.log

Cron Job #2

/usr/local/php71/bin/php /home/username/example.com/update/cron.php >>
  /home/username/example.com/var/log/update.cron.log

Cron Job #3

/usr/local/php71/bin/php /home/username/example.com/bin/magento setup:cron:run
  >> /home/username/example.com/var/log/setup.cron.log

This will correctly configure the cron jobs Magento needs. However, you should now manually run them so Magento knows they exist. Run the following three commands to forcefully update the cron  jobs in Magento:

[server]$ /usr/local/php71/bin/php /home/username/example.com/bin/magento cron:run | grep
  -v "Ran jobs by schedule" >> /home/username/example.com/var/log/magento.cron.log
[server]$ /usr/local/php71/bin/php /home/username/example.com/update/cron.php >>
  /home/username/example.com/var/log/update.cron.log
[server]$ /usr/local/php71/bin/php /home/username/example.com/bin/magento setup:cron:run
  >> /home/username/example.com/var/log/setup.cron.log

Click the Try Again button in Magento. This time, the cron error will no longer show.

Check Component Dependency

Make sure you have set the memory_limit in your phprc file to 2000M. Additionally, update the following .user.ini file with the same value:

example.com/.user.ini

Once both files have memory_limit = 2000M set, run the three cron jobs above to update this information.

PHP Settings Check

Setting the PHP memory_limit to 2000 should fix this error.

PHP Extensions Check

Running the cron jobs above fixes this error.

Backup failed

During Step#2, you may see the backup failed.

If so, run the following command in your website directory.

[server]$ /usr/local/php71/bin/php bin/magento config:set system/backup/functionality_enabled 1

Click the Try Again button and your backup will be created.

See also

Did this article answer your questions?

Article last updated PST.