ownCloud is a powerful, open-source software suite that allows you to create your own file-hosting services, similar to popular platforms like Google Drive and Dropbox. By hosting your own file storage solution, you can have complete control over your data, ensuring privacy and security. In this article, we will walk you through the step-by-step process of installing and configuring ownCloud on your Ubuntu 22.04 server.
Prerequisites
Before we dive into the installation process, let’s make sure we have everything we need. Here are the prerequisites for setting up ownCloud on your Ubuntu 22.04 server:
- An Ubuntu Server 22.04 edition.
- A non-root user with root administrator privileges.
- A domain name pointed and resolved to the server IP address.
Installing Dependencies
To ensure smooth installation, we need to install some basic package dependencies on our server. These packages include openssl, redis-server, smbclient, and more.
To update the Ubuntu repository to the latest version, run the following command:
sudo apt update
Once the repository is up to date, install the package dependencies using the following command:
sudo apt install smbclient redis-server unzip openssl rsync imagemagick
Installing PHP 7.4
ownCloud is mainly written in PHP, so we need to install PHP 7.4 on our Ubuntu server. While the latest version of Ubuntu 22.04 repository provides PHP 8.1 packages, ownCloud is currently not fully supported for PHP 8.1. Therefore, we’ll be installing PHP 7.4 from the third-party repository “ppa:ondrej/php”.
To add the PPA repository for PHP packages, run the following command:
sudo add-apt-repository ppa:ondrej/php -y
Next, install PHP 7.4 and other necessary PHP extensions using the following command:
sudo apt install php7.4 php7.4-intl php7.4-mysql php7.4-mbstring php7.4-imagick php7.4-igbinary php7.4-gmp php7.4-bcmath php7.4-curl php7.4-gd php7.4-zip php7.4-imap php7.4-ldap php7.4-bz2 php7.4-ssh2 php7.4-common php7.4-json php7.4-xml php7.4-dev php7.4-apcu php7.4-redis libsmbclient-dev php-pear php-phpseclib
After the installation is complete, set up PHP 7.4 as the default version on your system by running the following command:
sudo update-alternatives --config php
Select the number corresponding to PHP version 7.4 and hit Enter. Verify the PHP version by running the following command:
php --version
You should see that the default PHP version is now set to PHP 7.4.
Next, set up additional PHP tools for PHP 7.4 by running the following commands:
sudo update-alternatives --set phar /usr/bin/phar7.4 sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4 sudo update-alternatives --set phpize /usr/bin/phpize7.4 sudo update-alternatives --set php-config /usr/bin/php-config7.4
To ensure compatibility, upgrade PEAR to the latest stable version (v1.10.13) by following these steps:
Create a temporary directory called /tmp/pear/cache
using the following command:
sudo mkdir -p /tmp/pear/cache
Upgrade PEAR to version 1.10.13 by running the command below:
sudo pear upgrade --force --alldeps http://pear.php.net/get/PEAR-1.10.13
Clear the PEAR cache, update channels, and upgrade all by running the following commands:
sudo pear clear-cache sudo pear update-channels sudo pear upgrade --force sudo pear upgrade-all
Verify the PEAR version by running the following command:
pear version
You should see that PEAR has been upgraded to v1.10.13.
Installing Apache2 Web Server
Now, let’s install the Apache2 web server, which is required for hosting ownCloud. We’ll also enable the necessary Apache2 modules.
To install Apache2, run the following command:
sudo apt install libapache2-mod-php7.4 apache2
During the installation, you will be prompted to confirm. Press ‘Y’ and hit Enter to proceed.
Once the installation is complete, enable the required Apache2 modules by running the following command:
sudo a2enmod rewrite env dir mime unique_id headers ssl
To apply the changes, restart the Apache2 service:
sudo systemctl restart apache2
Installing MariaDB Server
Now, let’s install the MariaDB server, which will serve as the database backend for ownCloud. MariaDB is a popular choice for ownCloud and provides excellent compatibility with MySQL.
To install MariaDB, run the following command:
sudo apt install mariadb-server
During the installation, you will be prompted to confirm. Press ‘Y’ and hit Enter to proceed.
After the installation is complete, run the following command to set up and secure the MariaDB deployment:
sudo mysql_secure_installation
This command will guide you through a series of prompts to configure basic security settings for your MariaDB installation. It is recommended to set a strong root password, remove the anonymous user, disable remote login, and remove the test database.
Once you have completed the MariaDB server deployment, log in to the MariaDB shell by running the following command:
mysql -u root -p
Enter the root password you set during the secure installation process.
Next, create a new MariaDB database and user for ownCloud by running the following queries:
CREATE DATABASE owncloud; CREATE USER 'owncloud'@'localhost' IDENTIFIED BY 'owncloudpass'; GRANT ALL PRIVILEGES ON owncloud.* TO 'owncloud'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;
To verify the privileges for the MariaDB user ‘owncloud’, run the following query:
SHOW GRANTS FOR 'owncloud'@'localhost';
Make sure the ‘owncloud’ user has access and privileges to the ‘owncloud’ database.
Download ownCloud Source Code
With the LAMP stack and database ready, we can now download the ownCloud source code to our server.
Navigate to the /var/www/
directory by running the following command:
cd /var/www/
Use the wget
command to download the latest version of the ownCloud source code and the corresponding checksum file for verification:
wget https://download.owncloud.com/server/stable/owncloud-complete-latest.tar.bz2 wget https://download.owncloud.com/server/stable/owncloud-complete-latest.tar.bz2.sha256
Verify the integrity of the downloaded files by running the following command:
sudo sha256sum -c owncloud-complete-latest.tar.bz2.sha256 < owncloud-complete-latest.tar.bz2
If the verification is successful, you will see the message “owncloud-complete-latest.tar.bz2: OK”.
Extract the ownCloud source code by running the following command:
tar -xf owncloud-complete-latest.tar.bz2
This command will create a new directory named ‘owncloud’ in the ‘/var/www/’ directory. This directory will serve as the DocumentRoot/WebRoot for your ownCloud installation.
Finally, change the ownership of the ‘owncloud’ directory to ‘www-data’ using the following command:
sudo chown -R www-data:www-data owncloud
Setting Up Apache2 Virtual Host for ownCloud
To access ownCloud from a web browser, we need to set up an Apache2 virtual host that maps to the ‘owncloud’ directory. Let’s configure the virtual host for ownCloud using the domain name ‘example.io’ as an example.
Create a new virtual host configuration file called ‘owncloud.conf’ by running the following command:
sudo nano /etc/apache2/sites-available/owncloud.conf
Add the following Apache2 configuration to the file, making sure to replace ‘example.io’ with your own domain name:
<VirtualHost *:80>
ServerName example.io
ServerAlias www.example.io
Redirect permanent / https://example.io/
</VirtualHost>
<VirtualHost *:443>
ServerName example.io
DocumentRoot /var/www
ServerAlias www.example.io
Protocols h2 http:/1.1
<If "%{HTTP_HOST} == 'www.example.io'">
Redirect permanent / https://example.io/
</If>
ErrorLog ${APACHE_LOG_DIR}/example.io-error.log
CustomLog ${APACHE_LOG_DIR}/example.io-access.log combined
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/example.io/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.io/privkey.pem
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCompression off
Header always set Strict-Transport-Security "max-age=63072000"
Alias /owncloud "/var/www/owncloud/"
<Directory /var/www/owncloud/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/owncloud
SetEnv HTTP_HOME /var/www/owncloud
</Directory>
</VirtualHost>
Save and close the file when you are done.
Next, enable the virtual host configuration by running the following command:
sudo a2ensite owncloud.conf
To verify the Apache2 configuration, run the following command:
sudo apachectl configtest
If the configuration is correct, you will see the message “Syntax: OK”.
Finally, restart the Apache2 web server to apply the new virtual host configuration:
sudo systemctl restart apache2
Starting ownCloud Installation Wizard
With the virtual host set up, we are ready to start the ownCloud installation wizard. There are two ways to access the installation wizard: through a web browser or through the command line.
In this example, we will access the installation wizard through the command line.
Navigate to the ownCloud DocumentRoot directory by running the following command:
cd /var/www/owncloud
To complete the ownCloud installation, run the following command:
sudo -u www-data /var/www/owncloud/occ maintenance:install \ --database "mysql" \ --database-name "owncloud" \ --database-user "owncloud" \ --database-pass "owncloudpass" \ --admin-user "admin" \ --admin-pass "adminpassowncloud"
Make sure to replace the database details, admin user, and password with your own values.
Next, edit the ownCloud configuration file by running the following command:
sudo nano /var/www/owncloud/config/config.php
Add your ownCloud installation domain to the ‘trusted_domains’ configuration, as shown below:
'trusted_domains' => array (
0 => 'localhost',
1 => 'example.io',
),
Save and close the file when you are done.
Open your web browser and enter the domain name of your ownCloud installation (e.g., ‘https://example.io/owncloud/’) in the address bar. You should see the ownCloud login page.
Enter the admin username and password you set during the installation process and click ‘Login’.
If your credentials are correct, you will be taken to the ownCloud user dashboard, indicating a successful installation.
Performance Tuning for ownCloud
To optimize the performance of your ownCloud installation, there are a few additional configurations we can apply.
First, let’s set up the background jobs for ownCloud using cron. Run the following command:
sudo -u www-data /var/www/owncloud/occ background:cron
Next, create a new cron configuration for ownCloud by running the following command:
sudo crontab -u www-data -e
Add the following cron configuration to the file:
*/15****/ usr/bin/php -f /var/www/owncloud/occ system:cron
Save and close the file when you are done.
To enable caching in ownCloud, modify the ownCloud configuration file as follows:
sudo nano /var/www/owncloud/config/config.php
Add the following configuration to the file:
'filelocking.enabled' => true, 'memcache.local' => '\OC\Memcache\APCu', 'memcache.locking' => '\OC\Memcache\Redis', 'redis' => [ 'host' => 'localhost', 'port' => 6379, ],
Save and close the file when you are done.
To verify your configuration, go to the ‘Admin > Settings’ menu in the ownCloud dashboard. Under the ‘General’ section, check the ‘Security and setup warnings’. If you see a message stating “All checks passed”, your ownCloud installation and configuration are correct and complete.
Conclusion
Congratulations! You have successfully installed ownCloud on your Ubuntu 22.04 server. By following this comprehensive guide, you have learned how to set up the LAMP stack, install and configure ownCloud, and optimize its performance. With ownCloud, you can now host your own file-hosting service and have complete control over your data.
If you are looking for reliable cloud hosting solutions, consider Shape.host. With their Linux SSD VPS services, you can enjoy scalable and secure cloud hosting tailored to your needs. Shape.host provides efficient and reliable hosting solutions, empowering businesses with top-notch cloud infrastructure.