Nextcloud Configuration for Lighttpd

Prerequisites

Before starting, ensure you have the following software installed on your server:

  • Lighttpd
  • PHP and necessary modules
  • MariaDB (or MySQL)

Install Lighttpd

sudo apt update
sudo apt install lighttpd        

Install PHP and Necessary Modules

sudo apt install php-cgi php-cli php-fpm php-curl php-gd php-intl php-json php-mbstring php-mysql php-xml php-zip php-apcu php-redis php-imagick        

Install MariaDB (or MySQL)

sudo apt install mariadb-server mariadb-client        

Download and Extract Nextcloud

Download the latest Nextcloud server package from Nextcloud’s download page.

tar -xjf nextcloud-x.y.z.tar.bz2
sudo mv nextcloud /var/www/

Database Setup

Secure MariaDB Installation

sudo mysql_secure_installation

Create a Nextcloud Database and User

sudo mysql -u root -p
CREATE DATABASE nextcloud;
CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost';
FLUSH PRIVILEGES;
EXIT;        

Lighttpd Configuration

Enable Necessary Modules


sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php
sudo lighty-enable-mod rewrite
sudo systemctl restart lighttpd
        

Configure Lighttpd for Nextcloud

Edit the Lighttpd configuration file:


sudo nano /etc/lighttpd/lighttpd.conf
        

Add the following configuration:


server.modules += ( "mod_accesslog", "mod_rewrite", "mod_setenv" )

server.document-root        = "/var/www/nextcloud"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
accesslog.filename          = "/var/log/lighttpd/access.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80

index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

fastcgi.server = ( ".php" =>
    ( "localhost" =>
        (
            "socket" => "/var/run/lighttpd/php.socket",
            "bin-path" => "/usr/bin/php-cgi"
        )
    )
)

setenv.add-response-header = (
    "X-Content-Type-Options" => "nosniff",
    "X-XSS-Protection" => "1; mode=block",
    "X-Robots-Tag" => "none",
    "X-Download-Options" => "noopen",
    "X-Permitted-Cross-Domain-Policies" => "none"
)

$HTTP["url"] =~ "^/data/" {
    url.access-deny = ("")
}

$HTTP["url"] =~ "^($|/)" {
    url.rewrite-once = (
        "^($|/)$" => "/index.php$1"
    )
}

$HTTP["url"] =~ "^/\.well-known/(card|cal)dav" {
    url.rewrite-once = (
        "^/\.well-known/(card|cal)dav" => "/remote.php/dav/"
    )
}

$HTTP["url"] =~ "^/\.well-known/(webfinger|nodeinfo)" {
    url.rewrite-once = (
        "^/\.well-known/(webfinger|nodeinfo)" => "/index.php/.well-known/$1"
    )
}
        

Set Permissions


sudo chown -R www-data:www-data /var/www/nextcloud/
sudo chmod -R 755 /var/www/nextcloud/
        

Finalizing Installation

Access Nextcloud Web Installer

Open a web browser and go to http://your_server_ip/ to complete the installation via the web interface.

Follow the On-screen Instructions

  • Enter your database details.
  • Create an admin account.
  • Complete the setup.

Secure Your Nextcloud Instance (Optional but Recommended)

  • Consider setting up HTTPS using Let’s Encrypt.
  • Enable and configure a firewall.

By following these steps, you should have a functional Nextcloud installation running on Lighttpd.

 

Similar Posts

Leave a Reply

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