<p>I'll use myself as an example, so if something isn't right we'll know who to blame.</p>

<p>First thing I do is set up an environment variable in my <code>craft/config/general.php</code> file like this:</p>

<pre><code>...
'.dev' =&gt; array(
    'devMode' =&gt; true,
    'siteUrl' =&gt; 'http://mysite.dev/',
    'environmentVariables' =&gt; array(
        'basePath' =&gt; $_SERVER['DOCUMENT_ROOT'] . '/',
        'baseUrl' =&gt; 'http://mysite.dev/',
    )
)
...
</code></pre>

<p>Then, when I am creating assets sources, I'll create a general "Images" source:</p>

<pre><code>Name: Images
Handle: images
File System Path: {basePath}media/images/
URL: /media/images/
</code></pre>

<p>Note that I am using my environment variable in the file system path.</p>

<pre><code>{basePath}
</code></pre>

<p>You can call that whatever you want, it just has to match.</p>

<p>So if you were to view the source of my site, an image that was uploaded would have the path of:</p>

<pre><code>http://www.mysite.com/media/images/my-image.jpg
</code></pre>

<p>Hope this helps!</p>

CC BY-SA 3.0
2016-01-19T02:09:41.377Z
Setting it up like this works for me whether or not I use environment variables. The problem comes when I try to make the url differ from the file system path, which I thought was possible in Craft. For example, I want to store my images in {basePath}media/images, but show them at www.mysite/images. Whenever I try to do that, I get a 404.
jimchristie
CC BY-SA 3.0
2016-01-18T22:05:52.127Z
2016-01-18T22:05:52.127Z
Damon
<blockquote>
  <p>For example, <strong>I want my images to be</strong> in public_html/media/images, but I want the url for images to be <a href="http://mysite.com/images" rel="nofollow">http://mysite.com/images</a>.</p>
</blockquote>

<p>When you configure an asset source you tell Craft where to find the images, not where you want them to be.</p>

CC BY-SA 3.0
2016-01-20T02:55:12.533Z
I'm not sure exactly what you're suggesting the problem is. I set my File system path to public_html/media/images. The images upload just fine, which I've verified by navigating to that directory on the server. They just don't display when clicking on "view asset" on the assets page. Instead, I get a 404.
jimchristie
CC BY-SA 3.0
2016-01-20T07:24:12.823Z
You have to set the URL to /media/images/ because that's the path to the folder. I was just saying you have to type in the facts, not your wishes (if that makes sense).
carlcs
CC BY-SA 3.0
2016-01-22T21:10:29.627Z
It was my understanding that you didn't have to use the same path in the URL as the path to the folder. I thought that's why there were two separate fields for path to file and path to folder. Is that not correct?
jimchristie
CC BY-SA 3.0
2016-01-22T23:02:12.990Z
No, both have to be set according to the path "public root" to asset directory. There's two separate fields because sometimes you need to set one or both of them as absolute paths and relative paths do not work.
carlcs
CC BY-SA 3.0
2016-01-19T09:47:24.700Z
2016-01-19T09:47:24.700Z
carlcs
<p>I'm having some trouble getting started with Craft.</p>

<p>I'm attempting to upload some image assets for the first time. </p>

<p>I've set up an asset source. I've tried using both a relative and an absolute path to the file. I am certain that the absolute path name is correct  because I simply copied from the <code>pwd</code> command on my server. Also, when I look in the directory, I see the uploaded images.</p>

<p>I've also supplied a url for the source. (I've actually tried a few different ones.)</p>

<p>Every time I've made a change, I've gone into settings and run <code>Update Asset Indexes</code> just to be sure everything was up to date.</p>

<p>However, when I try to view the images, I get a 404. I've tried typing the URL into the address bar, as well as clicking on "View asset" on the assets page. </p>

<p>I did see <a href="https://craftcms.stackexchange.com/questions/13227/assets-images-return-a-404-on-the-front-end">this similar question</a>, but I'm not running an nginx server. I'm running Apache.</p>

<p>I would love any insight on what I could be doing wrong. If you need any additional information, I'll be more than happy to edit it in.</p>

<p><strong>Edit:</strong> For clarity, I'm trying to set up my file directory and my url to have different structures, which I believe is possible. For example, I want my images to be in <code>public_html/media/images</code>, but I want the url for images to be <a href="http://mysite.com/images" rel="nofollow noreferrer">http://mysite.com/images</a>. Doing that seems to be what causes the problem. </p>

CC BY-SA 3.0
2016-01-19T12:11:30.443Z
Check your folder permissions, Craft was creating folders for assets with an obscure permission on my server which was saving but was unable to be called by apache.
William Isted
CC BY-SA 3.0
2016-01-20T02:50:15.407Z
@WilliamIsted I did that. They're all owned by www-data, have read permissions across the board, and write permissions for the owner and group.
jimchristie
<assets><404>
404 when viewing assets
# 404 when viewing assets

(Asked by: username_0 on 2016-01-18)

I'm having some trouble getting started with Craft.

I'm attempting to upload some image assets for the first time.

I've set up an asset source. I've tried using both a relative and an absolute path to the file. I am certain that the absolute path name is correct because I simply copied from the `pwd` command on my server. Also, when I look in the directory, I see the uploaded images.

I've also supplied a url for the source. (I've actually tried a few different ones.)

Every time I've made a change, I've gone into settings and run `Update Asset Indexes` just to be sure everything was up to date.

However, when I try to view the images, I get a 404. I've tried typing the URL into the address bar, as well as clicking on "View asset" on the assets page.

I did see [this similar question](https://craftcms.stackexchange.com/questions/13227/assets-images-return-a-404-on-the-front-end), but I'm not running an nginx server. I'm running Apache.

I would love any insight on what I could be doing wrong. If you need any additional information, I'll be more than happy to edit it in.

**Edit:** For clarity, I'm trying to set up my file directory and my url to have different structures, which I believe is possible. For example, I want my images to be in `public_html/media/images`, but I want the url for images to be <http://mysite.com/images>. Doing that seems to be what causes the problem.

**Tags:** assets, 404
> **Comments:**
> **username_1**: Check your folder permissions, Craft was creating folders for assets with an obscure permission on my server which was saving but was unable to be called by apache.  
> **username_0**: @WilliamIsted I did that. They're all owned by www-data, have read permissions across the board, and write permissions for the owner and group.  

---

## 2 answers

### Answer by username_2 on 2016-01-18. Score: 2

I'll use myself as an example, so if something isn't right we'll know who to blame.
First thing I do is set up an environment variable in my craft/config/general.php file like this:
...
'.dev' => array(
    'devMode' => true,
    'siteUrl' => 'http://mysite.dev/',
    'environmentVariables' => array(
        'basePath' => $_SERVER['DOCUMENT_ROOT'] . '/',
        'baseUrl' => 'http://mysite.dev/',
    )
)
...

Then, when I am creating assets sources, I'll create a general "Images" source:
Name: Images
Handle: images
File System Path: {basePath}media/images/
URL: /media/images/

Note that I am using my environment variable in the file system path.
{basePath}

You can call that whatever you want, it just has to match.
So if you were to view the source of my site, an image that was uploaded would have the path of:
http://www.mysite.com/media/images/my-image.jpg

Hope this helps!

> **Comments:**
> **username_0**: Setting it up like this works for me whether or not I use environment variables. The problem comes when I try to make the url differ from the file system path, which I thought was possible in Craft. For example, I want to store my images in {basePath}media/images, but show them at www.mysite/images. Whenever I try to do that, I get a 404.  

---

### Answer by username_3 on 2016-01-19. Score: 0

> For example, **I want my images to be** in public\_html/media/images, but I want the url for images to be <http://mysite.com/images>.

When you configure an asset source you tell Craft where to find the images, not where you want them to be.

> **Comments:**
> **username_0**: I'm not sure exactly what you're suggesting the problem is. I set my File system path to public_html/media/images. The images upload just fine, which I've verified by navigating to that directory on the server. They just don't display when clicking on "view asset" on the assets page. Instead, I get a 404.  
> **username_3**: You have to set the URL to /media/images/ because that's the path to the folder. I was just saying you have to type in the facts, not your wishes (if that makes sense).  
> **username_0**: It was my understanding that you didn't have to use the same path in the URL as the path to the folder. I thought that's why there were two separate fields for path to file and path to folder. Is that not correct?  
> **username_3**: No, both have to be set according to the path "public root" to asset directory. There's two separate fields because sometimes you need to set one or both of them as absolute paths and relative paths do not work.  

---

