SWebApps / Node.js

This tutorial will show you how to create a simple “Hello World” web app using Node.js.

If you do not have a Web Apps section in your hosting Control Panel, then this tutorial is not suitable for your particular hosting environment. You can ask your hosting provider for more information, or you can seek assistance through our ticketing system.

1. The first step is to create a directory for the app in the Private directory on your account. The web apps can only be deployed in directories in the private directory on the account. We recommend creating a separate directory there for the app to avoid mixing its contents with other apps or other files in the private directory. You can create the directory using the File Manager in your hosting Control Panel. 

2. Create the app using the Web Apps section of the hosting Control Panel.

  • Choose Node.js as Engine and Current as Version. This will automatically update your Node.js version as soon as a new one is available on the server. 
  • Enter a name for your app. It is only for internal reference to the app. In this example, it is app_name.
  • Choose the subdomain you wish to access it at.
  • Enter the web access path. For example, if you enter /app_name, you will be able to access the app at http://subdomain.domain.com/app_name. You do not need to create the directory. 
  • The port will be assigned automatically and displayed in the app list.
  • Select the deployment directory by entering the directory you created in step 1.
  • Enter the start command of your app. In this example, it will be node app.js.

Web Apps

3. Create a file named app.js in the directory from step 1, and place the “Hello World” app code below in the app.js file. You can do this via the File Manager in the hosting Control Panel.

// requiring the HTTP interfaces in node
var http = require('http');
// create an http server to handle requests and response
http.createServer(function (req, res) {
// sending a response header of 200 OK
res.writeHead(200, {'Content-Type': 'text/plain'});
// print out Hello World
res.end('Hello World\n');
// listen on assigned port
}).listen(process.env.PORT);

4. Enable the app using the Web Apps section in hosting Control Panel by clicking on the red circle button for the app there.

5. Your app will appear in the list. You can access it by clicking on its address in the URL column of the list.

The sureapp command is a powerful CLI (command-line interface) tool that allows you to create and manage web applications on your account. In order to use the sureapp tool, you need to connect to your account over SSH. You can connect to your account over SSH as described in the SSH section of our online documentation.

Here are some of the functionalities the sureapp tool offers:

Note: If you do not have a WebApps section in your Control Panel, then this tutorial is not suitable for your particular hosting environment. You can submit a support ticket through our ticketing system if you need assistance.

Getting help

If you call the sureapp command without any arguments, you will see a list of its commands.

To get help with a specific command and see its subcommands, you need to call:

sureapp help command

where you need to replace command with the actual command you wish to see help information for.

Here is a list of the available commands in the sureapp CLI tool:

  • project – This command allows you to create, modify, remove, and list projects.
  • service – This command gives you the ability to view and manage application services.
  • supervisor – This command allows you to control the service supervisor.
  • meta – This command displays meta information.
  • log – This command lists and allows you to view service logs.
  • env – This command allows you to control project environment.

For example, if you would like to see the subcommands and the help information of the sureapp project command, you need to call:

sureapp help project

Then, to see the help information of the sureapp project create command for example, you need to call:

sureapp help project create

Creating a web app

Generally, web apps can be created through the WebApps section of the Control Panel. This way, all necessary options can be configured via a visual interface. However, you can use the sureapp CLI tool to create web apps as well. This can be done with the sureapp project create command.

In order to create a web app through the command line, it is recommended that you first create the subdomain you wish to run the app on through the Subdomains section of the Control Panel, as well as the deployment directory for the web app. To see a list of the available options for the command, call the command without any arguments:

sureapp project create

In order to create a web app through the sureapp CLI tool, it is mandatory to specify the web app name and at least the following options:

  • –engine – This option allows you to specify the application engine. Its value can be either node or custom.
  • –engine-version – This option allows you to specify the application engine version. If the –engine option is set to custom, this option must be set to  (dash). Alternatively, if the –engine option is set to node, this option can be set to currentlts, or any of the versions available. To see a list of available engines and versions, call the sureapp meta engines command.
  • –release-dir – This option allows you to specify the application deployment directory. This directory must be a subdirectory of the /private directory on your account. This directory must contain the files of your application. You must specify the full path to your application’s deployment directory.
  • –subdomain – This option allows you to specify the subdomain where the application will be accessible once it is running. The subdomain will not be created automatically if it does not exist. You must create the subdomain for your application through the Subdomains section of the Control Panel.
  • –domain – This option allows you to specify the domain where your application will be available once it is running. You can park domain names to your account through the Domain Parking section of the Control Panel.
  • –url-path – This option allows you to specify the URL path where your application will be available once it is running. You must specify the URL without the subdomain and the domain.

In addition, you can also specify the following options:

  • –notes STR – This option allows you to add free text notes.
  • –start-cmd STR – This option allows you to define a start command.
  • –rlimit-cpu INT – This option allows you to define the CPU timeout limit in seconds.
  • –rlimit-nproc INT – This option allows you to set the maximum number of processes (and threads) for the project.
  • –rlimit-core INT – This option allows you to set the upper limit on the size (in bytes) of core dump files.
  • –rlimit-data INT – This option allows you to define the maximum size (in bytes) of the process data segment.
  • –rlimit-as INT – This option allows you to set the maximum size of the process virtual memory bytes.
  • –rlimit-fsize INT – This option allows you to define the maximum size (in bytes) of files the process may create.
  • –rlimit-fileno INT – This option allows you to set the maximum number of opened files by the process.
  • –rlimit-stack INT – This option allows you to define maximum size (in bytes) of the process stack.

For example, if you would like to create a web app that will run on the current version of Node.js, available at http://www.yourdomain.com/path/to/your/webapp/, running from the /home/your_username/private/your_webapp_dir/ directory, and with the name MyWebApp, you need to call the sureapp project create command as follows:

sureapp project create --engine node --engine-version current --subdomain www --domain yourdomain.com --release-dir /home/your_username/private/your_webapp_dir/ --url-path /path/to/your/webapp/ MyWebApp

Please note that all options are case-sensitive.

Logging in to a web app shell

You can log in to a web app shell with the following command:

sureapp project shell MyWebApp

This command will log you in to the shell for the MyWebApp web app. You need to replace MyWebApp with the actual name of the web app you wish to manage. Most of the management commands of the sureapp tool work only after logging in to the web app shell.

Managing a web app

Modifying the settings of a web app

Once you log in to a web app shell, you can modify its settings with the sureapp project modify command. The command takes the same arguments as the sureapp project create command which is described in the Creating a web app section of this article.

For example, if you would like to change the engine of a web app to custom, you need to log in to the web app shell and call:

sureapp project modify --engine custom --engine-version -

Managing the state of a web app

You can enable, disable, start, stop, signal, and check the status of a web app with the sureapp service command. The command has several subcommands:

  • status – This subcommand allows you to view the current status of the application.
  • manage – This subcommand allows you to change the status of the application.
  • signal – This subcommand allows you to send signals to the application.

The sureapp service manage command takes the following options:

  • –enable – This option allows you to activate the service for the specified web app project.
  • –disable – This option allows you to stop any running instances and disable the web app project.
  • –start – This option allows you to start the web app as it is started via the WebApps section of the Control Panel.
  • –stop – This option allows you to stop the application as it is stopped via the WebApps section of the Control Panel.
  • –once – This option gives you the ability to run the web app once without restarting it if it exits.
  • –pause – This option allows you to pause the application temporarily (until resumed).
  • –resume – This option allows you to resume a paused application.

The sureapp service signal command takes the following options to send the corresponding signal to the application process tree:

  • –sigalrm–SIGALRM – This option sends the SIGALRM signal.
  • –sighup–SIGHUP – This option sends the SIGHUP signal.
  • –sigint–SIGINT – This option sends the SIGINT signal.
  • –sigkill–SIGKILL – This option sends the SIGKILL signal.
  • –sigquit–SIGQUIT – This option sends the SIGQUIT signal.
  • –sigterm–SIGTERM – This option sends the SIGTERM signal.
  • –sigwinch–SIGWINCH – This option sends the SIGWINCH signal.
  • –sigusr1–SIGUSR1 – This option sends the SIGUSR1 signal.
  • –sigusr2–SIGUSR2 – This option sends the SIGUSR2 signal.

For example, if you would like to enable a web app, you need to log in to the web app shell and call:

sureapp service manage --enable

Managing the environment variables of a web app

Once you log in to the web app shell, you can manage the environment variables of the web app with the sureapp env command. The command has several subcommands:

  • set – This subcommand allows you to set environment variables.
  • unset – This subcommand allows you to unset environment variables.
  • list – This subcommand lists the project environment variables.

For example, if you would like to set the value of NEWVALUE to the variable VAR1 for a web app, you need to log in to the web app shell and call:

sureapp env set VAR1 NEWVALUE

Viewing the configuration of a web app

Once you log in to the web app shell, you can get the configuration values of the web app in a machine-readable format with the sureapp meta config command. The command has several options, depending on the format you would like to get the output in:

  • –json – This option will provide the web app configuration values in pretty printed JSON format.
  • –perl – This option will provide the web app configuration values in Perl Data::Dumper format.
  • –yaml – This option will provide the web app configuration values in YAML format.

For example, if you would like to get the configuration for a web app in pretty printed JSON format, you need to log in to the web app shelland call:

sureapp meta config --json

Viewing the logs of a web app

The sureapp CLI tool allows you to view and monitor the logs of a web app in real time. Once you log in to the web app shell, you can view and monitor logs with the sureapp log command. The command has several subcommands:

  • list – This subcommand lists the log files for project.
  • view – This subcommand allows you to view the contents of a specified log file.
  • follow – This subcommand allows you to follow (tail) a log file in real time.

For example, if you would like to monitor the logs for a web app, you need to log in to the web app shelland call:

sureapp log follow

Deleting a web app

Generally, web apps can be deleted through the WebApps section of the Control Panel. However, you can also delete web apps through the command line by using the sureapp project remove command of the sureapp CLI tool.

For example, if you would like to delete a web app named MyWebApp, you need to call:

sureapp project remove MyWebApp

Managing the web apps supervisor

The web apps supervisor is a system application that makes sure your web apps are running. The web apps supervisor can start, stop, or restart a web app when needed. It also manages the processes started by web apps. The web apps supervisor application itself can be managed through the command line with the sureapp supervisor command. The command has several subcommands:

  • start – This command allows you to start the supervisor service.
  • stop – This command allows you to stop the supervisor service.
  • restart – This command allows you to restart the supervisor service.
  • status – This command allows you to check the status of the supervisor service.
  • tree – This command allows you to view the process tree of the supervisor service.

For example, if you would like to check whether the web apps supervisor is running, you need to call:

sureapp supervisor status

This article will show you how to view the logs for your web apps. 

To view the logs, you need to log in to the app shell, and execute the commands listed below there. You can see how to log in to the app shell in the Sureapp – app management CLI tool article from our online documentation.

CommandDescription
sureapp log followtail the current log
sureapp log listlist the log files for the app
sureapp log view [logfile]view a log file, default is current log

This tutorial will show you how to install and configure Django in a Python virtual environment within a web app.

If you do not have a WebApps section in your hosting Control Panel, then this tutorial is not suitable for your particular hosting environment. You can submit a support ticket through our ticketing system if you need assistance.

We will set up a Django production environment. We will use Python 3, pip 3, Django, virtualenv, Python's MySQL client (mysqlclient), WhiteNoise, Gunicorn, and uWSGI in order to provide you with the tools necessary for running web applications with Django.

1. The first step is to create a directory for Django in the private directory on your account
  • We recommend that web apps be only deployed in directories in the private directory on the account. You should create a separate directory there for the app to avoid mixing its contents with other apps or other files in the private directory. You can create the directory using the File Manager in your hosting Control Panel. In this example, the directory is called “django”.
2. Create the app using the WebApps section of the hosting Control Panel
  • Choose Custom as engine.
  • Enter a name for your app. It is only for internal reference to the app. In this example, it is Django.
  • Choose a subdomain at which you wish to access the app. In this example, we choose the “www” subdomain: www.mydomain.com.
  • Enter the web access path. For example, if you enter /django, you will be able to access the app at http://www.mydomain.com/django. You do not need to create the directory. In this example, we enter / (forward slash) as web access path, so the app is accessible at http://www.mydomain.com.
  • The port will be assigned automatically. It will be transparent to your users. You can see the port in the apps list after creating the project. We use 10101 as automatically assigned port in our example.
  • Select the deployment directory. Enter the directory you created in step 1 (/private/django).
  • We will add the start command of the web app once Django is fully configured.

Create a new web app

3. Installing Django
  • Connect to your account via SSH. You can check our online documentation for more information on doing this:

Logging Into Your Account via SSH using Putty
Logging Into Your Account via SSH using Terminal in Mac OS

  • Through your hosting Control Panel > SSH Access section > Additional tools, make sure that the “Compiling tools (gcc, g++)” feature is enabled.
  • On our servers, Python 2 is the primary Python interpreter, so “python” and “pip” commands use Python 2 by default. The latest version of Django requires Python 3. The path to Python 3 is /usr/bin/python3. The alias for this binary is “python3”. You can add aliases to /home/myusername/.bashrc
  •  Your next step is to install Django. It is time to use Sureapp – our app management CLI tool. Enter the shell of your web app with the following command (replace Django with the name of your web app):

myusername@s501:/home/myusername$ sureapp project shell Django

  • Next, run the following command to add a new executables path for this particular project:

myusername@s501 [django:custom/-] /home/myusername/private/django$ echo “” >> /home/$USER/.bashrc ; echo “# Additional executables path” >> /home/$USER/.bashrc ; echo “export PATH=$HOME/.local/bin:\$PATH” >> /home/$USER/.bashrc ; . /home/$USER/.bashrc

  • Install virtualenv with the following command:

myusername@s501 [django:custom/-] /home/myusername/private/django$ pip3 install virtualenv

  • virtualenv is a virtual environment where you can install software and Python packages in a contained space, which isolates the installed software and packages from the rest of your account’s global environment. Multiple virtual environments allow you to run various apps using different versions of software and packages, thus avoiding potential conflicts.
  • Create a new directory, which we will use as a home for our virtual environment. In this example, we will use /home/myusername/private/django/django1
  • Set up the new virtual environment with the command below:

myusername@s501 [django:custom/-] /home/myusername/private/django$ virtualenv -p /usr/bin/python3 /home/$USER/private/django/django1

  • Activate the newly created environment:

myusername@s501 [django:custom/-] /home/myusername/private/django$ source django1/bin/activate

  • You will know the virtual env is activated by the new prefix (django1):

 activate-django1-virtualenv.png

  • Install Django and Python’s MySQL client. Run the commands in the /home/myusername/private/django/django1 directory:

(django1) myusername@s501 [django:custom/-] /home/myusername/private/django/django1$ pip3 install Django
(django1) myusername@s501 [django:custom/-] /home/myusername/private/django/django1$ pip3 install mysqlclient

  •  Run the following command:

(django1) myusername@s501 [django:custom/-] /home/myusername/private/django/django1$ django-admin startproject mysite

4. Setting up Django to use MySQL instead of SQLite
  • Create a new MySQL database via the MySQL Databases section in your hosting Control Panel. It is recommended that you create a separate database user, too. More information can be found in our MySQL Databases article. In our example, we use myusername_databasename as database name, djangouser as database username, and djangodbpassword as password.
  • Using the File Manager in your hosting Control Panel, or by using your favorite command line text editor (e.g. nano), open /home/myusername/private/django/django1/mysite/mysite/settings.py for editing. Find the following block of code there:

DATABASES = {
 ‘default’: {
 ‘ENGINE’: ‘django.db.backends.sqlite3’,
 ‘NAME’: os.path.join(BASE_DIR, ‘db.sqlite3’),
 }
}

  • Comment (or delete) the above lines and add the following instead:

DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.mysql’,
‘NAME’: ‘myusername_databasename’,
‘USER’: ‘djangouser’,
‘PASSWORD’: ‘djangodbpassword’,
‘HOST’: ‘localhost’,
‘PORT’: ‘3306’,
}
}

  • Replace the database connection settings with your own database name,  username, and password. To use MySQL’s Strict Mode, which is strongly recommended by Django, you could also specify the MySQL mode:

DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.mysql’,
‘NAME’: ‘myusername_databasename’,
‘USER’: ‘djangouser’,
‘PASSWORD’: ‘djangodbpassword’,
‘HOST’: ‘localhost’,
‘PORT’: ‘3306’,
‘OPTIONS’: {
‘init_command’: “SET sql_mode=’STRICT_TRANS_TABLES'”,
},
}
}

  • navigate to /home/myusername/private/django/django1/mysite and run the command below, so the necessary data is migrated to your database:

(django1) myusername@s501 [Django:custom/-] /home/myusername/private/django/django1/mysite$ python3 manage.py migrate

  • With the next command, you can add an administrator user, so you can access the Django administration interface:

(django1) myusername@s501 [Django:custom/-] /home/myusername/private/django/django1/mysite$ python3 manage.py createsuperuser

  •  Congratulations! You have successfully installed Django and set it up to use a MySQL database in “STRICT_TRANS_TABLES” sql mode. Run the development web server and check that the site is working as you expect at http://www.mydomain.com/admin/

(django1) myusername@s501 [Django:custom/-] /home/myusername/private/django/django1/mysite$ python3 manage.py runserver 0:10101

  •  In the command above, make sure to replace port 10101 with the port assigned to your web app.
5. Getting ready for production – Gunicorn+WhiteNoise or uWSGI
5.1. Gunicorn and WhiteNoise
  • Gunicorn is a Python WSGI HTTP server recommeded for use with Django on our servers. To use it with your “django1” project, enter your project’s shell using the Sureapp CLI tool and activate your virtual environment as explained in the steps outlined above. Furthermore, as Django does not support serving static files in production, you can integrate the WhiteNoise project into your Django application:

(django1) myusername@s501 [django:custom/-] /home/myusername/private/django/django1/mysite$ pip3 install whitenoise
(django1) myusername@s501 [django:custom/-] /home/myusername/private/django/django1/mysite$ pip3 install gunicorn

 install-gunicorn-and-whitenoise.png

  • Add the following lines in the end of /home/myusername/private/django/django1/mysite/mysite/settings.py:

import os
STATIC_ROOT = os.path.join(BASE_DIR, ‘staticfiles’)
STATICFILES_STORAGE = ‘whitenoise.storage.CompressedManifestStaticFilesStorage’

  • Additionally, right after the first line in the MIDDLEWARE section, add

‘whitenoise.middleware.WhiteNoiseMiddleware’,

  • so it looks like so:

MIDDLEWARE = [
‘django.middleware.security.SecurityMiddleware’,
‘whitenoise.middleware.WhiteNoiseMiddleware’,
‘django.contrib.sessions.middleware.SessionMiddleware’,
‘django.middleware.common.CommonMiddleware’,
‘django.middleware.csrf.CsrfViewMiddleware’,
‘django.contrib.auth.middleware.AuthenticationMiddleware’,
‘django.contrib.messages.middleware.MessageMiddleware’,
‘django.middleware.clickjacking.XFrameOptionsMiddleware’,
]

  • You should also update the ALLOWED_HOSTS setting in settings.py, so it looks like so:

ALLOWED_HOSTS = [‘localhost’,’mydomain.com’]

  • On a production site, make sure to disable DEBUG mode in settings.py:

DEBUG = False

  • As a last step before starting your app, run the following command, so the static files are copied to your project’s root:

(django1) myusername@s501 [django:custom/-] /home/myusername/private/django/django1/mysite$ ./manage.py collectstatic

  • Log in to your hosting Control Panel and navigate to the WebApps section. Click the Edit button for your web app and enter the following as start command:

source /home/myusername/private/django/django1/bin/activate && cd /home/myusername/private/django/django1/mysite && gunicorn mysite.wsgi

  • Click the Update button to save the changes, and then click the red circle to enable the web app. Click the Refresh button to check if the web app was successfully enabled.

Django up and running

  • You can visit http://www.mydomain.com/admin to make sure that Django is running as expected.
5.2. uWSGI – an application server container recommended for use with Django
  • Instead of installing Gunicorn and WhiteNoise, you can just install and run your application via uWSGI. To install uWSGI, run the following command:

(django1) myusername@s501 [django:custom/-] /home/myusername/private/django/django1$ pip3 install uwsgi

ALLOWED_HOSTS = [‘localhost’,’mydomain.com’,’DEFAULT_IP_ADDRESS’]

  • On a production site, make sure to disable DEBUG mode in settings.py:

DEBUG = False

  • As a last step before starting your app, run the following command, so the static files are copied to your project’s root:

(django1) myusername@s501 [django:custom/-] /home/myusername/private/django/django1/mysite$ ./manage.py collectstatic

  • Create /home/myusername/private/django/django1/uwsgi.ini and add the code below to it (the following is an example setup, and settings can be modified as needed):

[uwsgi]
chdir=/home/myusername/private/django/django1/mysite
home=/home/myusername/private/django/django1
http-socket=:10101
module=mysite.wsgi:application
die-on-term = true
master=1
vacuum=1
max-requests=5000
processes=8
threads=4
static-map=/static=/home/myusername/private/django/django1/mysite/staticfiles

  • You will have to update at least the chdir, home, static-map, and http-socket options, so the proper port and paths are defined.
  • In your hosting Contol Panel > WebApps section, edit your web app and add the following as start command:

source /home/myusername/private/django/django1/bin/activate && uwsgi /home/myusername/private/django/django1/uwsgi.ini

  • Click the Update button to save the changes, and then click the red circle to enable the web app. Click the Refresh button to check if the web app was successfully enabled.
  • You can visit http://www.mydomain.com/admin to make sure that Django is running as expected.

Django_admin.jpg

This tutorial will show you how to install and configure the Flask micro-framework in a Python virtual environment within a web app.

If you do not have a WebApps section in your hosting Control Panel, then this tutorial is not suitable for your particular hosting environment. You can get in touch with us if you need further assistance.

The official Flask documentation can be found at https://flask.palletsprojects.com/en/1.1.x/.

We will set up a simple Flask environment and use it to run a “Hello World” script.

1. The first step is to create a directory for Flask in the private directory on your account
  • It is strongly recommended that web apps be only deployed in directories within the private directory on the account. We recommend that you create a separate directory there for the app to avoid mixing its contents with other apps or other files in the private directory. You can create the directory using the File Manager in your hosting Control Panel. In this example, the directory is called “flask”.
  • Additionally, we will create a “flask” subdomain where our application will be publicly accessibe. You can set up your new subdomain from the Subdomains section of the Control Panel.
2. Create the app using the WebApps section of the hosting Control Panel
  • Choose Custom as engine.
  • Enter a name for your app. It is only for internal reference to the app. In this example, it is Flask.
  • Choose a subdomain at which you wish to access the app. In this example, we choose the “flask” subdomain: flask.mydomain.com.
  • Enter the web access path. For example, if you enter /flask, you will be able to access the app at http://flask.mydomain.com/flask. You do not need to create the directory. In this example, we enter / (forward slash) as web access path, so the app is accessible at http://flask.mydomain.com.
  • The port will be assigned automatically. It will be transparent to your users. You can see the port in the apps list after creating the project. We use 7190 as automatically assigned port in our example.
  • Select the deployment directory. Enter the directory you created in step 1 (/private/flask).
  • We will add the start command of the web app once Flask has been installed and we have prepared our “Hello World” scripts.

Create a new web app

3. Installing Flask

  • Connect to your account via SSH. You can check our online documentation for more information on doing this:

Logging Into Your Account via SSH using Putty
Logging Into Your Account via SSH using Terminal in Mac OS

  • Through your hosting Control Panel > SSH Access section > Additional tools, make sure that the “Compiling tools (gcc, g++)” feature is enabled.
  • On our servers, Python 2 is the primary Python interpreter, so “python” and “pip” commands use Python 2 by default. However, Flask requires Python 3. The path to Python 3 is /usr/bin/python3. The alias for this binary is “python3”, and conversely, the Python 3 package installer can be accessed with “pip3”. You can add additional custom aliases to the /home/myusername/.bashrc file, where “myusername” is your hosting account username.
  • Your next step is to install Flask. It is time to use Sureapp – our app management CLI tool. Enter the shell of your web app with the following command (replace Flask with the name of your web app):

myusername@s501:/home/myusername$ sureapp project shell Flask

  • Next, run the following command to add a new executables path for this particular project:

myusername@s501 [Flask:custom/-] /home/myusername/private/flask$ echo “” >> /home/$USER/.bashrc ; echo “# Additional executables path” >> /home/$USER/.bashrc ; echo “export PATH=$HOME/.local/bin:\$PATH” >> /home/$USER/.bashrc ; . /home/$USER/.bashrc

  • Install virtualenv with the following command:

myusername@s501 [Flask:custom/-] /home/myusername/private/flask$ pip3 install virtualenv

  • virtualenv is a virtual environment where you can install software and Python packages in a contained space, which isolates the installed software and packages from the rest of your account’s global environment. Multiple virtual environments allow you to run various apps using different versions of software and packages, thus avoiding potential conflicts.
  • You can set up the new virtual environment in the current working directory with the command below:

myusername@s501 [Flask:custom/-] /home/myusername/private/flask$ virtualenv -p /usr/bin/python3 /home/$USER/private/flask

  • Activate the newly created environment:

myusername@s501 [Flask:custom/-] /home/myusername/private/flask$ source bin/activate

  • You will know the virtual env is activated by the new prefix of your shell prompt (flask):

 Activate virtualenv

  • At this point, you can install Flask. Run the following command in the /home/myusername/private/flask directory:

(flask) myusername@s501 [Flask:custom/-] /home/myusername/private/flask$ pip3 install Flask

4. Setting up the Flask “Hello World” scripts
  • To confirm that Flask is installed and running on the account, you should create the following two files in the Flask project directory:
    • hello.py with the following contents:

from flask import Flask
app = Flask(__name__)

@app.route(‘/’)
def hello_world():
    return ‘Hello World!’

    • hello.sh with the following contents:

#!/bin/sh
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
source /home/myusername/private/flask/bin/activate
exec env FLASK_APP=/home/myusername/private/flask/hello.py flask run –port=$PORT

  • When ready, navigate to the WebApps section. Click the Edit button for your Flask web app and enter the following as its start command:

sh hello.sh

  • Click the Update button to save the changes, and then click the red circle to enable the web app. Click the Refresh button to check if the web app was successfully enabled.

Flask up and running

  • You can now visit http://flask.mydomain.com in your browser to make sure that Flask is running as expected – if everything has been set up correctly, you should see the “Hello World!” greeting on the page.

 ghost_logo.png

This tutorial will show you how to install the CMS and blogging platform Ghost.

If you do not have a WebApps section in your hosting Control Panel, then this tutorial is not suitable for your particular hosting environment. You can contact us via our ticketing system for further assistance.

1. Create an app using the WebApps section of the hosting Control Panel
  • Choose Node.js LTS as engine. This is way, the app will use the latest Node.js LTS version which will almost always be Ghost’s current recommended Node.js version.
  • Enter a name for your app. It is only for internal reference to the app. In this example, it is ghost.
  • Choose a subdomain at which you wish to access Ghost. In this example, we choose the default “www” subdomain.
  • Enter the web access path. For example, if you enter /ghost, you will be able to access the app at https://www.example.com/ghost. You do not need to create the directory. In this example, we enter / (forward slash) as web access path, so the app is accessible at https://www.example.com.
  • The port will be assigned automatically. It will be transparent to your users. You can see the port in the apps list after creating the project.
  • Leave the deployment directory as /private. You will change it later when configuring the app.

    ghost_app.png

2. Create a MySQL database for Ghost
  • Create a new MySQL database via the MySQL Databases section in your hosting Control Panel. It is recommended that you create a separate database user, too. More information can be found in our MySQL Databases article. In our example, we use myusername_ghost as database name, ghostuser as database username, and ghostpassword as password.
3. Enable an SSL certificate and force HTTPS connections.

You can easily enable a free Let’s Encrypt certificate by using the SSL/HTTPS -> Let’s Encrypt certificates section of the hosting Control Panel as described in the Let’s Еncrypt certificates section from our online documentation. After that, you can use the SSL/HTTPS > Force HTTPS section to force HTTPS connections to the domain/subdomain where Ghost will be running. 

4. Install Ghost.

First you need to connect to your account via SSH. You can check our online documentation for more information on doing this:

Logging Into Your Account via SSH using Putty
Logging Into Your Account via SSH using Terminal in Mac OS

Once you have connected via SSH, you can enter the shell of your web app with the following command (replace ghost with the name of your web app):

sureapp project shell ghost

Next, run the following command to install the Ghost command line utility:

npm install ghost-cli@latest -g 

To install Ghost with a MySQL 5 database, run the following command: 

ghost install –url https://$SUBDOMAIN.$DOMAIN$URL_PATH –port $PORT –db mysql –dbhost localhost –dbname myusername_ghost –dbuser ghostuser –dbpass ghostpassword –dir /home/$USER/private/ghost –process local –no-setup-linux-user –stack false –no-start

If you wish to use a MySQL 8 database, you will need to also specify the database connection port as 3308:

ghost install –url https://$SUBDOMAIN.$DOMAIN$URL_PATH –port $PORT –db mysql –dbhost localhost –dbport 3308 –dbname myusername_ghost –dbuser ghostuser –dbpass ghostpassword –dir /home/$USER/private/ghost –process local –no-setup-linux-user –stack false –no-start

You should replace the parts in bold with the respective values for your web app.

dbname: the name of the MySQL database you created at step 2
dbuser: the MySQL user you created at step 2
dbpass: the password for the MySQL user
dir: the directory where Ghost should be installed. It must be an empty subdirectory of the private directory on your account. If the directory does not exist, the installer will create it for you.

The installer should finish with the following output:

Ghost was installed successfully! To complete setup of your publication, visit:
https://www.example.com/ghost/

The setup URL of Ghost is not working as we have not yet started and configured the web app.

5. Configure and start the Web App.

Make the following changes to the Web App:

  • Change the deployment directory to the location where Ghost was installed. In this example it is /private/ghost.
  • Enter the following in the ‘Start command’ field:

node current/index.js

  • Add the following environment variable:

NODE_ENV production

This way Ghost will run in production mode.

ghost5.png 

Save the changes and click on the red ‘Enable the app’ button. Ghost should start after a few seconds and you can complete the setup by visiting the URL that was provided by the installer (https://www.example.com/ghost/ in our example). To invite staff, you first need to configure the email service following the instructions provided in the next step.

 6. Configuring the email service

For Ghost to be able to send email, you can configure it to use the Sendmail binary on the server. To do this, you have to edit the Ghost configuration file config.production.json which is located in the Ghost installation directory. You can easily edit the file through the File Manager interface of the hosting Control Panel. Change the following lines in config.production.json:

 

  "mail": {
    "transport": "Direct"
  },

to

  "mail": {
    "transport": "sendmail",
            "options": {
                "path": "/usr/lib/sendmail"                
            }
        },

For the change to take effect, restart the Web App by clicking the green ‘Disable the app’ button, and then the red ‘Enable the app’ button.

This tutorial will show you how to install and configure a Ruby on Rails project within a web app.

If you do not have a Web Apps section in your hosting Control Panel, then this tutorial is not suitable for your particular hosting environment. You can ask your hosting provider for more information, or you can seek assistance through our ticketing system.

Important: Throughout this tutorial, ‘example‘ is used as the username for the account. Wherever you see ‘example‘, you should replace it with the actual username for your hosting account.

We will set up a Ruby environment by using Ruby Version Manager (RVM). RVM enables you to manage and work with multiple Ruby environments and allows you to switch between them. This way, you can have multiple projects on the same account, each using a different version of Ruby and different gems.

1. Connect to your account via SSH
  • Through your hosting Control Panel > SSH Access section > Additional tools, make sure that the Compiling tools (gcc, g++) and Network tools features are enabled.
  • Connect to your account via SSH. You can check our online documentation for more information on doing this:
    Logging Into Your Account via SSH using Putty
    Logging Into Your Account via SSH using Terminal in Mac OS
2. Install and configure Ruby Version Manager (RVM)

Most of the installation steps have been obtained from the RVM installation documentation.

  • The RVM packages are signed with GnuPG. You need to configure GnuPG and download the required public keys. To set a custom directory for storing the keys, run the following command:

echo “export GNUPGHOME=$HOME/private/.gnupg” >> ~/.bashrcReload your bash profile:
source ~/.bashrcDownload and import the keys:

curl -sSL https://rvm.io/mpapis.asc | gpg –import – && curl -sSL https://rvm.io/pkuczynski.asc | gpg –import – && gpgconf –kill gpg-agent

  • To download and run the RVM installation script, run the following command:

curl -sSL https://get.rvm.io | grep -v ‘partition=`df’ | bash -s — –path ~/private/.rvm –ignore-dotfiles

You should get the following output:

RVM was installed in the ~/private/.rvm directory on your account

* To start using RVM, you need to run the command listed below in all your open shell windows (in rare cases you need to reopen all shell windows):

source ~/private/.rvm/scripts/rvm

  • Add the RVM initialization scripts to the bash configuration file:

echo “source $HOME/private/.rvm/scripts/rvm” >> ~/.bashrc

  • Close all your SSH sessions and reconnect. You can test if RVM was loaded correctly in your new session by running:

type rvm | head -n 1

You should get the following output:

rvm is a function

  • RVM uses the /bin/df utility to check if there is enough free disk space on the server before installing a new version of Ruby. Unfortunately,  access to /bin/df is not allowed and the installation fails with an error. As of version 1.29.9, there is no way for this check to be disabled. Therefore, you need to patch RVM by removing the calls to __rvm_calculate_space_free. You can do this with the following command:

sed -i “/__rvm_calculate_space_free/c\__free_space=9999M” ~/private/.rvm/scripts/functions/manage/base_install ~/private/.rvm/scripts/migrate

The patch sets an arbitrary value of 9999M for the __free_space variable.

In case you update RVM to a newer version, you may need to apply the patch again.

  • Autolibs is a feature built into RVM that automatically installs system dependencies. As your user does not have sudo or root access this is not possible, thus you should disable the autolibs feature with the following command:

rvm autolibs 0

In case some gem installation fails or your project does not run due to a missing dependency, you can contact our support team for assistance. You can check for any missing dependencies with the following command:
rvm requirements

3. Install Ruby

RVM could run out of memory when compiling Ruby. Therefore, you should limit the compilation to 3 simultaneous threads by adding the following setting to ~/private/.rvm/scripts/functions/rvmrc:

echo “rvm_make_flags=( -j 3 )” >> ~/private/.rvm/scripts/functions/rvmrcTo make sure that all changes were applied, reload RVM:

rvm reload

You can now install the latest stable version of Ruby by running:

rvm install ruby –latest

RVM will compile Ruby from source and install a global gemset. At the time of this writing, the latest stable Ruby is 3.1.2. We will use this version in the examples that follow. You can switch to that Ruby version with:

rvm use 3.1.2

4. Install Rails and create a project.

You can install Rails directly into the global gemset. However, many developers prefer to keep the global gemset sparse and install Rails into a project-specific gemsets, so that each project has the appropriate version of Rails.

  • You need to create a directory for storing your project. All web app projects should be located in the ~/private directory. Create a new directory named ‘blog’ and switch to that directory:

mkdir ~/private/blog
cd ~/private/blog

  • Create a project-specific gemset:

rvm use ruby-3.1.2@blog –ruby-version –create

The name of our project and our gemset is blog.

The option “—ruby-version” creates .ruby-version and .ruby-gemset files in the root directory. RVM recognizes these files in an application’s root directory and loads the required version of Ruby and the correct gemset whenever you enter the directory.

  •  Proceed with installing Rails:

gem install rails

Rails will be installed in the gemset blog.

This can take a while as Rails has a lot of gem dependencies.

  • Now create a new Rails project:

rails new .

With ‘.’ (a dot) as project name, the command creates a new project in the current directory, and the project name is the same as the name of the directory.

You may be asked if .ruby-version should be overwritten. The old and new files have the same content, so both ‘yes’ and ‘no’ are valid options.

In case some gems were not installed correctly locally, you can fix this by running the following command:

bundle install

5. Create and configure the Web App

Open the Web Apps section of your hosting Control Panel and create a new app with the following settings:

• Choose Custom as the engine.
• Enter a name for your app. It is only for internal reference to the app. In this example, it is Blog.
• Choose a subdomain at which you wish to access the app. In this example, we choose the “www” subdomain: www.example.com.
• Leave the default web access path / (forward slash). For example, if you enter /rails, you will be able to access the app at http://www.example.com/rails. You do not need to create the directory.
• A port will be automatically assigned to the new project. It will be transparent to your users. It will be displayed in the app list after creating the project. You should note it as you will need it at the next step. In this example, it is 44181.
• For deployment directory select the directory where the project is located. In this case it is /private/blog.

• The Rails web server can be started with the following command:

rails server

However, to run a Ruby application as a web app with RVM, you need to first load the corresponding RVM environment and then run the executable of your app. For every installed ruby and gemset, RVM creates environment files. You can list the environment file for this project by running the following command in the project directory:

rvm env –path

RVM will return the path to the environment file:

/home/example/private/.rvm/environments/ruby-3.1.2@blog

You can use the ‘source’ command to load this environment file when starting Rails. Both commands combined are:

source /home/example/private/.rvm/environments/ruby-3.1.2@blog && rails server

You should enter this combined command in the Start command field of the web app.

Once you are finished, the project should look like the following:

 Web App

  • Before starting the web app, you need to configure the Rails app to use the correct port. The port setting is located in ~/private/blog/config/puma.rb. Change the default port 3000 to the one of your web app (in this example 44181):

    port ENV.fetch(“PORT”) { 44181 }

  • Add the following line to your ~/private/blog/config/application.rb file in the “class Application < Rails::Application” code block to allow requests from your domain/subdomain to your Ruby on Rails application:
    config.hosts << “www.example.com”
  • Start the web app by clicking on the red ‘Enable this app’ button. If everything is working correctly, you should see the following when you open the app URL in a browser:

Ruby on Rails 7.0.3.1

This tutorial will show you how to use the already installed MongoDB on the server, as well as install a custom MongoDB instance.

If you do not have a Web Apps section in your hosting Control Panel, then this tutorial is not suitable for your particular hosting environment. You can ask your hosting provider for more information, or you can seek assistance through our ticketing system.

1. Using the hosting server’s MongoDB packages to start an instance of MongoDB

You can run a MongoDB instance by using the MongoDB binaries installed on the hosting server by default. If port and dbpath parameters are not defined in the start command, the MongoDB instance will run with the default parameters – port 27017 and dbpath /data/db. As the port for the app is assigned automatically, and hosting accounts do not have access to /data/db, you just need to set different port and dbpath parameters when starting your MongoDB instance. First, you need to create the database data directory. In this example, we will use /home/myusername/private/mongodb/data/db. Make sure that the database data directory exists. Through the Web Apps section in your hosting Control Panel, create a new app for running the MongoDB instance. In this example, we name the app MongoDB.

Default MongoDB Create App

The start command is:

mongod –dbpath /home/myusername/private/mongodb/data/db –port $PORT

After you enable the app by clicking on the red circle, click the Refresh button until the circle is green, the State is OK, and the Status is Up. Then you can visit http://www.mydomain.com/mongodb to check if the application is running. You should receive a message saying “It looks like you are trying to access MongoDB over HTTP on the native driver port.”

2. Installing a custom MongoDB instance

If you want your project to use a version of MongoDB that is different than the one installed on the server by default, then you need to follow the steps below:

1) Connect to your account via SSH.
2) Navigate to the location from which MongoDB will run. In this example, we use /home/myusername/.local/bin.
myusername@s501:/home/myusername$ cd .local/bin3) Download the binary files for the desired release of MongoDB. You can download the binaries from https://www.mongodb.com/download-center/community. You need to select the version, choose “Debian 10.0” as Platform, choose “shell (tgz)” as package, and click the “copy link” button to copy the download link. In this example, the download link is “https://fastdl.mongodb.org/linux/mongodb-shell-linux-x86_64-debian10-5.0.3.tgz”. Then, download the file to the server with curl by running:
myusername@s501:/home/myusername/.local/bin$ curl -O https://fastdl.mongodb.org/linux/the_name_of_the_current_package.tgz
4) Extract the files from the downloaded archive with tar. For example, through the shell, you can extract with a tar command:
myusername@s501:/home/myusername/.local/bin$ tar -zxvf the_name_of_the_current_package.tgz5) Copy the extracted binaries to the location from which MongoDB will run (e.g. /home/myusername/.local/bin).
myusername@s501:/home/myusername/.local/bin$ cp -R -n the_name_of_the_current_package/bin/* .

Attention

At the time of writing, the current pakage name at the mongoDB download page is mongodb-shell-linux-x86_64-debian10-5.0.3.tgz, so the commands that need to be run are as follows::

cd ~/local/bin
curl -O https://fastdl.mongodb.org/linux/mongodb-shell-linux-x86_64-debian10-5.0.3.tgz
tar -zxvf mongodb-shell-linux-x86_64-debian10-5.0.3.tgz
cp -R -n mongodb-shell-linux-x86_64-debian10-5.0.3/bin/* .

6) Ensure the location of the binaries is in the PATH variable. You should have the following line in your shell’s rc file (/home/myusername/.bashrc):
export PATH=$HOME/.local/bin:$PATHIf you want to run the MongoDB binaries from a different location, make sure to add that location to the PATH variable:

export PATH=<mongodb-install-directory>/bin:$PATH

7) Create the deployment directory for the web app that will run your custom MongoDB instance, e.g. /home/myusername/private/mongodb. In the deployment directory, you should create the database data directory, e.g. /home/myusername/private/mongodb/data/db.

8) In the Web Apps section of the hosting Control Panel, create a new app. Our example app is named MongoDB.

 MongoDB Custom Instance

The start command is:
/home/myusername/.local/bin/mongod –dbpath /home/myusername/private/mongodb/data/db –port $PORT9) Click the Create button. Then click on the red circle to start the app. Click the Refresh button to update the State and Status of the app. When the State is OK, and the Status is Up, your custom instance of MongoDB is running.

 Custom MongoDB instance Up

3. Enabling authentication

Enabling access control on a MongoDB deployment enforces authentication, requiring users to identify themselves. When accessing a MongoDB deployment that has access control enabled, users can only perform actions as determined by their roles. The following procedure first adds a user administrator to a MongoDB instance running without access control and then enables access control.

1) Through your shell, connect to the MongoDB instance.

mongo –port $PORT2) Create the user administrator.

use admin
db.createUser(
{
user: “myUserAdmin”,
pwd: “abc123”,
roles: [ { role: “userAdminAnyDatabase”, db: “admin” } ]
}
)

3) Disconnect the mongo shell.

4) Restart the MongoDB instance with access control. To do this, go to the Web Apps section of the hosting Control Panel and click on the green circle to stop the app. Then update the start command of the MongoDB app by adding the “auth” parameter:

/home/myusername/.local/bin/mongod –auth –dbpath /home/myusername/private/mongodb/data/db –port $PORT

5) Click the Update button to save the changes, and then click on the red circle to restart the custom MongoDB instance with access control.

4. Connecting to the database

The standard format of the MongoDB URI connection scheme looks like this:

mongodb://[username:password@]host1[:port1][,…hostN[:portN]]][/[database][?options]]

By following this example, you could access the database created in this tutorial with the following connection string:

mongodb://myUserAdmin:abc123@localhost:36375/admin

In this tutorial, we will show you how to configure a PostgreSQL database server on your account using the WebApps platform.

If you do not see a WebApps section in the Control Panel of your hosting account, this tutorial may not be suitable for your particular hosting environment. Please contact our support team for more information.

You need SSH access to the server in order to make the changes described in this tutorial. If you haven’t set up SSH for your account yet, you should do this now.

Quick Setup

If you want to quickly set up a PostgreSQL server running on your account, you can download this PostgreSQL setup shell script to your account and run it. The script will set up the WebApps project and the PostgreSQL instance on your account and you will be able to start using them immediately.

In order to run the setup script, you have to change its permissions to 755 after you download it to your account. You will then be able to run it from the command line:

mv 4166.sh setup_postgresql.sh
chmod 755 setup_postgresql.sh
./setup_postgresql.sh postgres1

In that case, you can skip the “PostgreSQL Server Setup” and “Custom WebApps Project” sections of this article and go directly to the Creating Databases and Roles section.

PostgreSQL Server Setup

The PostgreSQL binaries are already installed on the server. You only have to set up a PostgreSQL instance to handle your databases using the WebApps platform.

To do that, you first have to create the directory structure to hold your data on the server. You can use the private/ directory that is available in each hosting account for this:

sureapp_project="postgres1"
pg_app_dir="/home/$USER/private/$sureapp_project"

mkdir -m 0700 “$pg_app_dir”
mkdir -m 0700 “$pg_app_dir/run”
mkdir -m 0700 “$pg_app_dir/sureapp”

touch “$pg_app_dir/.psql_history”
chmod 0600 “$pg_app_dir/.psql_history”

The next step is to initialize your database cluster and set up a superuser role. By default, the username of the superuser role is the same as the username of your hosting account (“example” in this case):

superuser_pass="$(pwgen 24 1)"
touch "$pg_app_dir/.superuser-pwfile"
chmod 0600 "$pg_app_dir/.superuser-pwfile"
echo "$superuser_pass" > "$pg_app_dir/.superuser-pwfile"

for pg_install_dir in $(find /usr/lib/postgresql -maxdepth 1 -type d -o -type l 2>/dev/null | sort -Vr)
do
    [ -x “$pg_install_dir/bin/initdb” ] && break
done
“$pg_install_dir/bin/initdb” -D “$pg_app_dir/pgdata” –auth=md5 –pwfile=”$pg_app_dir/.superuser-pwfile” && rm -f “$pg_app_dir/.superuser-pwfile”

touch “$pg_app_dir/.pgpass”
chmod 0600 “$pg_app_dir/.pgpass”
printf “*:*:*:%s:%s\n” “$USER” “$superuser_pass” > “$pg_app_dir/.pgpass”

Now, you have to configure the PostgreSQL server to listen for requests using a UNIX socket at the correct location in your account:

sed -i "s~^#*unix_socket_directories = .*\(\s*#.*\)~unix_socket_directories = '$pg_app_dir/run' \1~g" "$pg_app_dir/pgdata/postgresql.conf"
sed -i "s~^#*unix_socket_permissions = .*\(\s*#.*\)~unix_socket_permissions = 0700 \1~g" "$pg_app_dir/pgdata/postgresql.conf"
sed -i "s~^#*listen_addresses = .*\(\s*#.*\)~listen_addresses = '' \1~g" "$pg_app_dir/pgdata/postgresql.conf"

To make starting the PostgreSQL service easier, the following commands will create a startup script:

printf '#!/bin/sh\nexec %s/bin/postgres -D %s/pgdata\n' "$pg_install_dir" "$pg_app_dir" > "$pg_app_dir/start.sh"
chmod 0700 "$pg_app_dir/start.sh"

In order to use various PostgreSQL management tools such as psql easily, you should also make some changes to your .bashrc file:

grep -q '^PGHOST=' "/home/$USER/.bashrc" || cat <<BASHRC >> "/home/$USER/.bashrc"

# $sureapp_project client configuration
PGHOST=”$pg_app_dir/run”
export PGHOST
PGPASSFILE=”$pg_app_dir/.pgpass”
export PGPASSFILE
PSQL_HISTORY=”$pg_app_dir/.psql_history”
export PSQL_HISTORY
BASHRC
. “/home/$USER/.bashrc”

Custom WebApps Project

To run the database server, you have to set up a PostgreSQL service. There are two ways to do this:

  • You can create the project on the WebApps page of the Control Panel of your hosting account;
  • You can use the command line interface of the WebApps platform to create the project.

The following sections describe how to do this.

On the WebApps Page of the Control Panel

If you choose the Control Panel way, you should create a new app with the following settings:

  • Engine: Custom
  • Name: postgres1 – The name of your app.
  • Domain: example.com – You can choose any domain from the list. It will not affect the operation of the PostgreSQL server.
  • Subdomain: www – Again, you can choose any subdomain. It will have no effect because the PostgreSQL instance will not be listening on a TCP port.
  • Web access path: /Efu6dunox0vieyelahch2eaf – The web access path should simply be a dummy path that is unlikely to be used by your website. Here, we used “/Efu6dunox0vieyelahch2eaf” for the example, but you can use any random string. You should not leave the default ‘/‘ here because that would prevent your website from working correctly.
  • Deployment directory: /private/postgres1/sureapp – If you have changed the base data directory for PostgreSQL in the script above, you should enter the correct path here.
  • Start command: /home/example/private/postgres1/start.sh – Here, you have to replace “example” with the actual username of your hosting account.

create_app_form_postgres1.png

After you create and enable the app, you will be able to use the new PostgreSQL database server.

Using the Command Line Interface of the WebApps Platform

WebApps projects can be manipulated with the sureapp command-line client. To create and start the new PostgreSQL project, you should use the following commands:

sureapp project create \
    --engine "custom" \
    --engine-version "-" \
    --release-dir "$pg_app_dir/sureapp" \
    --start-cmd "$pg_app_dir/start.sh" \
    "$sureapp_project"
sureapp service manage --enable "$sureapp_project"
sureapp service manage --start "$sureapp_project"

After running these commands, the PostgreSQL server will be running and you will be able to use it.

Creating Databases and Roles

Once the server is running, you should set up a new user role and a database for your application. To do that, you can use the following commands over SSH:

. "/home/$USER/.bashrc"  # For $PGHOST
createuser -e -DEPRS "pgusername" createdb -e -O "pgusername" "pgdatabase"

You should replace the username and the database name in the example with the actual details you are going to set up in your application.

Backups

We create automatic system backups every 12 hours so that you don’t have to worry about data loss. These backups allow you to restore your data from backup if anything goes wrong with your site.

Database engines like PostgreSQL and MySQL store data in a special way on the server, so extra care must be taken in order to ensure backup archives are consistent and usable.

For MySQL, which is integrated with our hosting environment, this is already done automatically by the Control Panel. All MySQL data is backed up at regular intervals by our system and it can be easily restored using the “Restore” page of the Control Panel.

For PostgreSQL databases running on the WebApps platform, you have to set up a backup procedure separately. The following code will create two scripts in the WebApps project, backup.sh and restore.sh, that will take care of backups (note that if you have used our quick setup script, these files are already created for you):

mkdir -m 0700 "$pg_app_dir/backup"

cat <<BACKUP_SH > "$pg_app_dir/backup.sh"
#!/bin/sh
set -e
die() { printf "%s\n" "\$*" 1>&2 && exit 1; }
PGPASSFILE="$pg_app_dir/.pgpass"
export PGPASSFILE
"$pg_install_dir/bin/pg_dumpall" --clean --host "$pg_app_dir/run" | gzip --stdout -- > "$pg_app_dir/backup/pgdump.sql.gz" || die "PostgreSQL backup failed: $sureapp_project"
BACKUP_SH
chmod 700 "$pg_app_dir/backup.sh"

cat <<RESTORE_SH > "$pg_app_dir/restore.sh"
#!/bin/sh
set -e
die() { printf "%s\n" "\$*" 1>&2 && exit 1; }
PGPASSFILE="$pg_app_dir/.pgpass"
export PGPASSFILE
archive="$pg_app_dir/backup/pgdump.sql.gz"
[ -f "\$archive" ] || die "Backup file does not exist: \$archive"
zgrep -m1 "Dumped" "\$archive" || die "Backup file does not contain PostgreSQL data: \$archive"
gzip --decompress --stdout "\$archive" | "$pg_install_dir/bin/psql" --quiet --host "$pg_app_dir/run" postgres
RESTORE_SH
chmod 700 "$pg_app_dir/restore.sh"

After the scripts are created, you can set up a cron job that runs the backup.sh script every 12 hours. This can be done on the “Cron Jobs” page of the Control Panel.

This cron job will overwrite the pgdump.sql.gz backup archive every time. This way, each new system backup will contain the newest copy of the file.

Hopefully, you won’t have to use the restore.sh script. If you do, however, it will drop the current data in your PostgreSQL instance and will restore the data from the pgdump.sql.gz archive.

To restore from a particular backup, you can restore the pgdump.sql.gz file from one of the system backups using the “Restore” page of the Control Panel. After that, running restore.sh on the command line will restore the data from the archive into your PostgreSQL instance:

./restore.sh
PHP Configuration

If you are going to use a PHP application with PostgreSQL, you have to update the php.ini configuration file. You can skip this step if you are not going to use PHP.

PHP can use two libraries to connect to PostgreSQL. They are the PostgreSQL database extension and the more abstract PDO driver for PostgreSQL.

You have to enable the correct PHP extension depending on the application you want to use via the  Control Panel -> PHP Settings section by following these steps:

  1. Click on the Manage button next to the domain/subdomain where you want to use ImageMagick.
  2. Check the box next to the PostgreSQL or PDO_PGSQL extension from the Extensions section.
  3. Click on the Save changes button.

The extensions can also be activated by manually adding the respective line listed below to a PHP configuration file (php.ini):

PostgreSQL extension:

extension = pgsql.so

PDO driver for PostgreSQL:

extension = pdo_pgsql.so

Instructions on how to change other PHP settings for your account are available in our Changing PHP settings article.

Enabling Remote Connections

By default, PostgreSQL is configured to listen only to local connections. There is a way to enable remote connections if you wish to connect to your PostgreSQL server from a remote server or a graphical user interface (GUI) administration tool for PostgreSQL, such as pgAdmin. In order to enable remote connections, you need to update two configuration files:

  • pgdata/postgresql.conf
  • pgdata/pg_hba.conf

 In the pgdata/postgresql.conf file, you need to edit the following lines:

listen_addresses = ” # what IP address(es) to listen on;
port = 5432                             # (change requires restart)

You need to set the “listen_address” variable to “*”, and the “port” variable to the port of your WebApp. You can find the port of the WebApp in the “WebApps” section of the hosting Control Panel.

In the pgdata/pg_hba.conf file, you need to add the following line at the end:

host all all 0.0.0.0/0 md5

This code will configure the PostgreSQL server to accept connections from any remote location given that they provide a valid username and password. If you wish, you can configure the server to accept connections only from a specific IP address. For instance, to allow connections from the 123.123.123.123 IP address, you need to use the following line instead:

host all all 123.123.123.123/32 md5

You should then restart the WebApp through the “WebApps” section of the hosting Control Panel, and you will be able to connect to the server from a remote location. 

Note: Updating the port in the configuration file of PostgreSQL will break the functionality of applications, such as psql, createuser, and createdb. You will still be able to use them by defining the new port in the following way:
psql -p <the WebApp port>

In this tutorial, we will show you how to configure a Django project on your hosting account that uses PostgreSQL as the database backend using the WebApps platform.

If you do not see a WebApps section in the Control Panel of your hosting account, this tutorial may not be suitable for your particular hosting environment. Please contact our support team for more information.

You need SSH access to the server in order to make the changes described in this tutorial. If you haven’t set up SSH for your account yet, you should do this now.

Note that you should also enable both “Network tools” and “Compiling tools” on the SSH Access page of the Control Panel of your hosting account.

Quick Setup

If you want to quickly set up a Django project, you should first set up a PostgreSQL instance. We would recommend that you use the shell script from the Quick Setup section at the beginning of the article. It will configure PostgreSQL and it will set up the environment of your hosting account for installing Django.

After PostgreSQL is running in your account, you can download this Django setup shell script to your account and run it. The script will set up the WebApps project for your Django site.

Note that the Django setup script will automatically configure the PostgreSQL login details for your Django application, so you don’t have to do this manually. You can simply run the two scripts in sequence:

# Set up PostgreSQL
setup_postgresql.sh

# This sets up $PGHOST in the shell environment
. ~/.bashrc

# Set up Django
mv 4168.sh setup_django.sh
chmod 755 setup_django.sh
./setup_django.sh

In that case, you can skip to the “Running the Django Website” section of this article.

Installation

Before you start the installation, you have to make sure that you have a running instance of PostgreSQL in your account and that the $PGHOST environment variable is set in your shell. There is more information about this in the Running a PostgreSQL Instance article. The quick setup script can take care of that for you.

After that, you can create the directory structure of your new Django site:

sureapp_project="django1"
django_project_dir="/home/$USER/private/$sureapp_project"
mkdir -p "$django_project_dir/sureapp"

Then, set up the database details:

[ -z "$PGHOST" ] && . /home/$USER/.bashrc
if [ -n "$PGHOST" ]
then
    pguser="$sureapp_project"
    pgpass="$(pwgen 24 1)"
    pgdb="${sureapp_project}_db"
    printf "CREATE ROLE %s PASSWORD '%s' NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;" "$pguser" "$pgpass" | psql postgres
    createdb --owner "$pguser" "$pgdb" && printf "Database %s created successfully.\n" "$pgdb"
fi
virtualenv

For Python applications like Django, it is common to create an isolated environment for the application. You can do this with virtualenv:

mkdir -p "/home/$USER/.local/bin"
grep -q '^PATH=.*/.local/bin' "/home/$USER/.bashrc" || printf '\nPATH="/home/%s/.local/bin:$PATH"\nexport PATH\n' "$USER" >> "/home/$USER/.bashrc"
PATH="/home/$USER/.local/bin:$PATH"
export PATH
pip3 install virtualenv
virtualenv --system-site-packages -p /usr/bin/python3 "$django_project_dir/venv"
. "$django_project_dir/venv/bin/activate"

This way, all Python dependencies will be used only by your site.

Python Dependencies

You can now continue to installing the software dependencies of your Django site.

pip3 install psycopg2 whitenoise gunicorn Django
  • psycopg2 is a PostgreSQL database adapter;
  • whitenoise is a static files server, particularly suitable for Django;
  • gunicorn is a robust and performant WSGI server for production use;
  • Django is the package that contains the Django framework.
Django Project

At this point, you can set up the Django project and configure it:

django-admin startproject "$sureapp_project" "$django_project_dir"
django_project_settings_file="$django_project_dir/$sureapp_project/settings.py"
sed -i 's/^DEBUG = .*/DEBUG = False/' "$django_project_settings_file"
sed -i "s/^ALLOWED_HOSTS = .*/ALLOWED_HOSTS = ['localhost']/" "$django_project_settings_file"
cat <<POSTGRES_CONFIG >> "$django_project_settings_file"
DATABASES['default'] = {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': '$pgdb',
    'USER': '$pguser',
    'PASSWORD': '$pgpass',
    'HOST': '$PGHOST',
}
POSTGRES_CONFIG
cat <<STATICFILES_CONF >> "$django_project_settings_file"
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MIDDLEWARE.append('whitenoise.middleware.WhiteNoiseMiddleware')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_CONF
python3 "$django_project_dir/manage.py" migrate
python3 "$django_project_dir/manage.py" collectstatic
Creating the WebApps Project

Here, you have to create the WebApps project. This is necessary because it will determine the port on which your Django application will listen for requests.

sureapp project create \
    --engine "custom" \
    --engine-version "-" \
    --release-dir "$django_project_dir/sureapp" \
    --start-cmd "$django_project_dir/start.sh" \
    "$sureapp_project"
WSGI Server

Gunicorn is a robust and performant WSGI server meant for production use.

The easiest way to start the WSGI server is to use a wrapper shell script:

wsgi_port="$(sureapp project list | grep "$sureapp_project" | awk '{print $5}')"
cat <<START_SH > "$django_project_dir/start.sh"
#!/bin/sh
cd "$django_project_dir"
. "$django_project_dir/venv/bin/activate"
exec gunicorn -b "127.0.0.1:$wsgi_port" -w 4 "$sureapp_project.wsgi:application"
START_SH
chmod 0700 "$django_project_dir/start.sh"
Running the Django Website

WebApps Project

You now have to complete the configuration of the WebApps project in order to set up the URL where the application will be accessible.

The WebApps project is already created, so you have to click on the “Edit” icon in order to modify its settings:

apps_list-edit.png

You should set up the domain and subdomain fields:

edit_app-url.png

If you want to put your Django application on a separate subdomain, you can create one on the Subdomains page of the Control Panel.

Finally, you have to enable the application to run it:

edit_app_saved-enable.png

Management Script

Although it is not required, it is convenient to create a simple wrapper script to make managing the Django application from the command line easier. This script will take care of setting up the environment for you so that you don’t have to do it every time you want to use the manage.py script in the installation directory of Django.

cat <<MANAGE_SH > "$django_project_dir/manage.sh"
#!/bin/sh
. "$django_project_dir/venv/bin/activate"
exec python3 "$django_project_dir/manage.py" "\$*"
MANAGE_SH
chmod 0700 "$django_project_dir/manage.sh"
ln -s "$django_project_dir/manage.sh" "/home/$USER/.local/bin/manage-$sureapp_project"

With this wrapper script, you can log in over SSH and directly run any command in your Django project. For example, assuming that you named the project django1 as in this example, you can use the following command to see what management options are available:

manage-django1 help
Logging In

The installation script creates a wrapper shell script that allows you to manage your Django project directly on the command line, without having to first activate the virtualenv environment separately.

For example, you can create an administrative username for your Django project like this (assuming the project is named django1):

manage-django1 createsuperuser

After you fill out the prompts, you will be able to log in as the administrator of your new Django website.

This tutorial will show you how to install and run the InfluxDB database engine within a web app.

If you do not have a WebApps section in the Control Panel of your account, then this tutorial is not suitable for your particular hosting environment. You can get in touch with us if you need further assistance.

The official InfluxDB documentation can be found at https://docs.influxdata.com/influxdb/v1.8/.

In this guide, InfluxDB will be installed in the /home/$USER/private/influxdb directory on your account. You will need to replace $USER with the actual user name of your account. This user name is listed in the left pane of the account’s Control Panel.

1. Create a directory for your InfluxDB installation called influxdb in the /private directory on your account. You can create directories through the File Manager in the Control Panel of your account. It is also recommended creating a separate subdomain for each App. You can create subdomains through the Subdomains section of the Control Panel.

2. Create an App for your InfluxDB instance through the WebApps section of the account’s Control Panel.

Please use the following settings:

Deployment directory: private/influxdb
Start command: sh /home/$USER/private/influxdb/start.sh

3. Make sure all options are enabled in the SSH Access section of the account’s Control Panel. Next, log in to your account via SSH. You can check our online documentation for more information on doing this:

  • Logging Into Your Account via SSH using Putty
  • Logging Into Your Account via SSH using Terminal in Mac OS

To navigate to the /home/$USER/private/influxdb directory, run the following command:

cd ~/private/influxdb

4. Download and extract the latest stable InfluxDB release from the official website. You can find the latest stable release at https://portal.influxdata.com/downloads/. You can use wget to download the archive file directly on the server, and tar to extract the archive:

wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.1_linux_amd64.tar.gz
tar xvfz influxdb-1.8.1_linux_amd64.tar.gz

5. Create a file called start.sh in the /home/$USER/private/influxdb directory with executable permissions and the following content:

#!/bin/bash
cd /home/$USER/private/influxdb
/home/$USER/private/influxdbprivate/influxdb/influxdb-1.8.1-1/usr/bin/influxd –config /home/$USER/private/influxdb/influxdb-1.8.1-1/etc/influxdb/influxdb.conf

6. Update the configuration file at ~/private/influxdb/influxdb-1.8.1-1/etc/influxdb/influxdb.conf. There, edit the following settings:

[meta]
dir = “/home/$USER/private/influxdb/meta”

[data]
dir = “/home/$USER/private/influxdb/data”
wal-dir = “/home/$USER/private/influxdb/wal”

[http]
enabled = true
flux-enabled = true
bind-address = “:APP_PORT”

You will need to replace APP_PORT with the port assigned to the application you need to create through the WebApps section in the Control Panel of the account:

7. Finally, run the InfluxDB app through the WebApps section in the Control Panel of the account.

In this guide, we will install and run Elasticsearch. For a number of selected hosting plans, it can be installed with a few clicks through the “App Installer” section of the hosting Control Panel. If you can’t find it in your App Installer, read ahead. Bear in mind that Elasticsearch consumes a lot of resources, so even if you can install it manually following the instructions below, it may not operate correctly depending on your hosting plan.

Due to the specifics of Elasticsearch, we will actually need to create two WebApps to complete our setup. To install and run Elasticsearch as a WebApp, please follow these steps.

Create the necessary directories and files
1. Create a subdomain.

You need to create a subdomain for your Elasticsearch WebApp through the Subdomains section of the Control Panel. In this guide, we will call the subdomain elastic-sub.

2. Create the necessary directories.

Create a directory for the Elasticsearch installation in the /private directory on your account. In this guide, we will call the directory elasticsearch_dir. You can easily create directories through the File Manager in the Control Panel of your account.

Create a directory for the Portholder WebApp in the /private directory on your account. In this guide, we will call the directory portholder_dir.

3. Create the WebApps.

Create a WebApp for Elasticsearch through the WebApps section of the Control Panel. Remember the port number assigned to the WebApp. Use the following settings:

Create another WebApp. This app will be used to reserve another port for Elasticsearch. We will call this WebApp Portholder. Remember the port assigned to the Portholder WebApp. We are going to use this port in the Elasticsearch configuration. Since we are not going to activate this WebApp, you can use any settings you wish, as long as there are no conflicts with existing WebApps. In this guide, we are using the the following settings:

Install and configure Elasticsearch
4. Download and extract the Elasticsearch installation package.

Log in to your account over SSH. Logging in over SSH is covered in the SSH section in our documentation. Then, navigate to the directory that you created for your Elasticsearch installation. You can do this by running the following command (make sure you replace the path in the command with the actual path to the directory you created for Elasticsearch):

cd ~/private/elasticsearch_dir

Use wget to download the latest Elasticsearch LINUX X86_64 package directly to your elasticsearch_dir. You can get the URL to the latest Elasticsearch package at the official Elasticsearch website. If you need to enable wget, you can do it through the SSH Access section of your account’s Control Panel.

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.2-linux-x86_64.tar.gz

Use tar to extract the archive:

tar -xzf elasticsearch-7.9.2-linux-x86_64.tar.gz

5. Configure Elasticsearch.

Create a start.sh file in your elasticsearch_dir directory with the following content:

#!/bin/bash
cd /home/username/private/elasticsearch_dir/elasticsearch-7.9.2/
export ES_JAVA_OPTS=”-Xms128m -Xmx128m”
exec ./bin/elasticsearch

Make sure you replace the path in the command with the actual path to the directory you created for Elasticsearch and the version number with the version corresponding to the package you downloaded. You need to replace username with the actual username of your account’s Control Panel. You can easily create and edit files through the File Manager in the Control Panel of your account.

Edit the following configuration file in the directory where Elasticsearch is extracted:

/home/username/private/elasticsearch_dir/elasticsearch-7.9.2/config/elasticsearch.yml

There, you need to remove the # symbol in front of the http.port setting, and replace the port number with the port assigned to the Elasticsearch WebApp you created at step 3. You also need to insert a new line for the transport.port setting. Since this setting requires a range, you will need to set the port assigned to the Portholder WebApp you created at step 3 as the beginning and the end of the range:

http.port: XXXX #Elasticsearch WebApp port
transport.port: YYYYY-YYYYY #Portholder WebApp port

Go back to the WebApps section of the Control Panel. There click on the edit button next to the Elasticsearch WebApp, and set the Elasticsearch WebApp start command to the following:

sh /home/username/private/elasticsearch_dir/start.sh

Make sure you replace the path in the command with the actual path to the start.sh file you created.

That’s it!

Once you start your WebApp, Elasticsearch should be running on the specified port.

In this tutorial, we will show you how to configure a Redis instance on your account using the WebApps platform.

If you do not see a WebApps section in the Control Panel of your hosting account, this tutorial may not be suitable for your particular hosting environment. Please contact our support team for more information.

You need SSH access to the server in order to make the changes described in this tutorial. If you haven’t set up SSH for your account yet, you should do this now.

Setup

Depending on your hosting plan, Redis may already be available. You can check if this is the case by running the following command over SSH:

redis-cli ping && echo "Redis is available!"

If there is no Redis instance available by default, you will receive an error message. In that case, you can set up a WebApps project to run your own Redis instance.

To do that, you should first create the configuration file for Redis by running the following commands:

sureapp_project="Redis"
redis_dir="/home/$USER/private/redis"
mkdir -pv "$redis_dir"

cat <<REDIS_CONF > $redis_dir/redis.conf
unixsocket $redis_dir/redis.sock
unixsocketperm 700
port 0
daemonize no
stop-writes-on-bgsave-error no
rdbcompression yes
maxmemory 64M
# how redis will evict old objects - least recently used
maxmemory-policy allkeys-lru
REDIS_CONF

After that, you can create and enable the WebApps project:

sureapp project create \
    --engine "custom" \
    --engine-version "-" \
    --release-dir "$redis_dir" \
    --start-cmd "/usr/bin/redis-server $redis_dir/redis.conf" \
    "$sureapp_project"
sureapp service manage --enable "$sureapp_project"
sureapp service manage --start "$sureapp_project"

At this point, Redis should already be up and running.

You can check that by pinging it using the redis-cli command-line tool:

redis-cli -s "$redis_dir/redis.sock" ping

You will receive a “PONG” reply if everything is working correctly.

In order to use your Redis server from your applications, you will just have to configure them to use the file system socket to connect. The path to the socket should be /home/$USER/private/redis/redis.sock.

react-logo-transparent.png

This tutorial will show you how to set up and run your React app using npm and serve.

If you do not have a WebApps section in your hosting Control Panel, then this tutorial is not suitable for your particular hosting environment. You can submit a support ticket through our ticketing system if you need assistance.

React (also called ReactJS or React.js) is a popular JavaScript library for building highly interactive user interfaces. It can be easily installed via SSH with a single command:

npm install react

This command has to be executed under your project’s sureapp shell. You can find more information about using the sureapp CLI in our Sureapp – app management CLI tool article.

There are certain prerequisites to running a React app:

1) You should choose a location in your Private directory where the application will reside, e.g. /home/USERNAME/private/my_app. In this tutorial, we will place the application in /home/USERNAME/private/react/calculator.
2) You should create an app via the WebApps section in your Control Panel and use the path to your application as deployment directory.
3) You have to access your account via SSH and use the “sureapp” command-line interface to log in to your app’s shell and install React, as well as any other dependencies.
4) You will then have to complete the app’s configuration and make final changes via the WebApps section, so the app can run using React + Serve.

Let’s describe these steps in more detail. First, let’s pick an app which depends on React. We’ll use one of the examples listed on the official website of React (https://reactjs.org/community/examples.html) – Calculator.
1. Log in to your account via SSH and navigate to the directory in which you will place your app:

username@s501:/home/username$ cd ~/private/react

2. Download Calculator:

username@s501:/home/username/private/react$ git clone https://github.com/ahfarmer/calculator.git

Calculator will be installed under ~/private/react/calculator. At this point, you will have to run “npm install” to install all dependencies.

3. Create a new app

To use “npm”, however, you need to create a new app via WebApps in your Control Panel:

Create a new app - React

Leave the “Start command” field empty for now. Click Create but don’t enable the app.

4. Enter your project’s shell via SSH by running the following command:

username@s501:/home/username/private/react$ sureapp project shell ReactProject

Then run the following command to install all modules on which the application depends (including React):

username@s501 [ReactProject:node/lts] /home/username/private/react/calculator$ npm install

6. Test your app

Run the following command via SSH to start the development server:

username@s501 [ReactProject:node/lts] /home/username/private/react/calculator$ npm start

Visit your app’s URL (i.e. http://react-project.mydomain.com/) to check if the app is running as expected.

Then cancel the SSH command (Ctrl+C) to stop the development server and edit the app’s package.json file, located in the app’s document root.

Change the value of the “homepage” variable from “http://ahfarmer.github.io/calculator” to the app’s real URL – “http://react-project.mydomain.com”. A universal solution would be to just enter “/” as homepage, so the app can work properly regardless of the URL on which it is running.

7. Prepare the application for production mode.

Run these two commands in the project’s shell:

username@s501 [ReactProject:node/lts] /home/username/private/react/calculator$ npm run build
username@s501 [ReactProject:node/lts] /home/username/private/react/calculator$ npm install -g serve

Rut the following command to start the production server via SSH and test the app:

username@s501 [ReactProject:node/lts] /home/username/private/react/calculator$ serve -s build

Visit http://react-project.mydomain.com/ to verify that everything is running fine.

Shut down the production server by stopping the running process (Ctrl+C).

8) Enable your app and run it in production mode

Edit the app in the WebApps section of the Control Panel. Enter the following as “Start command”:

serve -s build

 edit-react-app.png

Enable the app and visit http://react-project.mydomain.com/ to check if everything is operating normally.

Memcached is a high-performance, distributed memory object caching system. It acts as a in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering. Memcached can improve the speed of your website or application by providing quick access to frequently accessed data.

This tutorial will show you how to use Memcached from within a web app.

If you do not have a WebApps section in the Control Panel of your account, then this tutorial is not suitable for your particular hosting environment. You can get in touch with us if you need further assistance.

The official Memcached documentation can be found at https://github.com/memcached/memcached/wiki.

If you follow this guide, Memcached will be installed in the /home/$USER/private/memcached directory on your account. You will need to replace $USER with the actual user name of your account. This user name is listed in the left pane of the account’s Control Panel.

1. Create a directory for your Memcached installation

In this guide, the directory will be called memcached in the /private directory on the account. You can create directories through the File Manager in the Control Panel of your account, or by clicking on the folder icon next to the “Deployment directory” filed in the WebApps section of the Control Panel when creating a new app and using the “Create” button in the dialog.

Create a new directory

Create a new directory

2. Create an App

You can create an App for Memcached instance through the WebApps section of the account’s Control Panel.

Create a webapp for memcached

Please use the following settings:

Engine: Custom
Name: memcached
Domain: a domain of your choice
Subdomain: a subdomain of your choice
Web access path: /does-not-exist/memcached
Port: Port number is assigned automatically.
Memory: Account default value
Deployment directory: /private/memcached
Start command: /usr/bin/memcached -m 64 -s /home/$USER/private/memcached.sock -a 700 -c 256

It is important to set a non-existing directory in the “Web access path” field. Otherwise, the web app might interfere with the operation of your website.

3. Activate the App

You need to activate the app by hitting the red button next to the App’s name.

Activate the memcached app

4. Enable the Memcached PHP extension

You need to enable the Memcached PHP extension in the subdomain where you need to use Memcached. You can enable the extension through the PHP Settings section in the Control Panel of the account. There, click on the “Manage” button next to the subdomain. The button to enable the extension is on the next page.

Enable the memached PHP extension

5. Configure your application or website

You need to configure your application or website to access Memcached via a socket. The socket for accessing Memcached is:

/home/$USER/private/memcached.sock

Don’t forget to replace $USER with the actual username of the hosting account.

Instructions on how to configure a specific application should be provided by its vendor.