Magento – In production mode the site does not load

magento2

I'm having problems with Magento 2.2.6
I deploy and when I go to the site it does not load
Here's how I deploy:

php bin/magento deploy:mode:show
Current application mode: production. (Note: Environment variables may override this value.)

rm -rf /var/www/html/magento2/var/view_preprocessed/*
rm -rf /var/www/html/magento2/var/page_cache/*
rm -rf /var/www/html/magento2/pub/static/*

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

php bin/magento setup:static-content:deploy -f pt_BR en_US

cd /var/www/html/magento2
chown www-data:www-data -R *
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find ./var -type d -exec chmod 777 {} \;
find ./pub/media -type d -exec chmod 777 {} \;
find ./pub/static -type d -exec chmod 777 {} \;
chmod 777 ./app/etc
chmod 644 ./app/etc/*.xml
chmod 777 ./generated

systemctl restart apache2
systemctl restart varnish
systemctl restart redis-server
systemctl restart mysql

Follows magento settings:
catalog/frontend/flat_catalog_category – 1
catalog/frontend/flat_catalog_product – 1
dev/template/minify_html – 1
dev/js/merge_files – 1
dev/js/enable_js_bundling – 1
dev/js/minify_files – 1
dev/css/merge_css_files – 1
dev/css/minify_files – 1
dev/grid/async_indexing – 1
dev/static/sign – 0

Access the site and error 500 in attachment (error.png)

I modify the /var/www/html/magento2/.htaccess file and add
SetEnv MAGE_MODE developer
The site returns to work correctly without any errors (site.png).
When I comment this line back does not work

I can not find where the error is.
I want to leave the site in production mode but ERROR 500 occurs

I would like your help if possible.

error.png
error.png

site.png
site.png

Best Answer

At a quick glance, you're probably running into one or more missing classes. In production mode, Magento doesn't generate any files; instead, it expects you to manually run bin/magento setup:di:compile and bin/magento setup:static-content:deploy on your own.

I see you run bin/magento setup:static-content:deploy; however, you never compile the dependency injection code. This generates all the interceptors, proxies, and other "missing" classes that are normally generated on-the-fly when in developer mode.

I would look in your Apache error logs to see the caught 500 error. You could also check the PHP error logs, as well as the exception and system logs in Magento.

When building a deployment for my site, I do the following steps:

  1. Update branch to be deployed: git fetch && git pull
  2. Set the deployment mode to production (just to be sure): bin/magento deploy:mode:set production
  3. Install composer dependencies: composer install --no-dev --no-suggest --optimize-autoloader
  4. Run upgrade to bring database up-to-date: bin/magento setup:upgrade
  5. Run Magento compilation for dependency injection files: bin/magento setup:di:compile
  6. Generate static content: bin/magento setup:static-content:deploy <lang_Code(s)>

At this point, you should have a bunch of files in the generated, var/view_preprocessed and pub/static folders. The files that you are most likely missing are those in the generated folder.

Related Topic