Symlink and Public folder issues SS4.1


Symlink and Public folder issues SS4.1

I appologise in advance for the long post!

I really like Silverstripe but since V4 came out, I am growing more and more frustrated with it…

The way I used to work would be that I would use composer to create a new site on my development machine, I would then create the templates, classes and functionality before FTPing the site to the development server, re-run the install, populate the content and the site was live.

When version 4.0 came out, there was a much bigger reliance on Composer, which is fine as it is great at maintaining compatibility but I found that the install process creates Sym Links in the resources folder to the Vendor folder. Sym links cannot be FTP’d, which left me with the options of:

  1. Using composer on the live server to install Silverstripe (this is difficult on the live server when compared to simply FTPing the site and also runs the risk of the live version not being exactly the same as the development version)

  2. Creating a copy of the files the sym link linked to in the resources folder (This means that there are duplicated files and folders, making updates more tricky)

This wasn’t the end of the world and I started making copies of the files in the resource folder.

Then V4.1 came along and added the public folder, for me, this has two further problems:

  1. I don’t have access to the necessary files to change the root folder of the site to public, so this functionality is of little use to me.

  2. I cannot figure out how to add a new theme for a site as simply creating the theme folder is not enough as the symlinks (again) need to be generated in the public resources folder.

I do understand the advantages of the reliance on composer and also the security advantages of the public folder, and if you have unrestricted access to the live server, this would be great, however, I am sure that I am not alone in that I do not have that kind of access to the live server, so the later advancements are simply throwing hurdles in my way. Silverstripe seems to be pushing this kind of developer out.

All I need to do is have an exact copy of the live site in my development environment, the easiest way to achieve this is the ability to FTP the site files to the live server.

To summarise, my questions are:

  1. Is there a way I can still work how I used to (having a local copy of the site and FTPing the site to the server?

  2. Is there anyway I can disable the use of the public folder during the installation process?

  3. If 1 or 2 are not possible, how do I create a custom theme and ensure that the resources folder in the public folder gets updated to allow me to use my new theme.


Hi Phillbex,

you don’t need to use /public/ in 4.1, just delete the folder and re-run composer vendor-expose to run your site with classic webroot. TBH I don’t use it yet cause you need to update all custom modules to expose their assets. In the long run it’s surely a big improvement.

You can also tell composer vendor-expose to copy over the files automatically if you don’t want symlinks. E.g. on Windows this happens automatically, but you can set the preferred method in an ENV var, see vendor plugin docs. Somewhere I also found you can place a file /resources/.method with your preferred expose method in 4.0, but I cannot find docs for it right now.

We also wrote a blogpost about exposing theme assets to resources and include them in your theme.

In the long run I suggest you look for a decent hosting with ssh access for composer; it’s a pretty common requirement nowadays. With a script like deployer it’s easy to deploy a project via ssh. I personally use it for most of my customers. The biggest plus with using a deployment script is that it runs all tasks you need automatically, e.g. checkout from your git repo, install composer no-dev (important if you have dev requirements that don’t belong on the live server like phpunit or ideannotator), copy over to sever, do other tasks like dev/build, send notice that everythign went well etc. How often did I forget to run dev/build or flush after updating a site manually cause uploading took too long…?

Or you look in another deployment tool like e.g. where you can define deployment pipelines with many different steps you need for each project. Depending on your budget you can get managed hosting. E.g. Derk from twistedbytes really knows what he’s doing and can help you and your customers to have stable and monitored hosting. I recently worked with him and it was a great experience. End of advertising section :wink:

The biggest problem is to change your current habbits. But that was also when you started composer or git, wasn’t it?

Edit: related topic: Handling composer vendor-expose without composer/ssh - #2 by DorsetDigital


Thanks for the reply, I tried just deleting the public folder and just got a 500 error. I also tried copying the contents of the public folder to the root before deleting the public folder and still got a 500 error.

I have now got the new theme working by adding:

    "expose": [

to the extra section of composer.json then doing a composer vendor-expose which created the symlinks for the new theme.

I do have SSH access and composer available with my host, it just seemed a bit of a faff compared to simply FTPing files to the server, but like you said, the hardest thing is changing current habbits, so will plod on!

Thanks for all your help, I really appreciate it.

Note that expose only works in your own composer.json when it contains "type": "silverstripe-something", e.g.

"type": "silverstripe-project",

Thanks, that’s good to know.

It is currently silverstripe-recipe so should be ok.

Btw maybe it will be helpful. I wasn’t able to change root folder too at client’s cpanel hosting so made it in a different way:

  1. Connect to ssh
  2. Move your SS folder from public_html (root) to silverstripe folder: mv ./public_html ./silverstripe
  3. Replace public_html with symbolic link to public folder: ln -s ./silverstripe/public ./public_html

@a2nt with cPanel I usually use a .tld-domain (placeholder) as main domain and than create addon-domains, so you can choose webroot. Also this way addon-domains are not nested in the main-domain under public_html.

I have an OVH performance server that I wouldn’t change for anything and I used to do most of my sites under SS3 and I was an advocate of Silverstripe, but since SS4, developers like myself who want to keep things simple like HTML, CSS, a bit of coding with a SQL database are completely left out. I do use composer on my Mac, to develop the sites, no worries, but all the symlinks, public folder and so on killed the simple workflow we had for years. I’m searching an alternative to Silverstripe that doesn’t require so much command line and tweaking, I tried my best to keep using Silverstripe, I’m sure some devs love all the new security features and composer, but as I can’t follow the rhythm of upgrades and all the technicality, I’m out.