Setting up localhost Apache/PHP on iCloud Drive

Update: I now use vvv on Dropbox instead, it’s a much simpler setup, more time building, less time with system admin work.

Prerequisite: you have a normal localhost LAMP setup, and your localhost/~username/ host serves the contents of ~/Sites/. If you don’t here’s the best step-by-step to get it running.

Alright, lets go:

iCloud drive is a neat place to save your localhost server contents as it backs up remotely and syncs across all devices. So work and home computer can have the same localhost files. As well iOS apps have access to it. A pretty cool way to do things.

Here’s how I got it running.

We’re going to point Apache to run off a folder in our iCloud drive, we’ll keep it named Sites (but it’s not the same as ~/Sites/), create it in iCloud Drive, add a sub folder named _temp and a index.php file with whatever phpinfo() or something therein to let you know when you’ve got things working.

Into Apache’s configuration:

sudo vi /etc/apache2/httpd.conf

Look for DocumentRoot and change to the following lines:

While in the file, we’ll also change the permissions of Apache to our current user

Then we need to change the owners of Apache to us:

And we’ll repeat for username.conf

sudo vi /etc/apache2/users/username.conf

And now let’s hide our temp folder from Finder

My understanding of the security involved with this is making sure PHP can’t touch anything outside of your Localhost directory in iCloud drive. The risks of a localhost being compromised is low but apparently possible using malicious scrips that fire off of localhost links. To prevent this, you can run localhost off of a random port instead of 80, and always ensure you have a good htaccess firewall preventing malicious queries.


  1. I tried this and unfortunately it didn’t work for me. Before I started I made copies of myhttpd.conf and username.conf files but although I have reverted back to them it does not work as before! I now get a 403 error when going to http://localhost, although http://localhost/~myusername does work. On my phpinfo file I can still see the iCloud path under documentroot as above and I’ve restarted Apache and my macbook several times and it won’t change back to /Users/myusername/Sites as it is under my httpd.conf file.
    Please help, I’ve googled for hours and can’t see anything like this!

  2. Sorry to hear about this. While figuring this out for myself I got caught up on 403s for a long time, I know how frustrating it can be.

    Reverting to your .conf backups (smart move by the way!) should of definitely worked as its a simple config file change, and it sounds like the restoring of these files wasn’t done properly if document root isn’t back to /Library/WebServer/Documents/ andor /Users/myusername/Sites.

    I’m sorry I can’t be of more help, it’s hard to troubleshoot remotely – I hope you’ve solved it.

  3. I use brew reinstall php71 and apache24.

    when everything is fine, then just change:


    DocumentRoot /Users/username/Library/Mobile Documents/com~apple~CloudDocs/Sites
    Directory /Users/username/Library/Mobile Documents/com~apple~CloudDocs/
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted

    that’s all, run info.php well done, thank you, and maybe Charlotte Andreanoff can reference, good lucky~

Leave a Reply

%d bloggers like this: