How to install and run ownCloud on Ubuntu 22.04?

Would you like to run your own cloud? Have you heard about ownCloud and do you feel ready to give it a try? How can you run your own ownCloud server on Ubuntu 22.04? Is it difficult? Not if you follow these instructions! Here I will take you through the necessary steps, and if you follow them, you will, hopefully, have your ownCloud server running in 15-20 minutes.

The most important thing you need is a computer or a VPS with Ubuntu 22.04 installed. If you use a VPS, it will run with Ubuntu 22.04 server, while a normal computer can come with the desktop version instead of the server version. This doesn’t really matter. But, all parts of this process will take part in the command line, so you better be prepared for that.

Don’t you have a place to run the ownCloud installation yet? If you are looking for a cheap, but good, VPS, I can warmly recommend one of the following options.

I have personal experience using both of these providers and I have no trouble recommending them at all. If you purchase a VPS from any of those, do not forget to choose Ubuntu 22.04 as your operating system. After you have placed your order, it normally takes 5-10 minutes before the server is ready and you can start. While waiting, download an SSH client to your computer as you will use it to communicate with the VPS. A great SSH client for such purposes is Putty.

We are ready to install ownCloud on Ubuntu 22.04!

We are now ready to start. Follow these commands, and you should be finished soon.

The first thing we do is to make sure that the system is up to date. It should be, but run this command at the start, just to be sure.

sudo apt-get update || sudo apt-get upgrade -y

In order to install and run ownCloud, you need to have several things installed on your server. Apache is the actual web server, but you also need to have PHP installed, and MySql. To get started, run the following command.

sudo apt-get install lamp-server^ -y

LAMP is an acronym for Linux, Apache, MySQL, PHP/Perl/Python, meaning that this is what is installed on your system in this process. Since you are installing quite a lot of things on your server right now, the command above might take some minutes to run.

When you are finished, run the following commands to start the web server.

sudo systemctl start apache2
sudo systemctl enable apache2

You know, right now your server is already up and running. If you visit the IP address of the server, you should now see the standard Apache site coming with a new installation of Apache.

apache server is running

As you can see above, the Apache server is already running.

All the users of ownCloud and other data will be stored in a MySQL database. In order to start the necessary processes, run the following commands.

 sudo systemctl start mysql
 sudo systemctl enable mysql
 sudo mysql_secure_installation

The last command will start the actual installation of MySQL. You will immediately be asked if you want to make sure that people use secure passwords or not. If you do not really care, you can answer No to the question. If you want to force people to use secure passwords, answer Yes to the question.

No matter what you answer, you will later have to type the root password for MySQL. Hopefully, everything will be fine, but it might be that you will see an error message like the one below. If you don’t see the error, just answer yes to the questions following the password request.

Error during mysql_secure_installation…

SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method used doesn't store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.
SET PASSWORD has no significance for user ‘root’@’localhost’ as the authentication method used doesn’t store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.

If you see the error message above, you should close the current terminal window and connect to the server once again. When you have returned, run the following commands. It is important that you are logged in as root for this to work.

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';
exit

Change the “mynewpassword” above to the password that you would like to use.

When this is done, run the mysql_secure_installation command once again.

sudo mysql_secure_installation

We are back on track…

Now you enter the root password that you want to use. After this, you will have to answer questions about whether to remove anonymous users, the test database, and more. By default, yes is a good answer to all the remaining questions.

Now it is time to get PHP up and running. It is important to know that ownCloud currently doesn’t work with PHP 8 (or PHP 8.1). This is actually causing some trouble because you will automatically install the newest version of PHP by running the default PHP installation commands. As a result, we need to type some other commands for this to work properly.

Installing PHP 7.4 on Ubuntu 22.04 for our ownCloud server.

To get the right version of PHP installed on our ownCloud server, run the following commands.

sudo add-apt-repository ppa:ondrej/php -y
sudo apt install php7.4
sudo apt install php7.4-{cli,common,curl,zip,gd,mysql,xml,mbstring,json,intl}

Since you installed the LAMP package at the start, you now have PHP 8.1 and PHP 7.4 installed on your system. As a default, the server will choose the newest version of PHP, and this will cause trouble for ownCloud. That is why we need to make some changes to make PHP 7.4 the standard version of PHP.

sudo update-alternatives --config php
php -v
change php version ubuntu

As you can see, the system chooses PHP 8.1 automatically. But, I then select option 1 (PHP 7.4). To check that the system now uses PHP 7.4 by default, I run the PHP -v command which now tells me that I am using PHP 7.4.32.

sudo systemctl restart apache2

Now it is time to create our MySQL database that will store the data. We also need to create a user for the database.

sudo mysql -u root -p
CREATE DATABASE ownclouddatabase;
CREATE USER 'myusername'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON ownclouddatabase.* to 'myusername'@'localhost';
FLUSH PRIVILEGES;
exit

You have now created the MySQL database, and you have created a user that has the right to work with the database. Now we only have to download and install ownCloud, and we are almost ready to go.

Time to download and install ownCloud on the Ubuntu 22.04 server

We are fully prepared right now. It is time to download the ownCloud package to our server.

wget https://download.owncloud.com/server/stable/owncloud-complete-latest.zip
sudo apt-get install unzip
unzip owncloud-complete-latest.zip

Right now, you have a big mess of files in your home directory. Let us move them to the directory in which we want to run the website.

 sudo mv owncloud /var/www/html/

Then we need to make sure that the right person and group has permission to modify the files in those directories.

 sudo chown -R www-data: /var/www/html/owncloud

The files are in place, the permissions are given. Now we just need to tell our Apache webserver to look in the right place for the website.

 sudo nano /etc/apache2/sites-available/owncloudserver.conf

This command will open an editor window. Here we have to add the configurations needed for Apache to find and to be able to operate our ownCloud server. Paste the following data into the ownCloud-server configuration file.

<VirtualHost \*:80>
     ServerAdmin [email protected]
     DocumentRoot /var/www/html/owncloud
     ServerName example.com
    <Directory /var/www/html/owncloud>
         Options FollowSymlinks
         AllowOverride All
         Require all granted
     </Directory>

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log

CustomLog ${APACHE_LOG_DIR}/your-domain.com_access.log combined

</VirtualHost>

You can close the editor window by hitting CTRL-X. You first have to confirm that you want to save the file by clicking Y, and then you are good to go.

sudo a2enmod rewrite mime unique_id
sudo a2dismod php8.1
sudo a2enmod php7.4
sudo systemctl restart apache2

Above I had to add a command to disable PHP 8.1 for Apache, as it still might use this as the default setting for a new Apache website. I then enable PHP 7.4 for the website. You might not need those commands at all, but you will most likely need them.

You are now ready to visit the ownCloud installation on your website. You can find it at youripaddress/owncloud.

setup owncloud on ubuntu server

First, you create an administrator login for your ownCloud interface.

administrator user owncloud

Further down, you will have to connect ownCloud to the MySQL database that we created earlier. Make sure to use the same username and password to whom we granted all privileges above.

connect owncloud to database

Things should work now and as you click Finish Setup, you will be ready to log in, use, and enjoy your installation of ownCloud.

If you end up seeing an error in this process saying something like this: “An exception occured in driver: SQLSTATE[HY000] [1044] Access denied“, take a break, and run the following commands.

sudo mysql -u root -p
grant all privileges on *.* to 'myusername'@'localhost' with grant option;
FLUSH PRIVILEGES;
exit
sudo systemctl restart apache2

Reload the ownCloud server website and give it a try again. You can now finish the process and enjoy your ownCloud installation.

owncloud installation is ready

It is brilliant that you can download your own ownCloud application to your Android phone and to your iOS device as well. That makes it really easy to access the cloud and enjoy the benefits of the cloud wherever you are in the world.

How to connect to your ownCloud from your mobile device?

It is easy to connect to your newly created ownCloud from your mobile device. You can download the ownCloud application from Google Play and from Apple Store. When you have installed the application, type the address of your ownCloud server. If it only runs with an IP address, make sure to add HTTP:// in front of the IP address. That’s it. You can then log in with your ownCloud user. It is possible to make the application automatically upload photos to the cloud and there are many other useful functions available as well.


Have you been able to install ownCloud on Ubuntu 22.04? I would love to hear from you!

I hope these instructions have helped you install and to set up ownCloud on your very own Ubuntu 22.04 server. If you are lucky, you have been able to solve all problems immediately by following these instructions. But, it might very well happen that you still meet errors or experience problems along the way. If you do, feel free to write a comment and let me hear from you.

Also, if you have followed these instructions and you have been successful, please let me know because it always makes me happy if people find the content I write useful and helpful!

Leave a Reply