سؤال

I am working on mageno 2.1.10 and I have tried setting mod to production from development by using the following solutions:

solution 1.

php bin/magento deploy:mod:set production

And it gave me the following error:

Something went wrong while deploying static content. See the error log for details.

Command returned non-zero exit code: /usr/bin/php5.6 -f /var/www/html/Katherine/bin/magento setup:static-content:deploy en_US

But There were no errors in error_log

After this error I have entered the following commands in terminal:

php bin/magento s:d:c (For di compile)
php bin/magento s:s:d (For static-content deploy)

And then some of the js and css were not loading on frontend.

Solution 2.

After the above solution didn't work for me then I have again set mod to developer and deployed static content which brough my store back to life.

Then I have tried the following code for setting it to production mode:

bin/magento setup:upgrade; bin/magento indexer:reindex; bin/magento deploy:mode:set production -s; bin/magento setup:di:compile; bin/magento setup:static-content:deploy

By doing this the frontend totally broke and none of the css/js were being loaded.

Also tried these in Database:

UPDATE `core_config_data` SET `value`='0' WHERE `path`='dev/js/merge_files';
UPDATE `core_config_data` SET `value`='0' WHERE `path`='dev/js/enable_js_bundling';
UPDATE `core_config_data` SET `value`='0' WHERE `path`='dev/js/minify_files';
UPDATE `core_config_data` SET `value`='0' WHERE `path`='dev/css/merge_css_files';
UPDATE `core_config_data` SET `value`='0' WHERE `path`='dev/css/minify_files';

This too didn't help and finally I ended up by setting it to developer mod.

Update 1

I have tried the answer provided by "Ayaz" on local host and this seems to be working fine. But on live server none of the css or js are being loaded

Following are the errors in browser console after trying this solution on live server:

CSS: Refused to apply style from 'website.com/pub/static/frontend/Pack/Theme/en_US/ThousandMonkeys_SocialButtons/css/social.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

JS: Refused to execute script from 'website.com/pub/static/frontend/Pack/Theme/en_US/owl.carousel/owl.carousel.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

There also some js files with console error : "net::ERR_ABORTED"

Update 2

I have checked the browser console and it is loading some css and js files which are (I think) from Magento base. The ones which are getting 404 in console are all the custom module's css/js

Image

enter image description here

Update 3

When in developer mode, I have tried to find the files in pub/static which were not found/deployed in production mode. These files were all shown as a link in FTP (FileZilla).

Update 4

So now I have disabled all the modules that are in app/code by adding Zeros for them in config.php. I have changed the theme to Magento Blank from admin. But still, when setting mod to production is ends up with the same error:

Command returned non-zero exit code: /usr/bin/php5.6 -f /var/www/html/Katherine/bin/magento setup:static-content:deploy en_US

Following are the logs generated when tried enabling production mod: debug.log and system.log, there was nothing in exception log.

P.S: I need to enable production mod in order to get minified css/js/html

How to debug and where should I look to fix this?

Is there any way to minify js in developer mode itself?

هل كانت مفيدة؟

المحلول

I have tried all the things as mentioned in question but none of these worked.

I have finally fixed this by installing fresh magento with same version and reinstalling all the modules one by one.

After installing each module I have tried the following command:

php bin/magento s:up; php bin/magento s:d:c; php bin/magento s:s:d; php bin/magento c:f

And all the modules were successfully installed on the same server one after the other without any errors.

Now I am able to deploy its mode to production.

نصائح أخرى

For me, I'm currently already in production mode Magento 2.3, I just wanted to apply some new code changes.

bin/magento setup:static-content:deploy -f

bin/magento cache:flush

that was it.

1) Set mode to production

php bin/magento deploy:mode:set production

2) Clear static contents with the following command

rm -rf var/di/* var/generation/* var/cache/* var/log/* var/page_cache/* var/session/* var/view_preprocessed/* pub/static/*

3) Deploy static content

php bin/magento setup:static-content:deploy
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top