How to Install Nextcloud on a CentOS 7 Server at centron
Nextcloud, true to its name, is a strong alternative to the open-source file hosting platform ownCloud.
In this guide, you will learn how to deploy Nextcloud on a centron CentOS 7 server instance.
Prerequisites
- A freshly provisioned centron CentOS 7 server instance.
- A sudo-enabled user account for logging in.
Step 1: Update the System
Sign in to your CentOS 7 machine using your sudo user, then bring the system up to the latest stable packages:
sudo yum install epel-release -y
sudo yum update -y
sudo shutdown -r now
Once the server has rebooted, log in again with the same sudo user.
Step 2: Install Apache
Set up Apache as the web server that will run Nextcloud:
sudo yum install httpd -y
Turn off the default Apache welcome page:
sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf
For better security, stop Apache from listing directory contents under the web root /var/www/html:
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf
As required by Nextcloud, block Apache from loading WebDAV modules:
sudo sed -i 's/^/#&/g' /etc/httpd/conf.modules.d/00-dav.conf
Start Apache now and enable it to launch automatically after boot:
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
Step 3: Install PHP and Required PHP Extensions
Nextcloud recommends PHP 5.6. You can install PHP 5.6 and the needed extensions by using the IUS YUM repository.
First, add the IUS YUM repository:
cd
wget https://centos7.iuscommunity.org/ius-release.rpm
sudo rpm -Uvh ius-release.rpm
Next, install PHP 5.6 along with all required extensions from IUS:
sudo yum install php56u php56u-common php56u-xml php56u-gd php56u-mbstring php56u-process php56u-mysqlnd php56u-intl php56u-mcrypt php56u-imap php56u-cli -y
Raise the PHP upload limits to a suitable value, for example 50 MB:
sudo cp /etc/php.ini /etc/php.ini.bak
sudo sed -i "s/post_max_size = 8M/post_max_size = 50M/" /etc/php.ini
sudo sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 50M/" /etc/php.ini
Restart Apache so these settings take effect:
sudo systemctl restart httpd.service
Step 4: Install MariaDB and Create a Nextcloud Database
Install MariaDB:
sudo yum install mariadb mariadb-server -y
Start MariaDB and configure it to run on boot:
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
Harden the MariaDB installation:
sudo /usr/bin/mysql_secure_installation
When prompted, respond as follows:
- Enter current password for root (enter for none): Enter
- Set root password? [Y/n]: Y
- New password: <your-password>
- Re-enter new password: <your-password>
- Remove anonymous users? [Y/n]: Y
- Disallow root login remotely? [Y/n]: Y
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y
Now create a dedicated database for Nextcloud:
mysql -u root -p
Type the MariaDB root password you just set to enter the MySQL shell.
Inside the shell, create the database and user, then grant permissions. Replace the database name nextcloud, username nextclouduser, and password yourpassword everywhere with your own choices:
CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
Step 5: Install Nextcloud
Fetch the latest stable Nextcloud release from the official site. At the time this was written, the newest stable version was 9.0.53.
cd
wget https://download.nextcloud.com/server/releases/nextcloud-9.0.53.zip
Unpack the Nextcloud archive:
sudo yum install unzip -y
unzip nextcloud-9.0.53.zip
Move Nextcloud into the web root and assign correct ownership:
sudo mv nextcloud/* /var/www/html && sudo chown apache:apache -R /var/www/html
Install Nextcloud using the command line with the sample values below. Be sure to substitute your real settings.
- database-name: nextcloud
- database-user: nextclouduser
- database-pass: yourpassword
- admin-user: admin
- admin-pass nextcloudadminpassword
Run:
cd /var/www/html/
sudo -u apache php occ maintenance:install --database "mysql" --database-name "nextcloud" --database-user "nextclouduser" --database-pass "yourpassword" --admin-user "admin" --admin-pass "nextcloudadminpassword"
If the installation completes successfully, you will see output like:
Nextcloud is not installed - only a limited number of commands are available
ownCloud was successfully installed
Add your server IP (for example 203.0.113.1) and domain (for example www.example.com) to the trusted domains list:
sudo vi /var/www/html/config/config.php
Locate this line:
0 => 'localhost',
Directly beneath it, add these two lines:
1 => '203.0.113.1',
2 => 'www.example.com',
Save and exit the editor:
:wq!
After installation, apply strong permissions to Nextcloud files and folders to avoid unauthorized access:
sudo find /var/www/html -type f -print0 | sudo xargs -0 chmod 0640
sudo find /var/www/html -type d -print0 | sudo xargs -0 chmod 0750
sudo chown -R root:apache /var/www/html
sudo chown -R apache:apache /var/www/html/apps
sudo chown -R apache:apache /var/www/html/config
sudo chown -R apache:apache /var/www/html/data
sudo chown -R apache:apache /var/www/html/themes
sudo chown -R apache:apache /var/www/html/updater
sudo chmod 0644 /var/www/html/.htaccess
sudo chown root:apache /var/www/html/.htaccess
sudo chmod 0644 /var/www/html/data/.htaccess
sudo chown root:apache /var/www/html/data/.htaccess
Also note that the directory /var/www/html/assets does not exist yet. If you create it later, run:
sudo chown -R apache:apache /var/www/html/assets
These permission rules help protect Nextcloud from unauthorized access.
Note: When you update Nextcloud later, you may temporarily relax permissions with:
sudo chown apache:apache -R /var/www/html
After updating, reapply the strong permissions listed above.
Restart Apache to enable all changes:
sudo systemctl restart httpd.service
Adjust firewall settings to permit HTTP and HTTPS traffic:
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --zone=public --permanent --add-service=https
sudo firewall-cmd --reload
Done. You can now open your browser to http://203.0.113.1 and sign in using the Nextcloud admin credentials you created.


