How to Install Nextcloud on CentOS 7
Nextcloud serves as a powerful alternative to OwnCloud, offering a secure, open-source file hosting platform.
This guide demonstrates how to install Nextcloud on a CentOS 7 server, optimized for enterprise hosting environments like centron.
Requirements
- A freshly deployed CentOS 7 server
- A sudo-enabled user account
Step 1: System Update
Connect to the server as a sudo user and apply all available updates:
sudo yum install epel-release -y
sudo yum update -y
sudo shutdown -r now
Once the reboot completes, log in again as the same user.
Step 2: Apache Installation
Set up Apache as your web server:
sudo yum install httpd -y
sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf
sudo sed -i 's/^/#&/g' /etc/httpd/conf.modules.d/00-dav.conf
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
Step 3: PHP and Extensions Installation
Install PHP 5.6 and its required modules via the IUS repository:
cd
wget https://centos7.iuscommunity.org/ius-release.rpm
sudo rpm -Uvh ius-release.rpm
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
To support larger file uploads (e.g., 50 MB), update PHP configuration:
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
sudo systemctl restart httpd.service
Step 4: MariaDB Setup
Install and configure MariaDB to serve as the database backend:
sudo yum install mariadb mariadb-server -y
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
sudo /usr/bin/mysql_secure_installation
Follow the prompts to set the root password and secure your installation. Then log into MariaDB:
mysql -u root -p
Create the Nextcloud database and user (replace values accordingly):
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: Download and Configure Nextcloud
Retrieve and unpack the Nextcloud archive:
cd
wget https://download.nextcloud.com/server/releases/nextcloud-9.0.53.zip
sudo yum install unzip -y
unzip nextcloud-9.0.53.zip
sudo mv nextcloud/* /var/www/html && sudo chown apache:apache -R /var/www/html
Install Nextcloud from the command line using your database and admin credentials:
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"
Step 6: Trusted Domains and File Permissions
Add trusted domains to the Nextcloud configuration:
sudo vi /var/www/html/config/config.php
Locate:
0 => 'localhost',
Append your server IP and domain:
1 => '203.0.113.1',
2 => 'www.example.com',
Save and exit the editor.
Step 7: Secure Permissions
Apply strict permissions to prevent 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
If you later create the /var/www/html/assets
directory, assign permissions accordingly:
sudo chown -R apache:apache /var/www/html/assets
For updates, temporarily change ownership:
sudo chown apache:apache -R /var/www/html
After updating, restore restrictive permissions.
Step 8: Firewall Rules and Service Reload
Enable HTTP and HTTPS traffic through the firewall and reload the service:
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --zone=public --permanent --add-service=https
sudo firewall-cmd --reload
sudo systemctl restart httpd.service
Conclusion
Your Nextcloud instance should now be accessible via http://203.0.113.1
. Use the administrator credentials to log in and start managing your file-sharing platform securely.