How to Setup Remotely to Apache Server

Introduction

Remotely is a remote access and control program. You can setup your own server or use demo server to access and control other computers over internet.

About Remotely

Remotely was created by Translucency Software with the goal of making IT support tools that adhere to the following ideals:

  • IT shops should be able to decide if they want to host their own servers.
  • A remote console can be used to solve many problems without ever needing to inconvenience the user with full desktop control.
  • Remote support tools should allow technicians to accomplish tasks without an excessive amount of clicking and waiting for pages to load.

How It Works

The Remotely client has two parts: the service and the remote control. The service is responsible for maintaining a persistent connection to the server and executing remote commands. The remote control is launched as needed for remote control sessions.

Both applications make outgoing websocket connections over secure SSL/TLS protocol. Because the connections are outgoing, you don’t need to open any ports in your firewall, and the service won’t accept any incoming connections.

The Remotely service will register with your Remotely organization ID, which is generated when you create your account or join an existing organization. On the first connection, the service generates a separate unique ID and sends it to the server. Upon each subsequent connection, the server must send back that ID before anything else, or else the service will uninstall itself immediately. This is an additional layer of security that ensures the service is communicating with the original server.

Users and computers are grouped into an organization, and they can’t interact with resources outside their organization. Microsoft’s Identity framework is used for all login and authentication to verify users.

Prerequisites

In order to complete this tutorial, you will need to have an Ubuntu 18.04 server with a non-root sudo-enabled user account and a basic firewall.

Step 1 – Creating Domain and Setting Up Apache

A domain or a sub-domain must be setup to install Remotely. First define an A entry using your DNS server. This entry must redirect to server.

Then; you must define your Apache virtual host. To do this run command:

sudo nano /etc/apache2/sites-available/your_domain.conf

This command opens an editor window. Paste in the following configuration block, which is similar to the default, but update according to your own site. If you will not use SSL (that means https):

<VirtualHost *:80>
ServerAdmin your-email-address
ServerAlias your-domain-name
ServerName your-server-name
DocumentRoot directory-files-are-stored

#Forward once Websocket Connection has been upgraded.
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*)           ws://localhost:5000/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*)           http://localhost:5000/$1 [P,L]

ProxyPreserveHost On
#Proxy Requests to Remotely Server
<LocationMatch "/">
    ProxyPass http://localhost:5000/ 
    ProxyPassReverse http://localhost:5000/
</LocationMatch>
<Location "/BrowserHub">
    ProxyPass http://localhost:5000/
    ProxyPassReverse http://localhost:5000/
</Location>

<LocationMatch "/DeviceHub">
    ProxyPass http://localhost:5000/
    ProxyPassReverse http://localhost:5000/
</LocationMatch>

<LocationMatch "/RCBrowserHub">
    ProxyPass http://localhost:5000/
    ProxyPassReverse http://localhost:5000/
</LocationMatch>

<LocationMatch "/RCDeviceHub">
    ProxyPass http://localhost:5000/
    ProxyPassReverse http://localhost:5000/
</LocationMatch>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

This is for using SSL. Port 80 has been redirected to port 443. That means you will use https.

<VirtualHost *:80>
     ServerAdmin YourAdminMail #[email protected]
     ServerAlias YourRemotelySiteAddress #remotely.somesite.com
     ServerName YourServerName #somesite.com
     Redirect permanent / https://YourRemotelySiteAddress #https://remotely.somsite.com
</VirtualHost>

<VirtualHost *:443>
     ServerAdmin YourAdminMail
     ServerAlias YourRemotelySiteAddress
     ServerName YourServerName
     DocumentRoot YourRemotelySitePath #/var/www/remotely

# ##### Remotely Setup #####
#Forward once Websocket Connection has been upgraded.
   RewriteEngine On
   RewriteCond %{HTTP:Upgrade} =websocket [NC]
   RewriteRule /(.*)           ws://localhost:5000/$1 [P,L]
   RewriteCond %{HTTP:Upgrade} !=websocket [NC]
   RewriteRule /(.*)           http://localhost:5000/$1 [P,L]

   ProxyPreserveHost On
   #Proxy Requests to Remotely Server
   <LocationMatch "/">
	ProxyPass http://localhost:5000/ 
	ProxyPassReverse http://localhost:5000/
   </LocationMatch>
   <Location "/BrowserHub">
	ProxyPass http://localhost:5000/
	ProxyPassReverse http://localhost:5000/
   </Location>

   <LocationMatch "/DeviceHub">
	ProxyPass http://localhost:5000/
	ProxyPassReverse http://localhost:5000/
   </LocationMatch>

   <LocationMatch "/RCBrowserHub">
	ProxyPass http://localhost:5000/
	ProxyPassReverse http://localhost:5000/
   </LocationMatch>

   <LocationMatch "/RCDeviceHub">
	ProxyPass http://localhost:5000/
	ProxyPassReverse http://localhost:5000/
   </LocationMatch>
# ##### End of Remotely Setup #####

   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

#If you use Let'sEncrypt; Let'sEncrypt will add some code here.

When you are finished, save and close the file by pressing CTRL+X. Confirm the save by typing Y and then hit ENTER to verify the file save location.

Notice that we’ve updated the DocumentRoot to our new directory and ServerAdmin to an email that the your_domain site administrator can access. We’ve also added two directives: ServerName, which establishes the base domain that should match for this virtual host definition, and ServerAlias, which defines further names that should match as if they were the base name.

Save and close the file when you are finished.

Let’s enable the file with the a2ensite tool:

sudo a2ensite your_domain.conf

Next, let’s test for configuration errors:

sudo apache2ctl configtest

You should see the following output:

Syntax OK

Restart Apache to implement your changes:

sudo systemctl restart apache2

We must enable proxy_http module to run Remotely. Run command;

sudo a2enmod proxy_http

Now we finished our Apache setup. So we can move on to Remotely setup.

Step 2 – Setting Up Remotely

Copy below code to a new text file. Run command;

sudo nano Install_Remotely.sh

Paste below code to this text file.

#!/bin/bash
echo "Thanks for trying Remotely!  If you have any questions, feel free to email me at [email protected]"
echo

read -p "Enter path where the Remotely server files should be installed (typically /var/www/remotely): " appRoot

if [ -z "$appRoot" ]; then
    appRoot="/var/www/remotely"
fi

read -p "Enter server host (e.g. remotely.alpaslan.tk): " serverHost

UbuntuVersion=$(lsb_release -r -s)

apt-get update

# Install .NET Core Runtime.
wget -q https://packages.microsoft.com/config/ubuntu/$UbuntuVersion/packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
add-apt-repository universe
apt-get -y install apt-transport-https
apt-get update
apt-get -y install aspnetcore-runtime-3.1
rm packages-microsoft-prod.deb

# Install other prerequisites. You must install unzip. It is necessary to unzip Remotely files to your server. Acl, ffmpeg, libc6-dev, libgdiplus adds properties to Remotely.
apt-get -y install unzip
apt-get -y install acl
apt-get -y install ffmpeg
apt-get -y install libc6-dev
apt-get -y install libgdiplus

# Download and install Remotely files.
mkdir -p $appRoot
wget "https://github.com/Jay-Rad/Remotely/releases/latest/download/Remotely_Server_Linux-x64.zip"
unzip -o Remotely_Server_Linux-x64.zip -d $appRoot
rm Remotely_Server_Linux-x64.zip
setfacl -R -m u:www-data:rwx $appRoot
chown -R www-data:www-data $appRoot

# Create service.

serviceConfig="[Unit]
Description=Remotely Server

[Service]
WorkingDirectory=$appRoot
ExecStart=/usr/bin/dotnet $appRoot/Remotely_Server.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
SyslogIdentifier=remotely
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target"

echo "$serviceConfig" > /etc/systemd/system/remotely.service

# Enable service.
systemctl enable remotely.service
# Start service.
systemctl restart remotely.service

When you are finished, save and close the file by pressing CTRL+X. Confirm the save by typing Y and then hit ENTER to verify the file save location.

We must run this file to setup Remotely. However this is a text file. We must make this file aas executable. Run this command:

sudo chmod +x Install_Remotely.sh

Now run this file to setup Remotely by typing and hitting ENTER.

sudo ./Install_Remotely.sh

Follow screen and give necessary answers to command. Then if you are successful and if you want to use SSL run this command:

certbot –apache -d your_domain

This completes Remotely setup. Open a browser page and go to your-domain. Test and use.

Some tutorial videos can be accessed from Remotely web site.

Be close to hapiness.