Linux tutorials

How to install Nextcloud with Nginx and MySQL

Install Nginx and MySQL

For Ubuntu:

 sudo apt-get update sudo apt-get install nginx mysql-server 

For CentOS:

sudo yum install nginx mysql-server

Create a database for Nextcloud

Connect to MySQL:

 mysql -u root -p 

Create a database and user:

 CREATE DATABASE nextcloud;<br />CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'secure_password';<br />GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';<br />FLUSH PRIVILEGES;<br />EXIT; 

3. Download and extract Nextcloud

Download the latest version of Nextcloud from

Extract the downloaded archive:

 tar xvf nextcloud-*.tar.bz2 

4. Configure Nginx for Nextcloud

Create a new Nginx server block:

 sudo nano /etc/nginx/sites-available/nextcloud 

Add the following configuration:

<br />server {<br />listen 80;<br />server_name;<br />return 301 https://$host$request_uri;<br />}</p><p>server {<br />listen 443 ssl;<br />server_name;</p><p>ssl_certificate /path/to/cert.pem;<br />ssl_certificate_key /path/to/cert.key;</p><p>root /var/www/nextcloud;<br />index index.php;</p><p>location = /favicon.ico {<br />log_not_found off;<br />access_log off;<br />}</p><p>location = /robots.txt {<br />allow all;<br />log_not_found off;<br />access_log off;<br />}</p><p>location / {<br />try_files $uri $uri/ /index.php?$args;<br />}</p><p>location ~ .php$ {<br />include fastcgi_params;<br />fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br />fastcgi_pass unix:/run/php/php7.4-fpm.sock;<br />fastcgi_read_timeout 3600s;<br />}</p><p>location ~* .(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {<br />expires 30d;<br />access_log off;<br />}<br />} 

Complete the Nextcloud installation through the web interface

Access Nextcloud in a web browser:

Follow the on-screen instructions to complete the setup.

Link the Nginx server block and restart Nginx

Link the server block to sites-enabled:

 sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/ 

Restart Nginx:

 sudo service nginx restart 

Leave a Reply

Your email address will not be published. Required fields are marked *