Fixing your Magento 2 guide.  Common things to look at and commands to perform

 

This is a guide of where to look at when you have problems with your magento installation.  We use it quite often and find it very useful.

  1. Cron jobs (Scheduled Tasks).  Things like Catalog price rules, newsletters, reindexing, emails, customer alerts and Notifications, etc. are done by cron jobs.  Magento crontab is used to run Magento cron jobs.  Common problems and fixes connected to cron jobs

           CRONTAB not installed or you might want to remove it and install it again

           php bin/magento cron:remove

           php bin/magento cron:install

           crontab -l

           A sample of the above command output

#~ MAGENTO START c5f9e5ed71cceaabc4d4fd9b3e827a2b

* * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/magento2/var/log/magento.cron.log

* * * * * /usr/bin/php /var/www/html/magento2/update/cron.php >> /var/www/html/magento2/var/log/update.cron.log

* * * * * /usr/bin/php /var/www/html/magento2/bin/magento setup:cron:run >> /var/www/html/magento2/var/log/setup.cron.log

#~ MAGENTO END c5f9e5ed71cceaabc4d4fd9b3e827a2b

// run as root user

systemctl start crond.service

Clear halted cron jobs from the database:

SELECT * FROM `cron_schedule` WHERE `cron_schedule`.`status` = 'running'

Remove var/log/cron.log

2. Magento commands that might save your day:

             php bin/magento c:c  // clear cache

             php bin/magento c:f   // flush cache

             php bin/magento setup:upgrade  // install update modules 

             php bin/magento setup:di:compile  // compile code - sometimes needed after above cmd

             php bin/magento indexer:reindex // reindex database

             php bin/magento catalog:image:resize  // resize and cache product images

             php bin/magento setup:static-content:deploy  // deploy static content in production mode

3. Changing Magento modes

Commands to change the modes:

             php bin/magento deploy:mode:show // show the current deployment mode

             php bin/magento deploy:mode:set developer // set magento to developer mode

             php bin/magento deploy:mode:set production // set magento to production mode

             php bin/magento deploy:mode:set production -s //without performing compilation and static content deploy (might be useful for machines with limited memory)

When you change from developer to production mode and vice versa the following folders are being cleared

var/cache

generated/metadata

generated/code

var/view_preprocessed

pub/static

4. Server memory check

free -m

top

5. Firewall settings - usually connected to site not available

firewall-cmd --zone=public --add-port=80/tcp --permanent; firewall-cmd --zone=public --add-port=443/tcp --permanent; firewall-cmd --reload

firewall-cmd --permanent --add-port=8080/tcp

sudo firewall-cmd --state

 

firewall-cmd --get-default-zone

sudo firewall-cmd --zone=public --list-ports

sudo firewall-cmd --zone=public --permanent --add-service=https

sudo firewall-cmd --zone=public --permanent --add-service=http