Bitnami Parse Server for Amazon Web Services

Description

Parse is a platform that enables users to add a scalable and powerful backend to launch a full-featured app for iOS, Android, JavaScript, Windows, Unity, and more.

First steps with the Bitnami Parse Server Stack

Welcome to your new Bitnami application running on Amazon Web Services! Here are a few questions (and answers!) you might need when first starting with your application.

What is the administrator username set for me to log in to the application for the first time?

Username: user

What is the administrator password?

What SSH username should I use for secure shell access to my application?

SSH username: bitnami

How to start or stop the servers?

Each Bitnami stack includes a control script that lets you easily stop, start and restart servers. The script is located at /opt/bitnami/ctlscript.sh. Call it without any service name arguments to start all services:

$ sudo /opt/bitnami/ctlscript.sh start

Or use it to restart a single service, by passing the service name as argument. For example, if the stack uses the Apache Web server, use the command below to restart it:

$ sudo /opt/bitnami/ctlscript.sh restart apache

Or, if the stack uses the Nginx server, use the command below to restart it:

$ sudo /opt/bitnami/ctlscript.sh restart nginx

Use this script to stop all services:

$ sudo /opt/bitnami/ctlscript.sh stop

Restart the services by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh restart

Obtain a list of available services and operations by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh  

Updating the IP address or hostname

Parse Server requires updating the IP address/domain name if the machine IP address/domain name changes. The bnconfig tool also has an option which updates the IP address, called –machine_hostname (use –help to check if that option is available for your application). Note that this tool changes the URL to http://NEW_DOMAIN/parse.

$ sudo /opt/bitnami/apps/parse/bnconfig --machine_hostname NEW_DOMAIN

If you have configured your machine to use a static domain name or IP address, you should rename or remove the /opt/bitnami/apps/parse/bnconfig file.

$ sudo mv /opt/bitnami/apps/parse/bnconfig /opt/bitnami/apps/parse/bnconfig.disabled
NOTE: Be sure that your domain is propagated. Otherwise, this will not work. You can verify the new DNS record by using the Global DNS Propagation Checker and entering your domain name into the search field.

You can also change your hostname by modifying it in your hosts file. Enter the new hostname using your preferred editor.

$ sudo nano /etc/hosts
  • Add a new line with the IP address and the new hostname. Here's an example. Remember to replace the IP-ADDRESS and DOMAIN placeholders with the correct IP address and domain name.

    IP-ADDRESS DOMAIN

How to create a full backup of Parse Server?

Backup

The Bitnami Parse Server Stack is self-contained and the simplest option for performing a backup is to copy or compress the Bitnami stack installation directory. To do so in a safe manner, you will need to stop all servers, so this method may not be appropriate if you have people accessing the application continuously.

Follow these steps:

  • Change to the directory in which you wish to save your backup:

      $ cd /your/directory
    
  • Stop all servers:

      $ sudo /opt/bitnami/ctlscript.sh stop
    
  • Create a compressed file with the stack contents:

      $ sudo tar -pczvf application-backup.tar.gz /opt/bitnami
    
  • Restart all servers:

      $ sudo /opt/bitnami/ctlscript.sh start
    

You should now download or transfer the application-backup.tar.gz file to a safe location.

Restore

Follow these steps:

  • Change to the directory containing your backup:

      $ cd /your/directory
    
  • Stop all servers:

      $ sudo /opt/bitnami/ctlscript.sh stop
    
  • Move the current stack to a different location:

      $ sudo mv /opt/bitnami /tmp/bitnami-backup
    
  • Uncompress the backup file to the original directoryv

      $ sudo tar -pxzvf application-backup.tar.gz -C /
    
  • Start all servers:

      $ sudo /opt/bitnami/ctlscript.sh start
    

If you want to create only a database backup, refer to these instructions for MySQL and PostgreSQL.

How to upload files to the server with SFTP?

Although you can use any SFTP/SCP client to transfer files to your server, the link below explains how to configure FileZilla (Windows, Linux and Mac OS X), WinSCP (Windows) and Cyberduck (Mac OS X). It is required to use your server's private SSH key to configure the SFTP client properly. Choose your preferred application and follow the steps in the link below to connect to the server through SFTP.

How to upload files to the server

How to enable HTTPS support with SSL certificates?

NOTE: The steps below assume that you are using a custom domain name and that you have already configured the custom domain name to point to your cloud server.

Bitnami images come with SSL support already pre-configured and with a dummy certificate in place. Although this dummy certificate is fine for testing and development purposes, you will usually want to use a valid SSL certificate for production use. You can either generate this on your own (explained here) or you can purchase one from a commercial certificate authority.

Once you obtain the certificate and certificate key files, you will need to update your server to use them. Follow these steps to activate SSL support:

  • Use the table below to identify the correct locations for your certificate and configuration files.

    Variable Value
    Current application URL https://[custom-domain]/
      Example: https://my-domain.com/ or https://my-domain.com/appname
    Apache configuration file /opt/bitnami/apache2/conf/bitnami/bitnami.conf
    Certificate file /opt/bitnami/apache2/conf/server.crt
    Certificate key file /opt/bitnami/apache2/conf/server.key
    CA certificate bundle file (if present) /opt/bitnami/apache2/conf/server-ca.crt
  • Copy your SSL certificate and certificate key file to the specified locations.

NOTE: If you use different names for your certificate and key files, you should reconfigure the SSLCertificateFile and SSLCertificateKeyFile directives in the corresponding Apache configuration file to reflect the correct file names.
  • If your certificate authority has also provided you with a PEM-encoded Certificate Authority (CA) bundle, you must copy it to the correct location in the previous table. Then, modify the Apache configuration file to include the following line below the SSLCertificateKeyFile directive. Choose the correct directive based on your scenario and Apache version:

    Variable Value
    Apache configuration file /opt/bitnami/apache2/conf/bitnami/bitnami.conf
    Directive to include (Apache v2.4.8+) SSLCACertificateFile "/opt/bitnami/apache2/conf/server-ca.crt"
    Directive to include (Apache < v2.4.8) SSLCertificateChainFile "/opt/bitnami/apache2/conf/server-ca.crt"
NOTE: If you use a different name for your CA certificate bundle, you should reconfigure the SSLCertificateChainFile or SSLCACertificateFile directives in the corresponding Apache configuration file to reflect the correct file name.
  • Once you have copied all the server certificate files, you may make them readable by the root user only with the following commands:

     $ sudo chown root:root /opt/bitnami/apache2/conf/server*
    
     $ sudo chmod 600 /opt/bitnami/apache2/conf/server*
    
  • Open port 443 in the server firewall. Refer to the FAQ for more information.

  • Restart the Apache server.

You should now be able to access your application using an HTTPS URL.

How to create an SSL certificate?

You can create your own SSL certificate with the OpenSSL binary. A certificate request can then be sent to a certificate authority (CA) to get it signed into a certificate, or if you have your own certificate authority, you may sign it yourself, or you can use a self-signed certificate (because you just want a test certificate or because you are setting up your own CA).

  • Create your private key (if you haven't created it already):

     $ sudo openssl genrsa -out /opt/bitnami/apache2/conf/server.key 2048
    
  • Create a certificate:

     $ sudo openssl req -new -key /opt/bitnami/apache2/conf/server.key -out /opt/bitnami/apache2/conf/cert.csr
    
    IMPORTANT: Enter the server domain name when the above command asks for the "Common Name".
  • Send cert.csr to the certificate authority. When the certificate authority completes their checks (and probably received payment from you), they will hand over your new certificate to you.

  • Until the certificate is received, create a temporary self-signed certificate:

     $ sudo openssl x509 -in /opt/bitnami/apache2/conf/cert.csr -out /opt/bitnami/apache2/conf/server.crt -req -signkey /opt/bitnami/apache2/conf/server.key -days 365
    
  • Back up your private key in a safe location after generating a password-protected version as follows:

     $ sudo openssl rsa -des3 -in /opt/bitnami/apache2/conf/server.key -out privkey.pem
    

    Note that if you use this encrypted key in the Apache configuration file, it will be necessary to enter the password manually every time Apache starts. Regenerate the key without password protection from this file as follows:

     $ sudo openssl rsa -in privkey.pem -out /opt/bitnami/apache2/conf/server.key
    

Find more information about certificates at http://www.openssl.org.

How to debug Apache errors?

Once Apache starts, it will create two log files at /opt/bitnami/apache2/logs/access_log and /opt/bitnami/apache2/logs/error_log respectively.

  • The access_log file is used to track client requests. When a client requests a document from the server, Apache records several parameters associated with the request in this file, such as: the IP address of the client, the document requested, the HTTP status code, and the current time.

  • The error_log file is used to record important events. This file includes error messages, startup messages, and any other significant events in the life cycle of the server. This is the first place to look when you run into a problem when using Apache.

If no error is found, you will see a message similar to:

Syntax OK

How to force HTTPS redirection?

Add the following to the top of the /opt/bitnami/apps/parse/conf/httpd-prefix.conf file:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]

After modifying the Apache configuration files, restart Apache to apply the changes.

How to debug Apache errors?

Once Apache starts, it will create two log files at /opt/bitnami/apache2/logs/access_log and /opt/bitnami/apache2/logs/error_log respectively.

  • The access_log file is used to track client requests. When a client requests a document from the server, Apache records several parameters associated with the request in this file, such as: the IP address of the client, the document requested, the HTTP status code, and the current time.

  • The error_log file is used to record important events. This file includes error messages, startup messages, and any other significant events in the life cycle of the server. This is the first place to look when you run into a problem when using Apache.

If no error is found, you will see a message similar to:

Syntax OK

How to modify PHP settings and install PHP modules?

The PHP configuration file allows you to configure the modules enabled, the email settings or the size of the upload files. It is located at /opt/bitnami/php/etc/php.ini.

To install a PHP module, the typical process is to install the module (either via the package manager or through a manual build/install process) and then activate it in the above configuration file. Find instructions for installing specific PHP modules on the PHP page.

NOTE: Bitnami stacks already include a number of PHP modules, which are installed but not active. Before installing a new module, check that it is not already included. If it exists, simply enable it in the PHP configuration file.

After modifying the PHP configuration file, restart both Apache and PHP-FPM for the changes to take effect:

$ sudo /opt/bitnami/ctlscript.sh restart apache
$ sudo /opt/bitnami/ctlscript.sh restart php-fpm

How to access RockMongo?

For security reasons, RockMongo is accessible only when using 127.0.0.1 as the hostname. To access it from a remote system, you must create an SSH tunnel that routes requests to the Apache Web server from 127.0.0.1. This implies that you must be able to connect to your server over SSH in order to access these applications remotely.

IMPORTANT: Before following the steps below, ensure that your Apache and MongoDB servers are running.
NOTE: The steps below suggest using port 8888 for the SSH tunnel. If this port is already in use by another application on your local machine, replace it with any other port number greater than 1024 and modify the steps below accordingly. Similarly, if you have enabled Varnish, your stack's Apache Web server might be running on port 81. In this case, modify the steps below to use port 81 instead of port 80 for the tunnel endpoint.

Windows

To access the application using your Web browser, create an SSH tunnel, as described below.

  • Download PuTTY and make sure you can log in to the server console with it following the instructions in the FAQ. Once you have confirmed you are able to log in successfully, log back out.

  • Reconnect to the server using PuTTY, this time adapting the steps to include an additional SSH tunnel. When configuring the new SSH session in PuTTY, additionally navigate to the "Connection -> SSH -> Tunnels" section and create a secure tunnel by forwarding port 80 on the server to port 8888 on the local host (127.0.0.1 or localhost).

  • Click the "Add" button to add the secure tunnel configuration to the session. Here is an example:

    PuTTY configuration

  • Go back to the "Session" section and save your changes by clicking the "Save" button.

  • Click the "Open" button to open an SSH session to the server. The SSH session will now include a secure SSH tunnel between the two specified ports.

While the tunnel is active, you should be able to access the RockMongo console through the secure SSH tunnel you created, by browsing to http://127.0.0.1:8888/rockmongo.

To log in, use username root and the application password from the detail page for your cloud server.

Here is an example of what you should see:

RockMongo

If you are unable to access RockMongo, verify that the SSH tunnel was created by checking the PuTTY event log (accessible via the "Event Log" menu):

PuTTY configuration

Linux and Mac OS X

To access the application using your Web browser, create an SSH tunnel, as described below.

  • Open a new terminal window on your local system (for example, using "Finder -> Applications -> Utilities -> Terminal" in Mac OS X or the Dash in Ubuntu).

  • Make sure you can log in to the server console following the instructions in the FAQ. Once you have confirmed you are able to log in successfully, log back out.

  • Run the following command to configure the SSH tunnel. Remember to replace SERVER-IP with the public IP address or hostname of your server. Enter your SSH password when prompted.

     $ ssh -N -L 8888:127.0.0.1:80 bitnami@SERVER-IP
    

    If you are using a private key to connect to the server, use the following command instead, remembering to replace KEYFILE with the path to your private key and SERVER-IP with the public IP address or hostname of your server:

     $ ssh -N -L 8888:127.0.0.1:80 -i KEYFILE bitnami@SERVER-IP
    
    NOTE: If successful, the above commands will create an SSH tunnel but will not display any output on the server console.

While the tunnel is active, you should be able to access the RockMongo console through the secure SSH tunnel you created, by browsing to http://127.0.0.1:8888/rockmongo.

To log in, use username root and the application password from the detail page for your cloud server.

Here is an example of what you should see:

RockMongo

How to add your custom cloud code to your Parse Server stack?

There are some cases where you may want to develop your own cloud code, so as to make Parse work in a non-standard way, or make it perform a desired operation when certains conditions are met. You can find more information about this in the Parse official documentation. In order to add your custom cloud code to your Parse Server stack, please follow the steps below:

  • Stop the Parse server:

       $ sudo /opt/bitnami/ctlscript.sh stop parse
    
  • Create a cloud directory in /opt/bitnami/apps/parse/htdocs/

       $ sudo mkdir -p /opt/bitnami/apps/parse/htdocs/cloud
    
  • Edit the script at /opt/bitnami/apps/parse/htdocs/

       $ cd /opt/bitnami/apps/parse/htdocs/
       $ vim server.js
    
  • Edit the ParseServer variable and modify the cloud object following the example below:

       var api = new ParseServer({
         databaseURI: "mongodb://root:MONGODB_PASSWORD@127.0.0.1:27017/bitnami_parse",
         cloud: "./cloud/main.js",
         appId: "APP_ID",
         masterKey: "MASTER_KEY",
         fileKey: "FILE_KEY",
         serverURL: 'http://SERVER-IP:80/parse'
         });
    

Remember to replace the MONGODB_PASSWORD, APP_ID, MASTER_KEY, FILE_KEY and SERVER-IP placeholders with your MongoDB administrator account password, application ID, application master key, application file key and server's public IP address respectively.

  • Restart the Parse server:

       $ sudo /opt/bitnami/ctlscript.sh restart parse
    

How to authenticate requests against the Parse API?

When accessing the Bitnami Parse Server Stack via a browser or other HTTP client, you may see a response that states:

{"error":"unauthorized"}

This occurs if your request does not include the necessary credentials. To resolve this, first obtain your Application ID and Master Key from the /opt/bitnami/apps/parse/htdocs/server.js file. Then, issue a request containing these credentials.

Here is a sample request to store a file:

$ curl -X POST -H "X-Parse-Application-Id: APP_ID" -H "X-Parse-Master-Key: MASTER_KEY" -H "Content-Type: text/plain" -d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' http://SERVER-IP/parse/classes/GameScore

Remember to replace the APP_ID and MASTER_KEY placeholders with the actual access credentials. Following this, execute the following request to obtain information about the file stored previously:

$ curl -X GET -H "X-Parse-Application-Id: APP_ID" http://SERVER-IP/parse/classes/GameScore

How to enable HTTP authentication for the Parse Dashboard?

To enable basic HTTP authentication for the Parse Dashboard, please follow the steps below:

  • Stop the Parse server:

       $ sudo /opt/bitnami/ctlscript.sh stop parse
    
  • Edit the script at /opt/bitnami/apps/parse/htdocs

       $ cd /opt/bitnami/apps/parse/htdocs
       $ vim server.js
    
  • Edit the dashboard variable and add a new object following the example below:

       var dashboard = new ParseDashboard({
           apps: [
               { 
                 ...
               }
           ],
           users: [
               {
                   user: 'USERNAME',
                   pass: 'PASSWORD'
               }
           ]          
    

    Remember to replace the USERNAME and PASSWORD placeholders with the desired access credentials, and ensure that there are no syntax errors, such as missing commas.

  • Restart the Parse server:

       $ sudo /opt/bitnami/ctlscript.sh restart parse
    

How to force HTTPS in the Bitnami Parse Server Stack?

When you design your own application and make requests to the Parse API you design, your Application ID will be sent in plaintext in API requests. This is dangerous, since anyone with bad intentions could sniff them and break into the application, or even worse, access confidential data from your clients.

To force HTTPS for all API requests, follow these steps:

  • Modify your /opt/bitnami/apps/parse/conf/httpd-vhosts.conf file so that it fits with this structure.

       <VirtualHost *:80>
           ServerName DOMAIN
           ServerAlias www.DOMAIN
           RewriteEngine On
           RewriteCond %{HTTPS} off
           RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L]
       </VirtualHost>
    
       <VirtualHost *:443>
           ServerName DOMAIN
           ServerAlias www.DOMAIN
           SSLEngine on
           SSLCertificateFile "/opt/bitnami/apps/parse/conf/certs/server.crt"
           SSLCertificateKeyFile "/opt/bitnami/apps/parse/conf/certs/server.key"
           Include "/opt/bitnami/apps/parse/conf/httpd-app.conf"
       </VirtualHost>
    

    Please remember to replace the DOMAIN placeholders with the corresponding domain name.

  • Open the Apache vhosts file at /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf and add the following line:

       Include "/opt/bitnami/apps/parse/conf/httpd-vhosts.conf"
    
  • Edit the serverURL variable property from both api and dashboard objects in the script found at /opt/bitnami/apps/parse/htdocs/server.js:

       serverURL: "https://SERVER-IP/parse",
    

    Please remember to replace the SERVER-IP placeholder with the corresponding public IP or domain name.

  • Restart the stack servers:

       $ sudo /opt/bitnami/ctlscript.sh restart 
    

Your application should now force HTTPS for all API requests correctly.

For more information about this process, refer to this section.

How to migrate an application from Parse's hosted service to the Bitnami Parse Server Stack?

To migrate an application from Parse's hosted service to the Bitnami Parse Server Stack, you must first migrate your data to the Bitnami Parse Server Stack's MongoDB instance, then migrate your application to use the Bitnami Parse Server Stack.

NOTE: The data migration tool used by Parse requires MongoDB v2.6.X or v3.0.X, and the failIndexKeyTooLong parameter set to false. The Bitnami Parse Server Stack is already configured with these requirements.

To migrate your data, follow these steps:

  • To let Parse access your database, open port 27017 in the server firewall. Refer to the FAQ for more information.

  • Ensure that you have sufficient storage space for the data. Parse's hosted service compresses data and Parse recommends having at least 10 times the amount of storage currently consumed by your hosted Parse database available prior to migration. You can find this information in your application's "Analytics -> Overview" page.

    Parse migration

  • Enable external connections for the MongoDB database server by editing the /opt/bitnami/mongodb/mongodb.conf file and changing the line below as follows:

       bind_ip = 0.0.0.0
    
  • Restart the MongoDB server:

       $ sudo /opt/bitnami/ctlscript.sh restart mongodb
    
  • Open the MongoDB database port in the server firewall. Refer to these instructions for more information.

  • Create an empty database to hold your application data, or use the existing bitnami_parse database included with the stack.

  • Use Parse's database migration tool to transfer your data. Log in to the Parse website and navigate to the "App Settings -> General" page. Click the "Migrate" button in the "App Management -> Migrate to external database" section.

    Parse migration

  • Enter the connection string for the MongoDB database server in the form using the format below. Replace the USERNAME, PASSWORD, SERVER-NAME, SERVER-PORT and DATABASE-NAME with the correct values for the Bitnami Parse Server Stack:

       mongodb://USERNAME:PASSWORD@SERVER-NAME:SERVER-PORT/DATABASE-NAME
    

    The USERNAME specified in the connection string must have administrative privileges to the MongoDB instance, as the migration tool will set some parameters automatically during the process. The default SERVER-PORT for MongoDB is 27017.

    Parse migration

  • If your data has been migrated successfully, you should see something like this:

    Parse migration

  • Connect to the MongoDB instance in the Bitnami Parse Server Stack and browse through the collections in the newly-created database. Check the collection counts and do a few spot checks to verify that your data was migrated successfully.

The next step is to configure your application to use the Bitnami Parse Server Stack instead of the hosted Parse service. Follow the steps below:

  • Log in to the Parse website and navigate to the "App Settings -> Security & Keys" page.

  • Note the values of the "Application ID", "File Key" and "Master Key" settings.

    Parse migration

  • Edit the /opt/bitnami/apps/parse/htdocs/server.js file and insert the credentials from the previous steps, as shown below:

     ...
     // Specify the connection string for your mongodb database
     // and the location to your Parse cloud code
     var api = new ParseServer({
         databaseURI: 'mongodb://USERNAME:PASSWORD@SERVER-NAME:SERVER-PORT/DATABASE-NAME',
         cloud: './cloud/main.js',
         appId: 'APP-ID',
         masterKey: 'MASTER-KEY',
         fileKey: 'FILE-KEY'
     });
     ...
    
  • Restart the Parse server:

       $ sudo /opt/bitnami/ctlscript.sh restart parse 
    
  • Verify that saving and retrieving objects works using the command below. Remember to replace the APP-ID, MASTER-KEY and FILE-KEY placeholders with the correct values.

       $ curl -X POST -H "X-Parse-Application-Id: APP-ID" -H "X-Parse-Master-Key: MASTER-KEY" -H "Content-Type: text/plain" -d 'Hello, World!' http://SERVER-IP/parse/files/new.txt
    
  • Disable external connections for the MongoDB database server by editing the /opt/bitnami/mongodb/mongodb.conf file and changing the line below as follows:

       bind_ip = 127.0.0.1
    
  • Close port 27017 in the server firewall. Refer to the FAQ for more information.

Your application should now be able to connect to the Bitnami Parse Server Stack.

For more information about this process, refer to https://parse.com/docs/server/guide#migrating.

How to migrate an application exporting your data from Parse's hosted service?

You can export your data from parse. For that, you need to go to App Settings -> General -> Export app data.

Parse migration

You will receive a mail with a ZIP that contains your data in JSON format. Now, you can unzip it and import it into MongoDB. For example, if want to restore you CustomClass class, you could execute:

    $ mongoimport -u user -p password -d bitnami_parse -c CustomClass --file CustomClass.json

For more information about this process, please check the official documentation at https://parse.com/docs/rest/guide#data-exporting-your-data.

How to upgrade the Bitnami Parse Server Stack?

To upgrade the Bitnami Parse Server Stack to the latest version, follow the steps below:

  • Change to the root user:

      $ sudo su
    
  • Stop the Parse server:

       $ /opt/bitnami/ctlscript.sh stop parse
    
  • Update with npm:

      $ cd /opt/bitnami/apps/parse/htdocs
      $ npm update -g npm
      $ npm install parse-server parse-dashboard
      $ ../bnconfig --machine_hostname *SERVER-IP*
    

Remember to replace the SERVER-IP placeholder with the public IP of your machine.

  • Change file permissions:

       $ chown bitnami:daemon -R .
    
  • Restart the Parse server:

       $ /opt/bitnami/ctlscript.sh restart parse