install nginx nexcloud
# apt install nginx
# systemctl start nginx
# systemctl enable nginx
Verify the status of the Nginx service using systemctl status command:
# systemctl status nginx
Output:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running)
Docs: man:nginx(8)
Process: 1280 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1281 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 1304 (nginx)
Tasks: 2 (limit: 2273)
Memory: 1.7M
CPU: 23ms
CGroup: /system.slice/nginx.service
├─1304 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
└─1307 "nginx: worker process"
Install PHP and PHP extensions for Nextcloud
To install PHP and the necessary extensions, run the following command:
# apt install php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-intl php-curl php-xml php-mbstring php-bcmath php-gmp
Once the installation is complete verify if PHP is installed:
# php -v
Output:
PHP 8.2.7 (cli) (built: Jun 9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies
After installing all the packages, edit the php.ini file:
# nano /etc/php/8.2/fpm/php.ini
Change the following settings per your requirements:
memory_limit = 512M
upload_max_filesize = 128M
post_max_size = 128M
max_execution_time = 300
opcache.enable=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
Hapus apache
sudo apt remove --purge apache2 apache2-utils
sudo apt autoremove
install maria db sma dg yg lama
apt install mariadb-server mariadb-client
Verify the status of the MariaDB service using systemctl status command:
# systemctl status mariadb
Output:
● mariadb.service - MariaDB 10.11.3 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enabled)
Active: active (running)
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 14433 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 11 (limit: 2273)
Memory: 163.8M
CPU: 513ms
CGroup: /system.slice/mariadb.service
└─14433 /usr/sbin/mariadbd
Once the installation is complete, run the following command to secure your MariaDB server:
# mysql_secure_installation
Configure it like this:
- Set root password? [Y/n] Y
- 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
Restart the database server for the changes to take effect.
# systemctl restart mariadb
setup sma dg yg lama
Configure Nginx for Nextcloud
Run the commands below to create a new VirtualHost file called nextcloud in the /etc/nginx/conf.d/ directory.
# nano /etc/nginx/conf.d/nextcloud.conf
server {
listen 80;
server_name 192.168.1.105; # Ganti dengan domain atau IP Anda
root /var/www/html/nextcloud; # Sesuaikan dengan direktori instalasi Nextcloud
index index.php;
client_max_body_size 10G; # Batas unggah file maksimum
# Redirect untuk CardDAV dan CalDAV
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
# Rewrite semua permintaan ke index.php
location / {
rewrite ^ /index.php;
}
# Penanganan file PHP
location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; # Sesuaikan dengan PHP 8.2
fastcgi_read_timeout 3600;
}
# Penanganan file statis (CSS, JS, gambar, dll.)
location ~ \.(?:css|js|svg|gif|png|jpg|ico|woff2|ttf)$ {
try_files $uri /index.php$request_uri;
expires 6M;
access_log off;
}
# Blokir akses ke file .htaccess
location ~ /\.ht {
deny all;
}
}
sudo chown -R www-data:www-data /var/www/html/nextcloud/
sudo chmod -R 755 /var/www/html/nextcloud/
Uji konfigurasi Nginx:
Jika tidak ada kesalahan, restart Nginx:
Langkah 9: Optimasi Tambahan (Opsional)
- Caching : Aktifkan caching untuk meningkatkan performa Nextcloud. Anda dapat menggunakan Redis atau Memcached.
- Fail2Ban : Instal Fail2Ban untuk melindungi server dari serangan brute-force.
- Log Monitoring : Pantau log Nginx dan PHP-FPM untuk memastikan tidak ada kesalahan.