How to install Nextcloud with Apache on Ubuntu 24.04
Installing Nextcloud with Apache on Ubuntu 24.04 creates a private cloud storage server to keep your files safe on your own hardware. Nextcloud is free software that acts like a personal Dropbox, letting you store and share photos and documents from any phone or computer without paying a monthly fee.
Apache works as the web server to run Nextcloud smoothly on Ubuntu 24.04 LTS (Noble Numbat). Setting up both tools gives you a fast and stable home server that you fully control.
Install Apache and MariaDB using `sudo apt install apache2 mariadb-server`. Then create a Nextcloud database and user within MariaDB. Finally, install PHP with `sudo apt install php libapache2-mod-php php-`.
Install Apache HTTP server on Ubuntu
Apache HTTP server (a web server application used to serve web pages) is installed on Ubuntu 24.04 by updating your package list and running the default installation command in the terminal. Open your terminal and run sudo apt update followed by sudo apt install apache2 to get the web server running on your system.
To do that, open the Ubuntu terminal and run the commands below to install the Apache web server.
sudo apt update
sudo apt install apache2
Once Apache is installed, the commands below can start, stop, and enable the Apache web server to start automatically when your server boots up.
sudo systemctl stop apache2
sudo systemctl start apache2
sudo systemctl enable apache2
You can test that the Apache web server is running by opening your web browser and browsing to the server’s localhost or IP address.
http://localhost

When you see the Apache2 Default Page, it means the Apache HTTP server is successfully installed.
Additional help on installing Apache on Ubuntu is in the link below.
Install MariaDB database server on Ubuntu Linux
MariaDB database server (an open-source database management system that stores application data) is installed on Ubuntu 24.04 through the terminal to handle your Nextcloud data storage needs. Open the Ubuntu terminal and run the standard package installation commands to download and set up the database server on your machine.
To install and use the MariaDB database server, use the instructions below.
Open the Ubuntu terminal and run the commands below to install the MariaDB database server.
sudo apt update sudo apt install mariadb-server
Once the MariaDB database server is installed, use the commands below to stop, start, and enable the MariaDB server to start automatically when the server boots.
sudo systemctl stop mariadb sudo systemctl start mariadb sudo systemctl enable mariadb
Run the following commands to validate and test if the MariaDB database server is installed successfully.
sudo mariadb
Once you run the commands above, it will log you onto the MariaDB console and display a message similar to the one below.
Welcome to the MariaDB monitor. Commands end with ; or g. Your MariaDB connection id is 32 Server version: 10.11.2-MariaDB-1 Ubuntu 23.04 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. MariaDB [(none)]>
The message tells you that the server is installed successfully.
Additional help on installing MariaDB.
- How to install MariaDB on Ubuntu Linux
- MariaDB without password prompt
Create a Nextcloud database
Nextcloud database creation requires logging into your MariaDB shell and running SQL commands to set up a dedicated database and user account. This process establishes a secure container named nextclouddb along with a designated user account called nextclouddbuser to manage your stored files and settings.
As part of the setup, we will create a database named 'nextclouddb' and a corresponding user account called 'nextclouddbuser.'
Finally, we'll grant the nextclouddbuser full access to the nextclouddb database.
All the database steps above can be done using the commands below:
But first, log on to the MariaDB database server:
sudo mariadb
Then run the commands below to complete the steps:
CREATE DATABASE nextclouddb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER nextclouddbuser@localhost IDENTIFIED BY 'type_your_password_here';
GRANT ALL ON nextclouddb.* TO nextclouddbuser@localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
Install PHP on Ubuntu Linux
PHP (a scripting language that powers web applications) and its required modules must be installed on your Ubuntu 24.04 system so Nextcloud can process server-side code properly. Run the apt install command in your terminal with the necessary PHP extensions like php-intl and php-mysql to make sure Nextcloud runs without errors.
Then, install PHP using the command below.
sudo apt install php libapache2-mod-php php-intl php-mysql php-curl php-cli php-zip php-xml php-gd php-gmp php-common php-mbstring php-xmlrpc php-json php-sqlite3 php-ldap php-imap php-pgsql php-ssh2 php-soap php-zip
Additional help on installing PHP
Download Nextcloud files
Nextcloud installation files are downloaded directly from the official website as a compressed archive that you extract and move into your web server directory. Grab the latest release package from the official source, unpack the archive, and place the resulting folder into the correct Apache document root on your Ubuntu system.
Replace the download link below with the current so you have the latest version.
First, navigate to the /tmp/ directory and download Nextcloud files. After unzipping the file, move the content into the Nextcloud folder in the Apache root directory.
The final step is to change the permissions. This will allow the Apache web server to safely interact with the files, ensuring a secure environment for your Nextcloud installation.
wget https://download.nextcloud.com/server/releases/latest.zip -P /tmp
sudo unzip /tmp/latest.zip -d /var/www
sudo chown -R www-data:www-data /var/www/nextcloud/
Once all the steps are done, configure the Apache webserver to serve the Nextcloud content.
Run the commands below to create an Apache virtual host file for Nextcloud.
sudo nano /etc/apache2/sites-available/nextcloud.conf
Then, copy and paste the content block below into the Apache server block.
Alias /nextcloud "/var/www/nextcloud/"
<Directory /var/www/nextcloud/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud
</Directory>
Save the file.
You enable the virtual host and restart the Apache server by running specific commands. Enabling the virtual host makes Apache aware of your Nextcloud site, and restarting Apache applies these new settings so that your Nextcloud installation becomes accessible.
sudo a2ensite nextcloud.conf
sudo a2enmod env rewrite dir mime headers setenvif ssl
sudo systemctl restart apache2
Setup Let's Encrypt SSL/TLS for Nextcloud
Let's Encrypt SSL/TLS certificates (free digital certificates that encrypt web traffic between your server and visitors) are set up on Apache using the Certbot tool to secure your Nextcloud connection with HTTPS. Configure your domain and run the Certbot utility in the terminal to generate and apply your security certificates automatically.
Please read the post below for additional resources on installing and creating Let's Encrypt SSL certificates for Apache.
How to set up Let's Encrypt SSL certificate for Apache on Ubuntu Linux
Once you have restarted the Apache web server, open your browser and browse to the server hostname or IP address defined in the Apache server block.
http://localhost/nextcloud
A Nextcloud installation wizard page should appear. Create an administrator account and password, enter the database name, database account name, and password created above, and click Install.

Your Nextcloud site should be ready to use.

Set up a reverse proxy for Nextcloud
Apache reverse proxy configuration (a setup where a server intercepts client requests and forwards them to a backend application) lets you access your Nextcloud installation using a custom domain name. Edit your Apache virtual host configuration file to forward incoming web traffic correctly to your local Nextcloud application backend.
The links below should help you set that up.
That should do it!
Conclusion:
- In this comprehensive guide, you learned how to install Nextcloud with Apache support on Ubuntu 24.04, setting up a reliable platform for hosting cloud storage and collaboration services.
- By leveraging the stability and security of the Apache web server and the robustness of Ubuntu as the operating system, you've ensured a reliable cloud hosting solution.
- The step-by-step instructions covered the installation of the Apache HTTP server, MariaDB database server, PHP, and Nextcloud files, the setup of Let's Encrypt SSL/TLS, and the option to configure a reverse proxy for Nextcloud using Nginx or Apache.
- This guide provides a solid foundation for creating your Nextcloud site and offers additional resources for further customization and optimization of your setup.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!