Nextcloud is a powerful open-source file sync and share software that allows you to store, share, and access your files from anywhere. In this tutorial, we will guide you through the process of setting up Nextcloud on Ubuntu 20.04 LTS.
Step 1: Install Ubuntu 20.04 LTS
First, you will need to install Ubuntu 20.04 LTS on your server. You can download the ISO file from the official Ubuntu website and follow the installation instructions.
Step 2: Update the system
Once you have installed Ubuntu 20.04 LTS, you should update the system to ensure that you have the latest security updates and packages. Open a terminal and run the following commands:
sudo apt update
sudo apt upgrade
Step 3: Install Apache web server
Nextcloud requires a web server to run. Apache is a popular web server that works well with Nextcloud. You can install Apache by running the following command:
sudo apt install apache2
Step 4: Install PHP and modules
Nextcloud is built using PHP, so you will need to install PHP and some PHP modules on your server. Run the following command to install PHP and the required modules:
sudo apt install php libapache2-mod-php php-mbstring php-xml php-gd php-curl php-zip
Step 5: Install MariaDB database server
Nextcloud uses a database to store its data. MariaDB is a popular open-source database server that works well with Nextcloud. You can install MariaDB by running the following command:
sudo apt install mariadb-server
During the installation process, you will be prompted to set a root password. Make sure to set a strong password and remember it.
Step 6: Configure MariaDB
Once MariaDB is installed, you will need to configure it by running the following command:
sudo mysql_secure_installation
Follow the on-screen instructions to secure your MariaDB installation.
Step 7: Create a database for Nextcloud
Next, you will need to create a database and user for Nextcloud in MariaDB. Log in to the MariaDB console by running the following command:
sudo mysql -u root -p
Enter the root password when prompted. Once you are in the MariaDB console, run the following commands to create a database and user for Nextcloud:
CREATE DATABASE nextcloud;
CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Make sure to replace ‘your_password’ with a strong password of your choice.
Step 8: Download and install Nextcloud
Next, you will need to download the latest version of Nextcloud from the official website. You can do this by running the following commands:
wget https://download.nextcloud.com/server/releases/nextcloud-23.0.0.zip
Unzip the downloaded file to the Apache web server’s root directory by running the following command:
sudo unzip nextcloud-23.0.0.zip -d /var/www/html/
Step 9: Configure Apache for Nextcloud
Next, you will need to create a virtual host file for Nextcloud in Apache. Create a new configuration file by running the following command:
sudo nano /etc/apache2/sites-available/nextcloud.conf
Add the following configuration to the file:
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/nextcloud/
ServerName example.com
<Directory /var/www/html/nextcloud/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
SetEnv HOME /var/www/html/nextcloud
SetEnv HTTP_HOME /var/www/html/nextcloud
</Directory>
ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined
</VirtualHost>
Save and close the file. Enable the virtual host by running the following command:
sudo a2ensite nextcloud.conf
Restart Apache to apply the changes:
sudo systemctl restart apache2
Step 10: Complete the Nextcloud setup
Access your Nextcloud installation by visiting the domain or IP address of your server in a web browser. You will see the Nextcloud setup page where you can enter the database details you created earlier, and create an admin account for Nextcloud.
Follow the on-screen instructions to complete the setup process. Once you have completed the setup, you will have a fully functional Nextcloud installation on your Ubuntu 20.04 LTS server.
That’s it! You have successfully set up Nextcloud on Ubuntu 20.04 LTS. You can now start using Nextcloud to store, share, and access your files from anywhere. If you encounter any issues during the setup process, refer to the official Nextcloud documentation for troubleshooting tips.
Thanks for the video. It is great. I know some Linux but not enough to be sufficient. But I think I can follow steps listed in the blog.
Having said that, I have also encountered some other Youtuber (e.g., Gary Explains) using snap as the package installation tool. And all he did, was just snapd nextcloud and the next thing he did, was pointing a web browser to the ip address of the machine and there NextCloud is already running and one can start configuring it or simply start using it. My guess is that all of those mariadb, apache2 etc. were installed as dependencies behind the scene.
My question to you is, what are the downside of doing that, instead of like going through dozens of commands you demo'ed? Esp. in the context of setting this up in a home machine without exposing to the internet? Thanks a lot!
22:57
Please do not use the MultiViews option here, it can lead to remote code execution. FollowSymlinks isn't as bad, but a symlink could be created access files outside of webroot, like /etc/passwd.
link doesn't work
This tutorial is amazing ! Thanks !
Are there any major differences between running bare metal vs docker?
Hello,
Could you please make a system installation video integrated with cloudflare zero tunnel on Ubuntu for a machine in our home?
Good intro!
Whats 127.0.1.1?
Thank you for your great work. I learned so much about Linux.
will this work on debian 12
Excellent video. It's not so often that I can follow a tutorial to install a piece of software, and exactly replicate on my machine. NOTE: ignore from 33:21 to 33:45 ('chown' command missing, but fixed right after). NOTE2: at 41:20, the occ command will fail (it does not show in the video). But the fix is right after.
I always use your tutorials when installing nextcloud! also always wondered why nextcloud comes installed with errors out of the box
chown php files as www-data is a no brainer, it's web security 101 negated 😞
Thank you so much for this, nextcloud install through truenas scale is such a pain to setup dns/vpn…
I cannot thank you enough for this fantastic tutorial. I now have NextCloud running on my own hardware at home and it's sensational.
Thanks, Jay Well Done
My server went down after a power outage. What command do I use to start nextcloud again after login?
Hands down the greatest NextCloud Tutorial of all time, finally got Nextcloud working in my Homelab after months of Trying. Also got it working on my Domain and able to access without Tailscale. Thanks heaps for such great content.
What if i don't have a domain and I do not want to expose nextcloud to the internet?
An excellent tutorial, as usual! I rarely find tutorials on YT as detailed and well explained.
Curious what you recommend for background jobs. I changed the owner of config.php to root like you did, but learned that the cron jobs must be executed by the same user that owns config.php. Is it safe to run cron.php as root if you need cron jobs for a larger instance, or is it better to keep config.php owned by www-data in that case? Thanks for everything!!