Setting up a ownCloud Server on Ubuntu with NGINX

Setting up a ownCloud Server on Ubuntu with NGINX

ownCloud is an open source, self-hosted file sync and share app platform. Access & sync your files, contacts, calendars & bookmarks across your devices.

The Story

Around three years ago, I purchased a web hosting service from GoDaddy, and I set up a personal cloud using KODExplorer(芒果云-资源管理器). With the personal cloud, I can easily share files between computers and virtual machines.
However, since I tried DigitalOcean, I decided to shift all my websites and services from GoDaddy to DigitalOcean. There are various reasons that DigitalOcean is much much better than GoDaddy. The biggest reason may be the freedom on a self-managed virtual machine. Besides, DigitalOcean runs on SSD, which makes it significantly faster than GoDaddy.
Recently, I tried to set up a new personal cloud on my DigitalOcean Droplet, and I found ownCloud is a good choice.


The recommended system setup listed on ownCloud Administration Manual is as follows:

  • Ubuntu 16.04
  • MySQL/MariaDB
  • PHP 5.6 +
  • Apache 2.4 with mod_php

On my DigitalOcean server, PHP7 is installed, and instead of Apache, I'm using NGINX. Thus I decided to try setting up my ownCloud on NGINX.

I download the ownCloud source code and uploaded to my server through FTP.

There are two PHP modules need to be installed.

apt-get install php7.0-zip  
apt-get install php-curl  


Now redirect to the ownCloud URL, a setup wizard will be shown. ownCloud intends to create a new database and a new DB user in MySQL, but due to the privilege issue, it always fails.
Actually, I can configure these parameters in the config.php located in owncloud/config/. A config.sample.php is given, you can just manually copy configuration switches that you consider important for your instance to the working config.php.
For instance, you can start your config file with the following content:

$CONFIG = array (
  'dbtype' => 'mysql',
  'dbhost' => 'localhost',
  'dbname' => 'owncloud',
  'dbuser' => 'your-db-username',
  'dbpassword' => 'your-db-password',

Other parameters will be added automatically by ownCloud later.

If you want to create a new MySQL user for ownCloud, the following command may be useful:

# Enter MySQL
mysql -u root -p

# Show all users
SELECT User FROM mysql.user;

# Create a new user and grant privileges
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';  
GRANT ALL PRIVILEGES ON * . * TO 'username'@'localhost';  

# Delete a user
DROP USER 'username'@'localhost';  

When I finished the setup wizard, a 404 error was occurred. This was caused by my NGINX configuration.
The url after logged in is .../owncloud/index.php/apps/files/, but since NGINX is configured as following:

location ~ \.php$ {  
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;

only urls end with .php will be executed as a php file. After deleting the dollar sign $, it should works. You can also add a specific prefix to the regx to make it safe.

Then I try to access my cloud, another error shown:
owncloud permission error This is because that I uploaded the stuff with my FTP account, but the ownCloud server is running as the user www-data (the default one for Debian/Apache). I have to change the owner to the user the server is running as:

chown -R www-data:www-data /var/www/cloud/  

Now, refresh the page, I can access my ownCloud successfully! However, there is a warning at the top of the page: There were problems with the code integrity check.
That including Apache configuration files, PHP configuration files, git files as well as some other stuff. But that can be ignored safely. Just add 'integrity.check.disabled' => true to the config.php file. Then the warning disappeared.


My ownCloud server is all set. I can access it from all my computer devices, install apps, and enjoy the high-speed downloading and uploading.

More: server