PHP Tuning for Owncloud

PHP Tuning for Owncloud

This is the third part of a series on installing Owncloud on a Mac mini. The first part is the actual installation process and the second part was integrating Owncloud with Open Directory on a Mac . This final part is for fine tuning PHP for Owncloud. Once again, thanks to @kolbyallen for his help. 

PHP Tuning

Since Owncloud uses PHP to handle all the files uploads the possibility of running into a file size issues increases. 

There are two types of PHP tuning that will be visited. First will be for a multisite host, the second is more for a server dedicated to serving Owncloud files. 

First let’s look at .htaccess

This assumes you have completed at least part 1 of this tutorial

FTP into your owncloud installation and view the root directory. There should be a file in there called .htaccess. Open that file in your favorite text editor (I will use SublimeText 2)


1) There are going to be 3 lines that we will edit in the this file:

  • php_value upload_max_filesize
  • php_value post_max_size
  • php_value memory_limit

These lines override the php.ini settings. Allowing only this app to have these values and not all sites on the system.

2) Before we start to change any of these values we need to make sure that the machine has enough RAM in the machine. If you have a machine with only 2 GB of RAM, then setting these values anywhere near or above that will cause issues. Lets break down each so that you know what settings you are changing. 

3) upload_max_filesize: This controls the size of the files that can be uploaded from the web interface. So at its current setting, we can upload a 513MB file from the web interface.

  • post_max_size: This value must always be the same or larger then the upload_max_filesize. This value controls how much data that php can post to the web server. 
  • memory_limit: this limits the amount of total memory php can use from the server. Keep this larger or the same size as the previous 

4) If you’d like to be able to handle files of 1 GB, then you would replace these values with 1G, but you would need at least 1GB of RAM available to the web server. So be careful when setting this. In my experience I always set these a little lower and then slowly creep them up to where the issues go away. To check if these need to be larger you can look in the error logs for php file size errors.

5) Once you have made all your adjustments, save the file and you should see the changes in the Owncloud installation.

Second let’s look at php.ini

If you have a server dedicated to using Ownlcoud then it might be more worthwhile to just edit the php.ini file directly that controls these settings. This allows you to tweak a server wide setting instead of a site localized setting. 

*To do this you will be editing the php.ini file. To edit this file we will be using “sudo” commands. “sudo” must be used with care and caution. It allows you full control over all settings and files on the computer. We will make a backup of all files before we work with them to insure we can revert and keep our system running.

1) First lets backup the php.ini file on your mac. You will want to run the following command from terminal. 

sudo cp /etc/php.ini ~/Desktop/php.ini.bkup

2) Type in your administrator password when prompted.


3) Now we can edit the file. I will edit the file using nano. It is a simple text editor, but you could use whatever editor your prefer. Type the following command and enter your password when prompted:

sudo nano /etc/php.ini 


4) Now instead of scrolling through the whole file we will look for those parts that were also present in the .htaccess file 

  • upload_max_filesize
  • post_max_size
  • memory_limit

5) Type Control + W and search for upload_max_filesize. You will be taken directly to that part in the document.


6) Scroll over to the filesize and adjust to the level that you desire.
7) Complete this for each of the other 2 options following the same guidelines suggested in the first part.


8) Once you are done changing these settings we must save them. Type “control + x” to close the file, then hit “Y” and “enter” again. That will save the file.

9) Now we must restart apache for them to take affect. Type in the following command and enter your password if prompted:

sudo apachectl restart

10 The final step is to remove the following lines from your .htaccess file in your site root. Those settings will overwrite everything we just set. 

  • php_value upload_max_filesize XXXM
  • php_value post_max_size XXXM
  • php_value memory_limit XXXM

Leave a Reply