How to Install Nextcloud with Apache on Ubuntu 24.04
Installing Nextcloud with Apache on Ubuntu 24.04 gives you a private cloud storage server that keeps your files on your own hardware. Nextcloud is free software that works like a personal Dropbox. You store and share photos and documents from any phone or computer, and there is no monthly fee.
Apache is the web server that runs Nextcloud on Ubuntu 24.04 LTS (Noble Numbat). Together with MariaDB for the database and PHP for the code, it makes a fast, stable home server that you control. The guide goes in this order: Apache, MariaDB, the Nextcloud database, PHP, the Nextcloud files, the Apache virtual host, HTTPS with Let’s Encrypt, and the setup wizard.
You need an Ubuntu 24.04 server, a user account with sudo rights, and an internet connection. If the server runs a firewall, ports 80 and 443 must be open so you can reach the site from a browser.
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 the first piece to install. Update your package list first, then install Apache. Both steps happen in the terminal.
The two commands are sudo apt update followed by sudo apt install apache2. The first refreshes the list of available packages, and the second installs the web server.
Open the Ubuntu terminal and run the commands below to install the Apache web server. Type your sudo password if the system asks for it. Nothing shows on screen as you type it, which is normal. When the install finishes, you are back at the command prompt.
sudo apt update
sudo apt install apache2
Once Apache is installed, use the commands below to start it, stop it, and enable it so it starts automatically every time the server boots. Ubuntu usually starts Apache right after installation, but running the enable command makes sure it also comes back after a reboot.
sudo systemctl stop apache2
sudo systemctl start apache2
sudo systemctl enable apache2
Test that Apache is running by following these steps:
- Open a web browser on the server itself, or on another computer on the same network.
- Type the address of the server in the address bar. Use localhost if you are on the server, or the server's IP address if you are on another computer.
- Press Enter.
http://localhost

You should now see the Apache2 Default Page. That means the Apache HTTP server is installed and working. If the page does not load from another computer, check that Apache is running and that your firewall allows port 80.
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) holds everything Nextcloud needs to remember, such as user accounts, file records and settings. You install it from the terminal with the standard package commands.
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 so it starts automatically when the server boots. Without the enable step, Nextcloud would stop working after a reboot until you started the database by hand.
sudo systemctl stop mariadb sudo systemctl start mariadb sudo systemctl enable mariadb
Run the following commands to check that the MariaDB database server is installed and responding.
sudo mariadb
When you run the commands above, you are logged onto the MariaDB console and see 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)]>
This message tells you the server is installed and running. You can leave the console for now. You will come back to it in the next section.
Additional help on installing MariaDB.
- How to install MariaDB on Ubuntu Linux
- MariaDB without password prompt
Create a Nextcloud database
Nextcloud needs its own database and its own database user. You create both by logging into the MariaDB shell and running a few SQL commands. This keeps Nextcloud's data in a separate container named nextclouddb, managed by a dedicated user account called nextclouddbuser, instead of using the database administrator account.
As part of the setup, you will create a database named 'nextclouddb' and a corresponding user account called 'nextclouddbuser.'
Finally, you will grant nextclouddbuser full access to the nextclouddb database. That user only has rights on this one database.
You can do all of this with the commands below:
But first, log on to the MariaDB database server:
sudo mariadb
The prompt changes to the MariaDB prompt once you are logged in. 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
Replace 'type_your_password_here ' with your own password before you run the commands. Pick a strong one and write it down, because you enter it in the Nextcloud setup wizard later. Also check that the quotes and semicolons stay in place, since SQL needs them.
Install PHP on Ubuntu Linux
PHP (a scripting language that powers web applications) and its required modules must be installed so Nextcloud can run its server-side code. Nextcloud checks for these modules during setup, so a missing one shows up as an error in the wizard. The install command includes extensions such as php-intl and php-mysql, which Nextcloud needs.
Install PHP with the command below. It is one long command, so copy it whole.
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 comes from the official website as a compressed archive. You download it, extract it, and move the resulting folder into the Apache web root, then give the web server access to it.
Always check the download page for the latest release. Replace the download link in the commands below with the current one, so you install the latest version.
First, change to the /tmp/ directory and download the Nextcloud files. Then unzip the archive and move the contents into the Nextcloud folder in the Apache root directory.
The final step is to change the ownership and permissions. This lets the Apache web server read and write the Nextcloud files, which it must do to save uploads and update settings, and it keeps the setup secure. If the setup wizard later says it cannot write to the config or data folder, wrong permissions are the usual cause.
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 the files are in place, configure Apache to serve the Nextcloud content. Apache does this through a virtual host file, which tells it which site name to answer to and which folder to serve.
Run the commands below to create an Apache virtual host file for Nextcloud.
sudo nano /etc/apache2/sites-available/nextcloud.conf
The command opens an empty file in the editor. Copy and paste the content block below into it. Change the server name in the block to your own domain name or server IP address.
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 and close the editor.
Next, enable the virtual host and restart Apache using the commands below. Enabling the virtual host makes Apache aware of your Nextcloud site. Restarting Apache applies the new settings, so the Nextcloud site becomes reachable. If Apache fails to restart, recheck the virtual host file for typos first.
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) secure your Nextcloud connection with HTTPS. You get them with the Certbot tool. Certbot needs a real domain name that points to your server, because Let's Encrypt does not issue certificates for a bare IP address. Set up your domain first, then run Certbot in the terminal. It generates the certificate and applies it to Apache for you.
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 go to the server hostname or IP address that you set in the Apache virtual host file.
http://localhost/nextcloud
The Nextcloud installation wizard should appear. Fill it in like this:
- Create an administrator account name and a strong password.
- Enter the database name, database account name, and password you created earlier. The database name is nextclouddb, and the account name is nextclouddbuser.
- Click Install.
If the wizard reports a missing PHP module or a permissions error, fix that on the server and reload the page. The wizard is safe to run again.

When the install finishes, you land in Nextcloud and the site is ready to use. Log in with the administrator account you just created.

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 reach your Nextcloud installation through a custom domain name. It is optional. You need it if Nextcloud sits behind another server, for example a front-end proxy that handles several sites. In that case you edit the Apache virtual host configuration file so incoming web traffic is forwarded to the Nextcloud backend.
The links below should help you set that up.
That should do it!
Conclusion:
- In this 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.
- With the Apache web server running on Ubuntu, you have a stable and secure base for your own cloud hosting.
- The steps 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 gives you a solid foundation for your Nextcloud site, and the extra resources linked above help you customize and tune it further.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
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!