44

Can I write to file system on azure Web Site? for example updating or installing plugins/themes in Wordpress from dashboard. AFAIK, it is not possible on Heroku so what about Azure Web Sites?

Raghavendra
  • 1,419
  • 4
  • 19
  • 28
Ansd
  • 1,865
  • 3
  • 19
  • 30
  • Can you please explain why my answer downvoted? I'd clearly mentioned you don't have access to the C: or D: like you *traditionally* would. – Girish Oct 19 '12 at 14:20

6 Answers6

41

Surely it is possible to write on the file system of Azure Websites. However your write permissions are limited to the root folder of your app. So, if you use ASP.NET, you shall be able to write anywhere within the Server.MapPath("~/from_here_on"). Meaning you shall be able to perform read/write/delete operations on files which are located in the root folder of your app and below. If you use PHP, the root folder can be get from $_SERVER['DOCUMENT_ROOT'] environment variable.

And a web application shall not need more privileges. For sure will not be able to write on the operating system folders.

astaykov
  • 30,768
  • 3
  • 70
  • 86
  • 3
    "Shall not need" is not quite accurate. Not all web apps store everything in the public directory. Many frameworks store cached templates outside of the document root. – Alexander Trauzzi Jun 18 '15 at 17:24
  • 1
    That'S the broken assumption of the PHP world - it assumes it can write everywhere. Anyway, I am not 100% sure, and it can be tested, but I think that the user the site runs under, can also write in one directory up from the document root. On the other hand, you can fairly easily make a sub-folder of DOCUMENT_ROOT be a `non-public` - not served by the web server at all. You can do this with Apache's .htaccess, you can also do it with IIS'es web.config. And if you cannot instruct your framework where to write its temp, then there is something terribly broken at its design. – astaykov Jun 18 '15 at 18:15
  • 2
    It's not a design issue, PHP should be allowed to do exactly what any other server language does. Assuming that it is document-root centric is the broken assumption. – Alexander Trauzzi Jun 18 '15 at 18:17
  • 1
    well, in my web server setup, I would be really concerned if any web worker has a write permissions to anything but the System's TEMP and its document root. But that's just me. Others may decide to run the web worker with a root account ... – astaykov Jun 18 '15 at 18:19
  • 2
    You've incorretly assumed that I'm advocating running using a root account. Massive difference. Permissions still apply here - as they should. The issue at hand here is limiting access to the filesystem under to be only under the document-root. – Alexander Trauzzi Jun 18 '15 at 18:20
  • 1
    and should that be an issue ? :) – astaykov Jun 18 '15 at 18:23
  • 1
    Yes, absolutely. It's universally accepted that a PHP app shouldn't host all its code under the document root. Usually you only want the bootstrap `index.php`. So for things like compiled templates, it needs a temp dir it can write to that isn't the system-wide temp. – Alexander Trauzzi Jun 18 '15 at 18:36
  • 1
    `it needs a temp dir it can write`, if you come back to my first comment, you will notice that I said `**not** being able to configure this temp dir, is a broken design`, and not the idea that the framework needs a temp. – astaykov Jun 18 '15 at 18:57
  • 1
    And I come back to the assertion that you're making an unfair imposition: https://github.com/laravel/framework/issues/8123#issuecomment-85796989 - It's not that it isn't configurable. – Alexander Trauzzi Jun 18 '15 at 19:28
  • Once I wrote a file to a subfolder, will it be available after the next deployment? – ulu Jul 04 '15 at 17:08
  • It depends. But I would generally use Blob Storage to store files which I want to be persisted. There are many reasons for that. And only one is, that Storage on Azure Web Apps is very limited: http://azure.microsoft.com/en-us/pricing/details/websites/ . Do not make mistake - every byte in your storage counts - logs, your application, user uploaded files, your source code (if you enabled integration with source control) along with deployments and deployment history ... – astaykov Jul 06 '15 at 11:02
6

Just as an additional information if someone encounters a could not find a part of the path ... error while writing: make sure that the folder you are writing to gets deployed. In my case it was an empty temporary directory which got skipped during deployment.

Nico
  • 3,542
  • 24
  • 29
2

I offer to use a blobs container instead to store permanent content that must be persisted regardless of virtual machines re-initialization or upgrades.

Konstantin Isaev
  • 642
  • 8
  • 14
  • 6
    Windows Azure *Web Sites*, as well as Windows Azure *Virtual Machines* work with *persisted* storage, so nothing is lost ever (to the degree that something might be lost from a BLOB). These two Windows Azure components work on top of an Azure Drive, which uses BLOB for persitense. What you are talking about is Windows Azure *Cloud Service* and the question is specific to *Azure Web Sites* – astaykov Oct 19 '12 at 18:08
  • Also, you get a certain amount of free storage with a Web App, whereas you have to pay for a blob container right? – Savage Apr 08 '20 at 14:31
2

You can write to the HOME environment variable location (%HOME% / $HOME) on Azure App Services. You can use Kudu or the app service's console to cd into this directory and explore it.

Daniel
  • 8,655
  • 5
  • 60
  • 87
1

As far as I understand, you can write to the drive on an azure web role, but the problem is that a web role can have multiple instances so putting a file on whatever node you are connecting too doesn't put it on the other nodes and when that instance gets recycled it goes back to the original image of the web role so you would lose the file.

However it is possible to share a drive across instances of Azure web role nodes at least according to this article, and then you can setup a virtual folder beneath the web site that points to this shared drive and use that for media storage.

http://blogs.msdn.com/b/windowsazurestorage/archive/2011/04/16/using-smb-to-share-a-windows-azure-drive-among-multiple-role-instances.aspx

I haven't tried it yet myself but came across this question while searching about how to do it.

Joe Audette
  • 35,330
  • 11
  • 106
  • 99
-7

If you're asking about a C:\ drive or D:\ drive access on the Azure Website, the answer is no. You don't have access to the file system in that way on Azure websites. You do have access to the disk if it's a Web Role (Cloud services) or Virtual Machines.

However, as you may have know already, you can use Wordpress admin tool itself to edit the plugin code.

Girish
  • 558
  • 5
  • 12