Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

codefreak's avatar

Store images and other static content on subdomain.

I want to store images and other static content on subdomain. My main site works on www.domain.com and I want to store images on static.domain.com So How can I store images on subdomain in Laravel. I also want to access css , js file from static.domain.com Thanks.

0 likes
7 replies
bashy's avatar

Depends what your structure is like. You can set an A record for the subdomain, point it to your server IP then direct that to where you want to serve the files from (document root/root).

codefreak's avatar

@bashy. Thanks for your reply. I am talking about upload image on sub domain , access image and manipulating it for creating thumbnail. Currently I am using '../../subdomain/uploads/images' in my controller. Is there any other clean way to do that?

Magnetion's avatar

You could store them on Amazon S3 or some other CDN type service. Ideally these assets would not be stored on the same server, as some of the benefits of a CDN are kind of lost. I have something like this where I also have a function I use to wrap the URL's of these assets. If I need to drop the CDN for whatever reason I can change a setting and instantly have them read locally if needed.

bashy's avatar

Yeah could use cloud/CDN, really depends how scalable you want it or what the files are used for.

Shovels's avatar

As far as I know you should be able to use a folder in the root of your project e.g. public/static Then have subfolders for your images, css, js, etc. You can then upload/compile assets as per-normal

Create a virtual host for assets.yourdomain.com and point to /public/static

Then for your static assets use http://static.yourdomain.com/css/main.css

Also, you probably want to prevent cookies from being set for this sub-domain

3 likes
codefreak's avatar

@Shovels As you suggest I have a folder public/static But when i have to access images for creating thumbnail , Currently I access image like '../../static/images' from controller. Is there any cleaner way to access images. I don't want to use relative path.

bashy's avatar

Use one of these?

Paths

app_path();
// Get the path to the public folder
public_path();
// App root path
base_path();
// Get the path to the storage folder
storage_path();
2 likes

Please or to participate in this conversation.