Introduction
In this tutorial, we will guide you through the process of installing Nextcloud on a VPS running Ubuntu 22.04. We will configure a full LAMP (Linux, Apache, MariaDB, PHP) stack and set up Nextcloud to work with these services.
Nextcloud is a powerful, open-source software that allows you to host your own cloud storage, giving you complete control over your data.
Prerequisites
Before we begin, make sure you have the following:
- A VPS running Ubuntu 22.04.
- Root or user with sudo privileges.
- A domain name (optional but recommended for SSL).
- Basic knowledge of the Linux terminal.
Step 1: Update and Upgrade Packages
First, let’s update the system to ensure all existing packages are up-to-date.
sudo apt update && sudo apt upgrade -y
Step 2: Install Apache
Next, we’ll install the Apache web server. Apache is one of the most popular web servers, and it’s required to serve the Nextcloud interface.
sudo apt install apache2 -y
Once installed, enable and start Apache:
sudo systemctl enable apache2
sudo systemctl start apache2
You can verify the status of Apache with:
sudo systemctl status apache2
Step 3: Install MariaDB
MariaDB is a popular database management system. We’ll use it to store Nextcloud’s data.
sudo apt install mariadb-server -y
After the installation, run the security script to improve MariaDB’s security:
sudo mysql_secure_installation
You’ll be asked to configure the root password and make other security changes. Follow the prompts to enhance the security of your database.
Step 4: Create a Database for Nextcloud
Log into the MariaDB shell:
sudo mysql -u root -p
Once inside, create a database and user for Nextcloud. Make sure to replace yourpassword with a strong password.
CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 5: Install PHP and Required Extensions
Nextcloud requires PHP along with several extensions. We will install PHP 8.1, which is supported by Ubuntu 22.04, and the necessary modules:
sudo apt install php libapache2-mod-php php-mysql php-xml php-gd php-curl php-zip php-mbstring php-intl php-bcmath php-gmp php-imagick -y
After installing PHP and its modules, adjust the Apache configuration to prioritize PHP files:
sudo nano /etc/apache2/mods-enabled/dir.conf
Make sure the index.php entry appears first:
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
Save and close the file, then restart Apache for the changes to take effect:
sudo systemctl restart apache2
Step 6: Download and Configure Nextcloud
Now, we will download the latest version of Nextcloud from their official website:
cd /var/www/
sudo wget https://download.nextcloud.com/server/releases/latest.zip
sudo unzip latest.zip
sudo mv nextcloud /var/www/html/
Set the appropriate permissions so Apache can access Nextcloud’s files:
sudo chown -R www-data:www-data /var/www/html/nextcloud
sudo chmod -R 755 /var/www/html/nextcloud
Step 7: Configure Apache for Nextcloud
Create a new Apache configuration file for Nextcloud:
sudo nano /etc/apache2/sites-available/nextcloud.conf
Add the following configuration:
<VirtualHost *:80>
ServerAdmin admin@yourdomain.com
DocumentRoot /var/www/html/nextcloud
ServerName yourdomain.com
ServerAlias www.yourdomain.com
<Directory /var/www/html/nextcloud/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and close the file, then enable the site and required Apache modules:
sudo a2ensite nextcloud.conf
sudo a2enmod rewrite headers env dir mime
Restart Apache to apply the changes:
sudo systemctl restart apache2
Step 8: Finalize the Nextcloud Installation
In your web browser, navigate to http://yourdomain.com or http://your-server-ip. You will be greeted by the Nextcloud setup page.
- Create an admin account.
- Enter the database details you configured earlier (database name:
nextcloud, user:nextclouduser, and password). - Finish the setup and log into Nextcloud.
Conclusion
You have successfully installed Nextcloud on your Ubuntu 22.04 VPS using Apache, MariaDB, and PHP. From here, you can further configure Nextcloud to meet your needs, such as enabling SSL with Let’s Encrypt or adding additional Nextcloud apps.
By hosting Nextcloud yourself, you gain full control over your data while leveraging the power of cloud storage solutions.