How to Install NextCloud with LAMP on CentOS Stream 9

NextCloud can be installed on a private home server or a virtual private server in the cloud. Files can then be uploaded and then synced to a local desktop, laptop, or even a smartphone. This way you have full control of your data.

Pre-requisites :

  • A system with CentOS Stream 9 installed and running.

  • root access to the system.

  • LAMP Stack installed and running, for this, you can refer to one of our guides on installing the LAMP Stack (Apache, MariaDB and PHP).

Once you're all set, we'll proceed with NextCloud installation and configuration.

Install Wget & Developer Tools

yum groupinstall "Development tools"

yum install wget

Disable SELinux

Next, let us disable SELinux. We are going to set SELinux to permissive. Edit this file:

vi /etc/selinux/config

Then update, Edit this line to permissive:


Download NextCloud

First, navigate to the /var/www/nextcloud directory as follows:

cd /var/www/nextcloud

Now, download the latest NextCloud archive from the official website of NextCloud with the following command:


Check for the latest version here : NextCloud Official.

Check for files with the following command.


Now, extract the NextCloud archive file with the following command:


Setting up FilePermission & Ownership

Now, change the owner and group of the nextcloud/ directory and its contents to apache as follows:

sudo chown -R apache nextcloud

Now, change the permission or the nextcloud/ directory and its content to 775 as follows:

chmod -Rf 755 nextcloud

For, some update needed 777.

chmod -Rf 777 nextcloud/sites/files

chcon -R -t httpd_sys_content_rw_t /var/www/nextcloud/

Nextcloud required a directory to keep its data. To create a data directory and set the proper permissions on the nextcloud directory

sudo mkdir -p /var/nextcloud/data

sudo chown -R apache: /var/www/nextcloud

sudo chmod -R 755 /var/nextcloud

We need PHP-ZIP Module to run NextCloud. Install it using the below code.

yum install php-zip

Enable Firewall if not already done.

firewall-cmd --permanent --zone=public --add-service=http

firewall-cmd --permanent --zone=public --add-service=https

sudo firewall-cmd --reload

Configuring Apache vHost

Create a new apache configuration file nextcloud.conf for NextCloud with the following command:

vi /etc/httpd/conf.d/nextcloud.conf

Add the following codes:

Alias /nextcloud "/var/www/nextcloud/"

<Directory /var/www/nextcloud/>
Options +FollowSymlinks
AllowOverride All

<IfModule mod_dav.c>
Dav off

SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud

Change with Your Domain Name. If you are using with IP, Please remove the entire server_name line.

Now, press the Esc key, and type in :wq! and press the Enter key to save and exit the file.

Now, restart & check the apache & PHP-FPM service with the following commands:

systemctl restart php-fpm

systemctl restart apache.service

Enable Firewall:

firewall-cmd --permanent --add-service=http

firewall-cmd --permanent --add-service=https

firewall-cmd --reload

Configuring Database

Now create a Database, User & Password for NextCloud:

Change strong_password to something more secure/unqiue when using it for your database password.

mysql -u root


CREATE USER 'username'@'localhost' IDENTIFIED BY 'strong_password';

GRANT ALL PRIVILEGES ON nextCloud.* TO 'username'@'localhost';



Configuring NextCloud

Now open the IP address from your browser, this will redirect you to configuring the final parts of the NextCloud installation.


Replace the IP_address with the actual IP of the server.

Input the Database details which was configured earlier.

Now you have successfully installed NextCloud with LAMP on your server.