I'm having a rather strange issue with Magento 2. I pulled a full copy of the site to my local dev, did some styling and content changes, nothing major, then migrated the site from my local back to the server, and for some reason, several but not all of the product images are missing.
I've had this issue with another site for a different client, but also a Magento 2 site, hosted in another SiteGround account.
To move the sites I:
- export the database (I've tried both with mysqldump command line and PHPMyAdmin)
- compress the entire site directory (I tried zip and tar)
- copy both files to or from the server using SSH scp command
- edit the env.php file with the corresponding local or remote DB info
- edit the core_config_data entries with corresponding local or remote domains
- clear cache and re-deploy static content
I've also tried to rsync the entire site with the same results.
Thank you for your advice.
Solved! Go to Solution.
The issue was related to the pub/media/catalog/product subdirectories case. Magento store product images in subdirectories that use the 1st and 2nd letter of the image filename, for example, a product which image file name is sticker.jpg is stored in pub/media/catalog/product/s/t/sticker.jpg.
The issue started when cloning the site to a local Mac OS dev environment, then cloned back to the server. Some directory names where in upper case and some not, and for some reason, the links to the product images which directory started with upper case were lost.
I fixed the issue by changing all letter directories to lowercase, then changing the image path to lower case as well in the corresponding database tables:
UPDATE catalog_product_entity_media_gallery SET value = CONCAT(LCASE(LEFT(value,4)),SUBSTRING(value, 5, CHAR_LENGTH(value)))
UPDATE `catalog_product_entity_varchar` SET value = CONCAT(LCASE(LEFT(value,4)),SUBSTRING(value, 5, CHAR_LENGTH(value))) WHERE value LIKE '/%'
I hope this helps somebody some time.
You, sir or ma'am, are a saint! This was exactly my issue and your fix worked beautifully. Strange issue. I noticed that one of my folders had a capital when navigating the folder structure but didn't pay attention to it. We have a third party dev working on our site and I assume somewhere along the line the site/code lived on MacOS.
Thank you so much for taking the time to come back to your own post to provide the answer!
Hey, I'm glad I helped. Magento 2 is full of surprises like this so it helps to document and share bits like this.