1

My original installation of v2.3.0 was working fine. All images showed up for categories. I decided (after setting up a lot of categories and images for those categories) to serve the site from pub.

The only code customization my site has is a modification for a bug that is apparently fixed in v2.3.1. Other than that, i have no third party modules installed or other code customizations.

I followed docs to make site more secure using Ubuntu and Apache2 (not nginx). When i visit a page with images (front-end or admin area), i get a 404 not found for the image. Page loads text and css but console outputs:

GET http://192.168.5.10/pub/media/Shoes/nike.jpg 404 (Not Found)

What i've tried that did not work:

  1. Looking for errors in /var/log/apache2/error.log and /var/log/apache2/error.log (found nothing other than a record of 404 but no permission errors.)
  2. Checked magento/var/log/system.log, magento/var/log/exception.log and magento/var/log/debug.log, no permission errors.
  3. Switching modes:

    bin/magento deploy:mode:set production  
    bin/magento cache:flush  
    bin/magento deploy:mode:set developer  
    bin/magento cache:flush  
    
  4. Made sure had default .htaccess in magento directory.

  5. Made sure pub/ had default .htaccess.

  6. Doc: bin/magento setup:static-content:deploy -f

  7. "Flush Cache Storage", "Flush Magento Cache", "Flush Catalog Images Cache", and "Flush Static Files Cache" from admin area > System > Cache Management.

  8. Refresh all cache types from admin area > System > Cache Management.

  9. Re-ran permissions as root cd /var/www/html/magento2 && 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 {} + && chown -R :www-data . && chmod u+x bin/magento

  10. Ran alternative permissions commands (does same thing as above):

    cd /var/www/html/<magento install directory>
    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 {} +
    chown -R :www-data . # Ubuntu
    chmod u+x bin/magento
    
  11. Checking permissions of example image from magento directory:

    magentouser$ ls -al pub/media/Shoes/nike.jpg
    -rw-rw-r-- 1 magentouser www-data 77645 Jan 15 17:14 pub/media/Shoes/nike.jpg
    
  12. rm -rf var/cache

  13. bin/magento indexer:reindex

  14. Checked my /etc/apache2/sites-available/000-default.conf

    Listen 8080
    <VirtualHost *:80>
    
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/magento2/pub
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    </VirtualHost>
    <Directory "/var/www/html">
    AllowOverride all
    </Directory>
    
  15. Re-started systemctl restart apache2

  16. Change DocumentRoot back to /var/www/html/magento2, and restarted apache2.

    Note: i was in the wrong demo server the first time i tried step 16 again. I had spun up so many test servers trying to re-duplicate the issue in different ways (too many terminals open trying to test different variations without attention to IP). I noticed while deleting all the demo servers from the network that the command was in the wrong one. After switching server 56 back to documentRoot to /var/www/html/magento2, and restarting apache on server 56, all images show up again normally. but the URL is still like (example): http://192.168.5.10/pub/media/Shoes/nike.jpg. I'm still not sure how "pub" got in there or even how i would add "pub" if it was't there and I wanted it, or how to remove it from the url and make the system look in the right place without having to re-upload all my images. This test confirmed again that when not serving from pub, the site works fine...but images appear to be already served in a strange way (unable to confirm this without a snapshot of the system before following docs to serve from "pub")

    How do you resolve this?

6
  • have you try to restart your server? Commented Feb 8, 2019 at 6:48
  • 1
    @EdwinWidhiyanto "Have you tried turning it off and back on again" lol. yes
    – jtlindsey
    Commented Feb 8, 2019 at 13:54
  • Hi, @learnsomemore, I am facing same issue, you got solution? Commented Sep 1, 2020 at 4:44
  • Did you ever figure out what the issue was? Commented Nov 11, 2020 at 19:58
  • Yes. The solution was for us was to stop using Magento and develop our own custom solution. For you it might be time to evaluate Magento enterprise (what Adobe wants now that they own it), or look at other open source solutions. Magento has a lot of money invested in marketing. "My site runs on magento -[Some Big Company]" doesn't provide practical insight into if it's a good platform. The quality of code should be most important and if the out of box experience following the docs and combing the repo isn't a clue, the github issues (open and closed) is.
    – jtlindsey
    Commented Nov 12, 2020 at 15:36

6 Answers 6

2

Check database table core_config_data, rows where path is web/secure/base_media_url and web/secure/base_media_url if the value contains "pub/" in the path. If it does, remove "pub/" from the value.

1

2 things come to mind based on your description:

  1. You might be missing .htaccess in your /pub/media/ folder.

  2. Since you made changes to Apache, you might have disabled the Options FollowSymLinks setting (since you mentioned that you increased security).

So you might have to change

Options +FollowSymLinks

to

Options +SymLinksIfOwnerMatch

in .htaccess in the following locations:

  • {Your root Magento directory}
  • /pub/
  • /pub/media/
1
  • i made the change to the .htaccess in all 3 areas and restarted apache. Getting a lot more errors (403s in addition to 404s) so i changed it back.
    – jtlindsey
    Commented Feb 8, 2019 at 19:32
0

After changing your document root in Apache to point to the pub subdirectory your correct image URL is

http://192.168.5.10/media/Shoes/nike.jpg

The image URLs provided by Magento should have the correct path, if you have set somewhere 'pub' in your image paths you have to remove that

7
  • I never set images to "pub" anywhere. I uploaded them via the admin GUI while working on categories. I followed the directions exactly from the docs for serving from root. Before serving from pub. images were working. after following docs, images not working.
    – jtlindsey
    Commented Feb 8, 2019 at 12:13
  • ok, can you please provide more information where this image come from? If it is referenced in a cms block, please paste the code in your question. By default magento uploads category images to 'media/catalog/category' directory, images from CMS upload are in 'media/wysiwyg'. Do you get product images with the correct path?
    – HelgeB
    Commented Feb 8, 2019 at 12:32
  • Images where uploaded before serving from pub. To upload image (in this case, to a category) I went to the category, clicked content, clicked upload. Note from my original...everything worked normally before serving from pub. All i did was change DocumentRoot to serve from pub. I did not upload anything after making serve from pub so if the issue is with default upload directory, it should have showed a problem before serving from pub shouldn't it? Given i haven't uploaded any new images after modifying document root?
    – jtlindsey
    Commented Feb 8, 2019 at 13:53
  • media/Shoes is not a Magento default directory. The default directory for category images uploaded in the content area of the category in the admin panel is media/catalog/category. Have you uploaded the image nike.jpg as "category image" in the admin panel? do you see the image now in the admin panel or at least a broken image there?
    – HelgeB
    Commented Feb 8, 2019 at 14:05
  • yes, the image is broken in admin area too. "media/Shoes is not a magento default directory". If I create a category in the backend named 'Shoes", and upload a image to the category content area. that image becomes domain/media/<Cagtegory>/<image>.png. or domain/media/Shoes/nike.png
    – jtlindsey
    Commented Feb 8, 2019 at 14:25
0

I think you may have not put name of correct directory of magento installation in virtualhosts, you've to mention path to pub directory of your magento installation in DocumentRoot.

<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot {path to magento installation}/pub

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory "/var/www/html">
                    AllowOverride all
        </Directory>
</VirtualHost>
1
  • Thanks for suggestion. it wasn't that. I updated question to reflect test
    – jtlindsey
    Commented Feb 8, 2019 at 19:23
0

In my case, the issue was with the permissions of the pub folder. Fixed by giving proper permissions

find ./var -type d -exec chmod 777 {} \;                // 777 permission for var folder    

find ./pub/media -type d -exec chmod 777 {} \;

find ./pub/static -type d -exec chmod 777 {} \;

chmod 777 ./app/etc
-2

You just have to remove the trailing slash "/" from the base url. Login to your MySQL console and select the database, execute

UPDATE core_config_data SET value='http://dev.abc.com' WHERE path='web/unsecure/base_url';

At the time of installation Magento by default puts a forward slash at the end of the base url when you change your DocumentRoot to pub, it needs to be updated i.e. remove that trailing slash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.