Magento 2 Quick Setup Check

From Moogento How-to Guides
Jump to: navigation, search

Magento Setup Help

If you've just installed Magento and are having issues, first step is to check some basic things.

You might also want to check the official guide.

Check PHP Version

Acceptable PHP Versions for Magento 2

First up, Magento 2 won't work with some versions.

Here's the current list of accepted versions, for Magento 2.3:

acceptable-magento-versions-magento-23.png

And for Magento 2.2:

acceptable-magento-versions.png

Check the official requirements list here.

Running Magento 2 Locally

If you're running this locally, if you're using something like MAMP, check in the settings:

magento-mamp-php-versions.png

If the version showing as installed doesn't match one of the above accepted versions, change it before continuing.

Check Commandline PHP Version

Type: php -v

You should see something like this:

PHP 7.1.12 (cli) (built: Nov 27 2017 15:53:40) ( NTS )

Copyright (c) 1997-2017 The PHP Group

Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

with Zend OPcache v7.1.12, Copyright (c) 1999-2017, by Zend Technologies

First, if you're running Magento locally, and using something like MAMP, check the versions match.

If they don't then time to fix.

Remote / cPanel-type install
If you're running on something like cPanel, then you might find the CommandLineInterface doesn't use the 'correct' version of PHP.
You can then specify the specific version to use, eg.:
php -ea_php 71 -v
eg. here we're specifying to use php7.1 when running the command '-v' (= 'check php version')


Local / MAMP-type install
We want to get the commandline to use MAMP's version.
1. Edit the system settings to tell it to get PHP from the MAMP version:
nano ~/.bash_profile
Add this line, editing the php version to match whatever you have selected in MAMP:
alias phpmamp='/Applications/MAMP/bin/php7.1.12/bin/php'
2. Check where the local system is getting php from:
which php
which should return something like:
/usr/local/bin/php
3. Backup this php, using the path from (2):
sudo mv /usr/local/bin/php /usr/local/bin/php.bak
4. Make an alias to the MAMP PHP version, using the path from (2) and the PHP version from MAMP:
sudo ln -s /Applications/MAMP/bin/php/php7.1.12/bin/php /usr/local/bin/php
5. Reload the new settings:
source ~/.bash_profile
6. Check the new version is sticking:
php -v

Make Initial PHP Settings

Magento needs some minimum system resources. PHP by default will have 128MB of memory allocated. We want more!

Find In-use PHP Settings File (php.ini)

Type: php -r 'phpinfo();' | grep 'php.ini'

Should return something like:

/Applications/MAMP/bin/php/php7.1.12/conf/php.ini


Edit PHP Settings for Magento 2

  • These are basic settings for a new test install.
  • If you're running a live site these will be different!

1. Find that file from above and edit in a text editor.

2. Look for these settings and change them if they're different.

Uncomment (remove the semicolon from the start of the line) if needed.

memory_limit = 2G

^ You might be able to deal with 1G, but for things like updating Magento you might need the 2G.

date.timezone = "Asia/Bangkok"

^ Set this to match your local machine (if running local), or the server timezone.

always_populate_raw_post_data = -1

Uncomment this line:

zend_extension="...

Add this line near the above line:

opcache.save_comments=1

^ This turns on PHP caching which will make decent improvements to the speed Magento runs at.

Check PHP Version

Finally check the running PHP version:

php -v


Check file/folder ownership/permissions

In 1-user (eg. cPanel) setups

  1. Navigate to the magento install folder (the one with /app /var etc. in) in eg. FIleZilla,
    or via CLI eg. cd public_html/example_site.com
  2. Check write permissions are set for these folders:
    1. vendor
    2. app/etc
    3. pub/static
    4. var
    5. generated
    6. {any other static resources}
  3. If you need to change those permissions, use either FileZilla again,
    or via CLI eg. find var generated vendor pub/static pub/media app/etc -type f -exec chmod u+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod u+w {} + && chmod u+x bin/magento


In 2-user (eg. VPS) setups

  1. Make the user that will be the Magento file system user:
    sudo adduser {username}
    (Replacing {username} with the actual name for this user you want to create, eg. 'magento_user')
  2. Give that user a password:
    sudo passwd {username, eg. magento_user}
  3. Find the web server user (usually 'apache' in CentOs, or 'www-data' in Ubuntu):
    CentOS: grep -E -i '^user|^group' /etc/httpd/conf/httpd.conf
    Ubuntu: ps aux | grep apache to find the user, then groups {apache user} to find the group
  4. Move the Magento file system user in the web server user group:
    CentOS: sudo usermod -a -G apache {username}
    Ubuntu: sudo usermod -a -G www-data {username}
    eg. in CentOS: sudo usermod -a -G apache magento_user
    ^ Assuming the web server user you found earlier is "apache" or "www-data"
  5. Check your Magento file system user is in the web server user group:
    groups magento_user
    eg. this would mean primary is 'magento' and secondary is 'apache': magento_user : magento_user apache
  6. Restart the server:
    CentOS: service httpd restart
    Ubuntu: service apache2 restart
  7. Log in to the server as the Magento file system user, navigate to the Magento install folder, then set the ownership/permissions:
    find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {}
    find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws
    sudo chown -R :{web server group, eg. apache} .
    chmod u+x bin/magento
  8. Switch to the Magento file system user
    CentOS: su - {username, eg. magento_user}
    Ubuntu: su {username, eg. magento_user}


Check Magento 2 Version

php bin/magento --version

Update Magento 2.3.x Version

  1. Show the maintenance page
    php bin/magento maintenance:enable
  2. Update to a specific version
    composer require magento/product-community-edition 2.3 --no-update
    composer update
    If you're running on a cPanel-type setup, you might find it easier to install/run a local version of composer:
    curl -sS https://getcomposer.org/installer | php -d allow_url_fopen=On
    php composer.phar require magento/product-community-edition 2.3 --no-update
    php -d allow_url_fopen=On -d memory_limit=128M -ea_php 72 composer.phar update
  3. Update database
    php bin/magento setup:upgrade
    If you're running on a cPanel-type setup, you might need to specifically reference a magento-valid php version:
    php -ea_php 72 bin/magento setup:upgrade
  4. Recompile
    php bin/magento setup:di:compile
    If you're running on a cPanel-type setup, you might need to specifically reference a magento-valid php version:
    php -ea_php 72 bin/magento setup:di:compile
  5. Refresh indexes & clear the cache
    php bin/magento indexer:reindex && php bin/magento cache:clean && php bin/magento cache:flush && php bin/magento cache:enable
    If you're running on a cPanel-type setup, you might need to specifically reference a magento-valid php version:
    php -ea_php 72 bin/magento indexer:reindex && php -ea_php 72 bin/magento cache:clean && php -ea_php 72 bin/magento cache:flush && php -ea_php 72 bin/magento cache:enable
  6. Hide the maintenance page
    php bin/magento maintenance:disable
  7. Check version
    php bin/magento --version
    or, on a cPanel-type setup:
    php -ea_php 72 bin/magento --version

Update to Magento 2.3 from 2.2.x

Magento 2.3 has a minimum PHP version 7.1.3 or 7.2.x : check that first!

  1. Show the maintenance page
    php bin/magento maintenance:enable
  2. Make some changes to composer.json to deal with the new version:
    composer remove --dev sjparkinson/static-review fabpot/php-cs-fixer --no-update
    composer require --dev friendsofphp/php-cs-fixer:~2.10.1 --no-update
    composer require --dev sebastian/phpcpd:~3.0.0 --no-update
    composer require --dev phpunit/phpunit:~6.2.0 --no-update
    composer require --dev lusitanian/oauth:~0.8.10 --no-update
    composer require --dev pdepend/pdepend:2.5.2 --no-update
    composer require --dev squizlabs/php_codesniffer:3.2.2 --no-update
    If you're running on a cPanel-type setup, you might need:
    php -d allow_url_fopen=On composer.phar remove --dev sjparkinson/static-review fabpot/php-cs-fixer --no-update
    php -d allow_url_fopen=On composer.phar require --dev friendsofphp/php-cs-fixer:~2.10.1 --no-update
    php -d allow_url_fopen=On composer.phar require --dev sebastian/phpcpd:~3.0.0 --no-update
    php -d allow_url_fopen=On composer.phar require --dev phpunit/phpunit:~6.2.0 --no-update
    php -d allow_url_fopen=On composer.phar require --dev lusitanian/oauth:~0.8.10 --no-update
    php -d allow_url_fopen=On composer.phar require --dev pdepend/pdepend:2.5.2 --no-update
    php -d allow_url_fopen=On composer.phar require --dev squizlabs/php_codesniffer:3.2.2 --no-update
    php -r '$autoload=json_decode(file_get_contents("composer.json"), true); $autoload["autoload"]["psr-4"]["Zend\\Mvc\\Controller\\"]= "setup/src/Zend/Mvc/Controller/"; file_put_contents("composer.json", json_encode($autoload, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));'
  3. Update to a specific version
    composer require magento/product-community-edition 2.3 --no-update
    composer update
    If you're running on a cPanel-type setup, you might find it easier to install/run a local version of composer:
    curl -sS https://getcomposer.org/installer | php
    php composer.phar require magento/product-community-edition 2.3 --no-update
    php -d allow_url_fopen=On -d memory_limit=128M -ea_php 72 composer.phar update
  4. Update database
    php bin/magento setup:upgrade
    If you're running on a cPanel-type setup, you might need to specifically reference a magento-valid php version:
    php -ea_php 72 bin/magento setup:upgrade
  5. Recompile
    php bin/magento setup:di:compile
    If you're running on a cPanel-type setup, you might need to specifically reference a magento-valid php version:
    php -ea_php 72 bin/magento setup:di:compile
  6. Refresh indexes & clear the cache
    php bin/magento indexer:reindex && php bin/magento cache:clean && php bin/magento cache:flush && php bin/magento cache:enable
    If you're running on a cPanel-type setup, you might need to specifically reference a magento-valid php version:
    php -ea_php 72 bin/magento indexer:reindex && php -ea_php 72 bin/magento cache:clean && php -ea_php 72 bin/magento cache:flush && php -ea_php 72 bin/magento cache:enable
  7. Hide the maintenance page
    php bin/magento maintenance:disable
  8. Check version
    php bin/magento --version
    or, on a cPanel-type setup:
    php -ea_php 72 bin/magento --version

Check https

Check your cert

First check that you have installed your SSH cert correctly.

  1. Go to https://{your site domain}
  2. Click the lock on the left of the URL
  3. Check it shows valid

Set your Magento config to point to https

These will set default values - for a multi-site setup you'll need to edit this
bin/magento setup:store-config:set --use-secure 1
bin/magento setup:store-config:set --use-secure-admin 1
bin/magento setup:store-config:set --base-url "https://{your site domain}/"
bin/magento setup:store-config:set --base-url-secure "https://{your site domain}/"
* If your magento install isn't in the public root, add that path after your domain in the commands above (don't miss the trailing slash)

Check non-https auto-redirects to https

  1. Go to http://{your site domain}
  2. It should redirect to https://{your site domain}

Check cron runs via CLI

php bin/magento cron:run

Set language, currency, timezone

These will set default values - for a multi-site setup you'll need to edit this

Language

List the available language options:

bin/magento info:language:list

Eg. to set French:

bin/magento setup:store-config:set --language fr_FR


Currency

List the available currency options:

bin/magento info:currency:list

Eg. to set British Pounds:

bin/magento setup:store-config:set --currency GBP


Timezone

List the available timezone options:

bin/magento info:timezone:list

Eg. to set London UK:

bin/magento setup:store-config:set --timezone Europe/London


Magento Cache

While you're in the commandline, may as well enable Magento Caches:

bin/magento cache:enable

You can selectively enable/disable caches by adding from :

config layout block_html collections db_ddl eav full_page translate config_integration config_integration_api config_webservice

or do the lot - clean & flush the cache, then enable it:

bin/magento cache:clean && php bin/magento cache:flush && php bin/magento cache:enable

Enable Developer Mode

If you're running a local test install, or have a live dev server, check you've got developer mode enabled:

php bin/magento deploy:mode:set developer

Tidy Up Magento 2

Magento 2 comes with a couple modules that you'll probably not use, some of which annoyingly provide warnings in the Dashboard!

They might also slow down the store a bit, especially in development phase when your caches are off.


Check your installed Magento 2 modules

Quick check what you have installed/uninstalled:

php bin/magento module:status


Disable unnecessary Magento 2 modules

Here's a couple quick ones you might want to disable:

php bin/magento module:disable Magento_SalesAnalytics && php bin/magento module:disable Magento_CustomerAnalytics && php bin/magento module:disable Magento_Analytics && php bin/magento module:disable Magento_QuoteAnalytics && php bin/magento module:disable Magento_ReviewAnalytics && php bin/magento module:disable Magento_CatalogAnalytics && php bin/magento module:disable Magento_WishlistAnalytics

^ If you're not using Magento's cloud analytics service, then this will disable it and remove the 'ad' in the dashboard.

bin/magento module:disable Temando_Shipping

^ Unless you're shipping in Australia

bin/magento module:disable Dotdigitalgroup_Email

^ Unless you're using dotMailer

bin/magento module:disable Magento_Usps && bin/magento module:disable Magento_Ups && bin/magento module:disable Magento_Fedex && bin/magento module:disable Magento_Dhl

^ Unless you're offering USPS, UPS< FedEx

bin/magento module:disable Magento_NewRelicReporting

^ Unless you're using NewRelic to monitor your app/server

bin/magento module:disable Magento_SampleData

^ If you're not using the Magento Sample Data to test a setup

bin/magento module:disable Magento_Marketplace

^ If you don't need in-site access to the Magento Marketplace site

bin/magento module:disable Amazon_Payment && bin/magento module:disable Amazon_Login && bin/magento module:disable Amazon_Core

^ If you don't want to take payments in AmazonPay

bin/magento module:disable Klarna_Kp && bin/magento module:disable Klarna_Ordermanagement && bin/magento module:disable Klarna_Core

^ If you don't use Klarna payments

bin/magento module:disable Vertex_Tax

^ If you don't use Vertex tax services

Refresh the install

Don't forget to run the usual Magento 2 refresh commands here:

php bin/magento maintenance:enable

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:db-schema:upgrade

php bin/magento indexer:reindex

php bin/magento cache:clean && php bin/magento cache:flush && php bin/magento cache:enable

php bin/magento maintenance:disable

Show the Demo Store Notice on Magento 2

If you're not yet live, or have a dev and live server, it's helpful to visually separate live vs dev with a demo store 'hello bar'.

  1. In admin, ContentDesignConfiguration
  2. Select the store to add the Demo notice to
  3. In 'Other Settings' -> 'HTML Head', set the 'Display Demo Store Notice'