Showing posts with label Web. Show all posts
Showing posts with label Web. Show all posts

Nov 18, 2024

NextCloud Install in Ubuntu Server

NextCloud is an Open Source, Self-Hosted or Cloud Hosted, File Sync and Sharing Platform. It's Secure, Private and Easy to use. Compatible with Windows, Linux, Android and Apple iOS devices.

This is assuming that you already have Ubuntu Server installed, patched and updated.

1. Download the latest version of NextCloud.

sudo wget https://download.nextcloud.com/server/releases/latest.zip


2. Install some required packages.


sudo apt install libmagickcore-6.q16-6-extra php php-apcu php-bcmath php-cli php-common php-curl php-gd php-gmp php-imagick php-intl php-mbstring php-mysql php-zip php-xml -y



3. Install Marid DB Server.

sudo apt install mariadb-server -y


4. Secure Marid DB installation, follow on-screen prompt and instructions.

sudo mysql_secure_installation


5. Configure Maria DB Server.


CREATE DATABASE nextcloud;

SHOW DATABASES;

GRANT ALL PRIVILEGES ON nextcloud.* TO 'ncuser'@'localhost' IDENTIFIED BY 'ncpass';

FLUSH PRIVILEGES;

QUIT;



6. Enable PHP Modules.

sudo phpenmod apcu bcmath gmp imagick intl


7. Install Unzip Apps.

sudo apt install unzip -y


8. Unzip the downloaded NextCloud file.

sudo unzip latest.zip


9. Copy and Rename the extracted NextCloud folder.

sudo cp nextcloud demo.com


10. Move the renamed folder to Apache server path.

sudo mv demo.com /var/www/


11. Grant permissions to NextCloud folder.

sudo chwon -R www-data:www-data /var/www/demo.com


12. Create Apache configuration file for NextCloud.


<VirtualHost *:80>
   ServerAdmin webmaster@local.com
   ServerName demo.com
   DocumentRoot /var/www/demo.com

   <Directory /var/www/demo.com>
     Options MultiViews FollowSymlinks
     AllowOverride All
     Order allow,deny
     Allow from all
   </Directory>

   ErrorLog /var/log/apache2/demo.com/error.log
   TransferLog /var/log/apache2/demo.com/access.log

  <IfModule mod_headers.c>
     Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
   </IfModule>

</VirtualHost>



13. Configure and modify PHP file. Modify the value according to your requirements.


memory_limit = 512M

upload_max_filesize = 512M

max_execution_time = 360

post_max_size = 512M

date.timezone = Asia/Kuala_Lumpur

opcache.enable = 1

opcache.interned_strings_buffer = 16

opcache.max_accelerated_files = 10000

opcache.memory_consumption = 128

opcache.save_comments = 1

opcache.revalidate_freq = 1



14. Enabled Apache modules for NextCloud use.

sudo a2enmod dir env headers mime rewrite ssl


15. Enable APCU module in PHP.

sudo nano /etc/php/8.3/mods-available/apcu.ini

add the following line :-

apc.enable_cli = 1


16. Open your favorite browser, such as Google Chrome browser. And type the URL of NextCloud server (eg. http://demo.com). At the main screen, you need to configure the NextCloud Database (eg. nextcloud) created earlier including its username (eg. ncuser) & password (eg. ncpass). You also need to create the First Administrator account with a valid email address too.


17. NextCloud screen will auto refresh upon successful connection to the database, now login with the new administrator account created in earlier step.


18. Secure NextCloud with Let's Encrypt SSL.

sudo certbot --apache


19. Fix missing Indices in NextCloud.

sudo chmod +x /var/www/demo.com/occ

sudo /var/www/demo.com/occ db:add-missing-indices

sudo chmod -x /var/www/demo.com/occ


20. Change permissions of NextCloud config file.

sudo chmod 660 /var/www/demo.com/config/config.php

sudo chown root:www-data /var/www/demo.com/config/config.php


21. Modify NextCloud configuration file.

sudo nano /var/www/demo.com/config/config.php

Modify the following lines according to you needs :-


'memcache.local' => '\OC\Memcache\APCu',

'default_phone_region' => 'MY',

'maintenance_window_start' => 1,

'filelocking.enabled' => true,

'memcache.locking' => '\OC\MemCache\APCu',



22. Restart Apache server.

sudo systemctl restart apache2


23. Configure Crontab.

sudo crontab -u www-data -e

Add the following line :-

00 * * * 1 php -f /var/www/demo.com/cron.php



OPTIONAL STEPS

24. Remove Skeleton Files and Folders when User account is created.

sudo rm -R /var/www/demo.com/core/skeleton/Templates


25. Remove Work Flow Engine, to prevent User from installing WorkFlow.


sudo /var/www/demo.com/occ config:app:set workflowengine user_scope_disabled --value yes



26. Install "Redis" as MemCache for NextCloud.

sudo apt install redis php-redis -y

sudo systemctl enable redis

sudo systemctl start redis

sudo nano /var/www/demo.com/config/config.php


'memcache.local' => '\OC\Memcache\Redis',

'memcache.locking' => '\OC\Memcache\Redis',

'redis' => array(
     'host' => '/var/run/redis/redis.sock'.
     'port' => 0,
     'timemout' => 0.0,
     ),


sudo nano /etc/redis/redis.conf


unixsocket /var/run/redis/redis.sock

unixsocketperm 660


sudo usermod -aG redis www-data

sudo systemctl restart redis


27. If Redis is distributed, add following line into NextCloud config file :-

'memcache.distributed' => '\OC\Memcache\MemCached',


28. To clear all NextCloud log entries.

sudo -u www-data truncate /var/www/demo.com/data/nextcloud.log --size=0



!!! HAPPY COMPUTING !!!


Jan 25, 2024

Ubuntu : Apache 2 WebDAV with Directory List

At times, we need to serve some sort of file sharing over the Internet but instead of just grant the access anonymously, we need also to control who can access it. And also some SSL encryptions along the way.

The instructions herein are based on Ubuntu Server v.22.04.3 system, a TrueNAS Scale and all in the same VLAN.

The TrueNAS Scale server already have Samba Service (SMB) enabled with all the necessary credentials and folders permissions created.


1. As always, ensure the Ubuntu repositories are up-to-date. If there are "Kernel" update, a system restart is required.

sudo apt update && sudo apt upgrade -y



2. Next is to install Apache2 server.

sudo apt install apache2 -y



3. Now we need to create a folder to hold the website. Replace "demo.com.my" with your domain name. You can also a Dynamic DNS, ensure the DDNS is updated.

sudo mkdir /var/www/demo.com.my 



4. Next is to assign the proper ownership and access to the new folder. Replaced the text in "Red" accordingly.

sudo chown -R $USER:$USER /var/www/demo.com.my 


sudo chmod -R 755 /var/www/demo.com.my



5. For testing purposes, we need to create a temporary "index.html" file so that we can be sure the website is working as expected. Replaced the text in "Red" accordingly.

sudo nano /var/www/demo.com.my/index.html



6. Type-in the following scripts.

<html>
    <head>
        <title>WELCOME TO MY WEBSITE</title>
    </head>
    <body>
        <h1>MY WEBSITE IS WORKING !</h1>
    </body>
</html>


7. Next is to create apache's configuration file that correspond to the website. Replaced the text in "Red" accordingly.

sudo nano /etc/apache2/sites-available/demo.com.my.conf



8. Type-in the following configuration scripts. Replace text in "Red" accordingly.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName demo.com.my
    ServerAlias www.demo.com.my
    DocumentRoot /var/www/demo.com.my
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


9. Then we need to enable the new site. Replaced the text in "Red" accordingly.

sudo a2ensite demo.com.my.conf



10. Next is to disabled the "Default" site.

sudo a2dissite 000-default.conf



11. To ensure the configuration file is error free, perform a simple test. The result of the test return back should have "Syntax OK" displayed on the screen.

sudo apache2ctl configtest



12. Now, restart apache2 services.

sudo systemctl restart apache2



13. Next is to test whether the apache server is running correctly or not, open any preferred browser and browse to the URL. You will see the simple text word created earlier in the "index.html" file. Replaced the text in "Red" accordingly.

http://demo.com.my


In case, that the DNS is not up-to-date; you can use IP Address instead. Replaced the text in "Red" accordingly.

http://[IP Address]



13. In order for the server to access the TrueNAS Scale's SMB service, we need to install CIFS Utility.

sudo apt install cifs-utils -y



14. After installation complete, we now need to create a "Mount Point" or folder in the server first. Replaced the text in "Red" accordingly.

sudo mkdir /mnt/samba_share



15. Now, assuming that my TrueNAS Scale's IP Address is "192.168.0.2", where the intended share folder name is "Public", we need to manually mount the share to our local mount point. Replaced the text in "Red" accordingly.

sudo mount -t cifs //192.168.0.2/public -o username=demo_user /mnt/samba_share


You will be prompted for the password, type-in the password that corresponds to the credentials in TrueNAS Scale.


16. Next is to enabled the "WebDAV" module in Apache2 and restart the service.

sudo a2enmod dav

sudo a2enmod dav_fs


 sudo systemctl restart apache2



17. Grant the proper access permissions for apache to that folder. Replaced the text in "Red" accordingly.

 sudo chown www-data:www-data /mnt/samba_share



18. We need to create a folder location to store WedDAV's database file for storing username and password that have access to the webdav services.

 sudo mkdir -p /usr/local/apache/var



19. Now, we need to modify the configuration of the website to work with webdav. Replaced the text in "Red" accordingly.

DavLockDB /usr/local/apache/var/DavLock

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName demo.com.my
    ServerAlias www.demo.com.my
    DocumentRoot /var/www/demo.com.my
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /samba_share /mnt/samba_share

    <Directory /mnt/samba_share>
        Options Indexes
        DAV ON
        AuthType Digest
        AuthName "webdav"
        AuthUserFile /usr/local/apache/var/users.password
        Require valid-user
    </Directory>
</VirtualHost>


20. Verify the configurations and restart apache2 service.

sudo apache2ctl configtest


sudo systemctl restart apache2


21. Next is to create the WebDAV's database file for storing the username and password, the password is encrypted in the file.

sudo touch /usr/local/apache/var/users.password


22. Assign the proper ownership to the file.

sudo chown www-data:www-data /usr/local/apache/var/users.password


23. Next is to create the first user into the database. Replaced the text in "Red" accordingly

sudo htdigest -c /usr/local/apache/var/users.password webdav demo_user

Note :
(1) "webdav"     = Realm

You will be prompted to key-in a password for this username and re-confirm the password again. Ensure that both password matches exactly the same.


24. Now, we need to enable the Authentication Digest module in apache and restart the service.

sudo a2enmod auth_digest

sudo systemctl restart apache2


25. Once all done, we can test whether the WebDAV services is configured directly or not. Open any preferred browser and type-in the following URL. Replaced the text in "Red" accordingly

http://demo.com.my/samba_share

You should be prompted for a username and password, key-in the credentials we have created earlier for WebDAV services.


26. You might also want to configure the auto-mount for the samba services, after every-time the server restart. This step is OPTIONAL.

sudo nano /etc/fstab

Type-in the following configurations. Replaced the text in "Red" accordingly

//192.168.0.1/public /mnt/samba_share cifs username=demo_user,password=demo123 0 0


27. If you want to allow access from External Internet, it is advised to have SSL Certificate (Let's Encrypt) installed. Also ensure that your "Router" or "Firewall" have the appropriate port "Whitelisted" or enabled "Port Forwarding" accordingly. (eg. 443/TCP)

sudo apt install certbot python3-certbot-apache -y


28. Now request for a new SSL Certificate from Let's Encrypt.

sudo certbot --apache


29. You will be prompted for an email address, please ensure the email address you type-in is "VALID", this is to ensure you will receive email notification about the renewal of the SSL Certificate.

Also you must agreed to Let's Encrypt's Terms and Conditions of use, type-in "Y" to accept it.

You can also opt-in to their newsletter and marketing materials, but as this is a demo I have chosen "N" for this tutorials.


30. Next, you will prompted to select which domain you want to have the SSL certificate installed, in this case I will just select "demo.com.my" domain, but you can also do the same steps for "www.demo.com.my" too.


31. Once everything is completed, we need to restart apache2 services again.

sudo systemctl restart apache2


32. Now we can test the new SSL certificate, open your preferred browser and type-in the following URL. Take note now we are using "HTTPS" instead. Replaced the text in "Red" accordingly

https://demo.com.my/samba_share

And as expected, you should be prompted for a username and password to access the content.



!!! HAPPY COMPUTING !!!

Jan 18, 2024

Ubuntu : Web Server Directory Listing

 To enable directory listing for a web server.

1. sudo apt install nginx -y

2. sudo systemctl stop nginx

3. sudo nano /etc/nginx/sites-available/default
    --> #root /var/www/html;
    --> root /mnt/samba;
    --> location / {
            --> autoindex on;

4. sudo apt install cifs-utils -y

5. sudo mkdir /mnt/samba

6. sudo mount -t cifs //[IP Address]/[Folder Name] -o username=[SMB Username] /mnt/samba

7. Type-In the SMB Share Password when prompted.

8. sudo systemctl start nginx


To automatically mount the same smb share :-

9. sudo nano /etc/fstab
    --> //[IP Address]/[Folder Name] /mnt/samba cifs username=[SMB Username],password=[SMB Password] 0 0



!!! HAPPY COMPUTING !!!

Jun 22, 2023

Ubuntu : Apache2's Module - WebDAV

WebDAV (Web Distributed Authoring and Versioning) is a set of extensions to the HTTP (HyperText Transfer Protocol) which allows Users to collaboratively author contents directly in HTTP web server by providing facilities for concurrency control and namespace operations.

In this tutorial, we will focus on the Installation and Configuration of WebDAV via Ubuntu Server v.22.04.2 and Apache2 Web Server.

For more information on How-To install Ubuntu Server, please refer here (https://danielcheah.blogspot.com/2023/03/linux-install-ubuntu-server-v22041.html)

For more information on How-To install Apache2 Server, please refer here (https://danielcheah.blogspot.com/search/label/Apache)

1) Enabled Apache2's WebDAV module:

 sudo a2enmod dav


 sudo a2enmod dav_fs



2) Restart Apache2 service:

 sudo systemctl restart apache2



3) Create a new folder in Apache2:

 sudo mkdir /var/www/webdav



4) Change ownership for that new folder:

 sudo chown www-data:www-data /var/www/webdav



5) Create another new folder to store the WebDAV's DB file and change the ownership:

 sudo mkdir -p /usr/local/apache/var


 sudo chown www-data:www-data /usr/local/apache/var



6) Modify the Virtual Host file for the domain (eg. demo.gob.com.my):

 sudo nano /etc/apache2/sites-enabled/demo.gob.com.my.conf

* The file name depends on your domain name created during installation of Apache2.


7) Add the following content into the Virtual Host file as below, as per in "RED" text:
DavLockDB /usr/local/apache/var/DavLock

<VirtualHost *:80>
    ServerAdmin demo@localhost
    ServerName demo.gob.com.my
    ServerAlias www.demo.gob.com.my
    DocumentRoot /var/www/demo.gob.com.my
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /webdav /var/www/webdav

    <Directory /var/www/webdav>
        DAV ON
        AuthType Digest
        AuthName "webdav"
        AuthUserFile /usr/local/apache/var/users.password
        Require valid-user
    </Directory>

</VirtualHost>



8) Check the Apache2 configuration and restart the service:

 sudo apache2 configtest


 sudo systemctl restart apache2



9) Now we need to create a file to store all Username and change the ownership of the file:

 sudo touch /usr/local/apache/var/users.password


 sudo chown www-data:www-data /usr/local/apache/var/users.password



10) Create the first Username and its corresponding password:

 sudo htdigest -c /usr/local/apache/var/users.password webdav demo

* webdav --> Realm
* demo --> Username
* It will automatically prompt you to key-in the password for the new user.


11) Enable Apache2's Digest Authentication module:

 sudo a2enmod auth_digest



12) Restart Apache2 service:

 sudo systemctl restart apache2



13) Now create a dummy file for testing purposes and assign the appropriate ownership:

 sudo nano /var/www/webdav/testfile.txt

* Type some text into that file.

 sudo chown www-data:www-data /var/www/webdav/testfile.txt



14) To verify the connection, open any inter browser (eg. Google Chrome) and browse to (eg. http://demo.gob.com.my/webdav)

You should be prompted with a username and password, continue to key-in the username (eg. demo) and the password.

Upon successful login, you will able to view the dummy file created earlier and able to download/access the file accordingly as per below screenshot.


WebDAV Dummy File


15) You can also map a network drive by using the same URL / Path and with the same username and password.





!!! HAPPY COMPUTING !!!

Mar 24, 2023

Apache 2 Server : Installation in Ubuntu Server v.22.04.2

 Apache 2 Server Installation in Ubuntu Server v.22.04.2

1. Ensure Ubuntu repository is up-to-date.

sudo apt update && sudo apt upgrade -y

 

2. Install Apache 2 server.

sudo apt install apache2 -y

 

3. Double check UFW settings and configure to allow. Below is to list all "Allow" apps:-

sudo ufw app list

 This is to show UFW status.

sudo ufw status

 This command is to add "Apache2" into allow list

sudo ufw allow ‘Apache’

 

4. Create a virtual directory for Apache 2 server. Replace [Domain Name] with your actual domain name (eg. intranet.company.com)

sudo mkdir /var/www/[Domain Name]

 

5. Change the ownership of that folder.

sudo chown -R $USER:$USER /var/www/[Domain Name]

 

6. Change the mode of that folder.

sudo chmod -R 755 /var/www/[Domain Name]

 

7. Now create a temporary "index.html" file for testing of the new virtual directory.

sudo nano /var/www/[Domain Name]/index.html

 Copy the below code as an example then Save and Exit.

<html>

    <head>

        <title>WELCOME TO [DOMAIN NAME] !</title>

    </head>

    <body>

        <h1>SUCCESS ! THE [DOMAIN NAME] VIRTUAL HOST IS WORKING !</h1>

    </body>

</html>

 

8. Create a configuration for your virtual host.

sudo nano /etc/apache2/sites-available/[Domain Name].conf

 Copy the following code and then Save and Exit.

<VirtualHost *:80>

    ServerAdmin webmaster@localhost

    ServerName [Domain Name]

    ServerAlias www. [Domain Name]

    DocumentRoot /var/www/[Domain Name]

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

 

9. Enable the newly created site.

sudo a2ensite [Domain Name].conf

 

10. Disable the "Default" site.

sudo a2dissite 000-default.conf

 

11. Now test the configuration of the new site.

sudo apache2ctl configtest

 It should return --> "Syntax OK" message.


12. Restart the Apache service to take effect.

sudo systemctl restart apache2

 

13. Now open any browser and browse to the new site (eg. http://[Domain Name])


Edit: Added video for easy references.




!!! HAPPY COMPUTING !!!


Webmin : Installation in Ubuntu Server v.22.04.2

 Webmin as a Web GUI for Linux (https://webmin.com/) and have tons of functions and features, this is especially useful for Beginners IT Admin personnel.

Still it is recommended to use SSH to manage any Linux servers instead of GUI.


1. Ensure Ubuntu repository is up-to-date.

sudo apt update && sudo apt upgrade -y

 

2. Install the following pre-requisites.

sudo apt install wget curl nano net-tools gnupg1 -y

 

3. Next is to add Webmin's custom repository into Ubuntu's Apt Sources.

sudo nano /etc/apt/sources.list

 Add the following at the last line of the file and then Save and Exit.

deb http://download.webmin.com/download/repository sarge contrib

 

4. Then download and add Webmin's GPG key into sources.

sudo curl -o setup-repos.sh https://raw.githubusercontent.com/webmin/webmin/master/setup-repos.sh

 Run the script to update GPG key.

sudo sh setup-repos.sh

 

5. Run apt update again.

sudo apt update && sudo apt upgrade -y

 

6. Now you are ready to install Webmin.

sudo apt install webmin -y

 

7. Once installation completed, use any internet browser and open the following link. Replacing [Your IP Address] to match your server configurations.

https://[You IP Address]:10000

 

8. If you have UFW installed, you may need to add exceptions.

sudo ufw allow 10000

 

9. Do a server restart (optional) to ensure everything is loaded automatically at start.

sudo reboot

 

10. The Username and Password is the same you use to login to the server via SSH or Console.

More information and documentation is available at (http://doxfer.webmin.com/Webmin/Main_Page).


EDIT: 10-Apr-2023, Added video.




!!! HAPPY COMPUTING !!!