Bitnami MEAN Stack (MongoDB, Express, Angular, Node.js) Redirected from Infrastructure Stacks/BitNami MEAN Stack

    The Bitnami MEAN Stack greatly simplifies the development and deployment of MongoDB and Node.js applications and their runtime dependencies. It includes the latest stable release of MongoDB, Express, Angular, Node.js, Git, PHP and RockMongo.

    How do I download and install MEAN Stack?

    Cloud Images

    Bitnami Cloud Images extend stack appliances to run in a cloud computing environment. You can run Bitnami applications on a pay-as-you-go basis, programmatically starting and stopping them. Bitnami Cloud Images are currently available for Amazon EC2Microsoft AzureVMware vCloud AirGooogle Cloud Platform, and DigitalOcean, with support for additional cloud environments planned for the future.

    Virtual Machine/Native Installer

    You can download the Bitnami MEAN Stack for your platform at http://bitnami.com/stack/mean. There are installers and virtual machines available for Windows, Mac OS X and Linux operating systems.

    The Bitnami MEAN Stack is distributed free of charge under the Apache 2.0 license.

    Which components are installed with MEAN Stack?

    The Bitnami MEAN Stack ships the components listed below. If you want to know which specific version of each component is bundled in the stack you are downloading, check the README.txt file in the download page or in the stack installation directory. You can also find more information about each component using the links below.

    Main components:

    • MongoDB database
    • Node.JS 
    • Express
    • AngularJS
    • Apache Web server
    • Git
    • PHP scripting languange (optional)
    • RockMongo web application management tool for MongoDB database (optional)

    What is the default installation directory?

    Cloud Images

    The default installation directory is /opt/bitnami.

    Virtual Machine

    The default installation directory is /opt/bitnami.

    Native Installer

    When using native installers, the default installation directory depends on the platform and can be changed during the installation:

    • Windows: C:\Bitnami\meanstack-VERSION (On previous versions, the default installation directory was C:\Program Files\BitNami Django Stack)
    • Mac OS X: /Applications/meanstack-VERSION
    • Linux: /home/user/meanstack-VERSION.

    How do I start and stop the servers?

    Each MEAN Stack ships several servers that must be started before you will be able to work with them. By default, the MongoDB database server and the Apache server are started after the installation.

    Cloud Images

    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 arguments to restart all services:

    $ sudo /opt/bitnami/ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

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

    Virtual Machine

    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 arguments to restart all services:

    $ sudo /opt/bitnami/ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

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

    Native Installer

    You can use either the graphical manager tool or the command-line tool to start and stop the servers.

    Graphical Tool

    Bitnami stacks include a graphical tool to manage the servers easily (native installers only). Using this tool, you can start, stop and restart the servers and check the log files.

    manager-servers.png

     

     

     

     

     

     

     

     

     

     

    On Windows:

    • Double-click the "manager-windows.exe" file in your installation directory.  
    • You can also start the Manager tool using the Start Menu path Start -> Program Files -> Bitnami Stack -> Manager.

    On Linux and Mac OS X:

    • Double-click the "manager-osx" or "manager-linux-*" tool in your installation directory. 
    Command-line Tool

    Each Bitnami stack includes a control script that lets you easily stop, start and restart servers.

    The control script is only available for Linux and Mac OS X native installers. The script is located in your installation directory and named ctlscript.sh. Call it without any arguments to restart all services.

    On Linux:
    If your installation directory is /home/USER/wordpress-4.0.1-0, call the control script with the ‘start’ argument to start all servers. For example:

    $ cd /home/USER/wordpress-4.0.1-0
    $ ./ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

    $ cd /home/USER/wordpress-4.0.1-0
    $ ./ctlscript.sh restart mysql
    

    On Mac OS X:
    If your installation directory is /Applications/wordpress-4.0.1-0, call the control script with the ‘start’ argument to start all servers. For example:

    $ cd /Applications/wordpress-4.0.1-0
    $ ./ctlscript.sh start
    

    Or use it to restart a specific service only by passing the service name as argument - for example 'mysql':

    $ cd /Applications/wordpress-4.0.1-0
    $ ./ctlscript.sh restart mysql
    

    Tabs end

    How can I run a command in the MEAN Stack?

    Select your platform for instructions on how to run commands in your stack.

    Cloud Images

    Log in to the server console as the 'bitnami' user and run the command as usual. The required environment is automatically loaded for the ‘bitnami’ user.

    Virtual Machine

    Log in to the server console as the 'bitnami' user and run the command as usual. The required environment is automatically loaded for the ‘bitnami’ user.

    Native Installer

    All native installers for Bitnami Stacks are completely self-contained and run independently of the rest of the software or libraries installed on your system. Therefore, to work correctly, you will need to load specific environment variables before you invoke any command utilities bundled with the Bitnami MEAN Stack.

    The Bitnami console is a script to load the stack environment. This console is useful to run any command included in the stack: mongo, node, npm, php among others.

    On Linux:

    At the server console, enter the following commands:

    $ cd ~/meanstack-VERSION
    $ ./use_meanstack

    On Windows:

    From the Start Menu, click the Start -> Bitnami MEAN Stack -> "Use MEAN Stack" shortcut.

    On OS X:

    Open a Terminal and type the following commands:

    hostname:~ user$ cd /Applications/meanstack-VERSION
    hostname:~ user$ ./use_meanstack
    

     

    IMPORTANT: You may have a separate, unrelated Node.js or MongoDB installation on your system. In this case, if you do not use the Bitnami console script explained above, any Node.js or MongoDB command will operate on the non-Bitnami Node.js or MongoDB installation. However, if you run the same command using the Bitnami console, the command will operate on the Node.js or MongoDB installation included in the Bitnami MEAN Stack. To illustrate, if you run the command npm install -g sample through the Bitnami console, it will install NPM packages into the Bitnami MEAN Stack. However, if you run the same command outside the console, it will be install the NPM packages into your other (non-Bitnami) Node.js environment.

    How to start with a sample MEAN project?

    Cloud Images

    Access the Bitnami MEAN Stack via your browser at http://[server-IP-address]/.

    Virtual Machine

    Access the Bitnami MEAN Stack via your browser at http://[server-IP-address]/.

    Native Installer

    Access the Bitnami MEAN Stack via your browser at http://localhost (Windows) or http://localhost:8080 (Mac OS X and Linux).

    Tabs end

    If you would like to create a new MEAN project, follow the steps below for your platform.

    Cloud Images

    1. Log in to your server console.

    2. Create a new folder for your project in the /home/bitnami directory.

    $ cd /home/bitnami
    $ mkdir projects
    

    3. Create a new Express project:

    $ cd /home/bitnami/projects
    $ express sample
    
     
    4. The MEAN stack already has the required components installed in Node.js, but if you prefer, you can install them in the new project folder:
    $ cd /home/bitnami/projects/sample
    $ npm install
    

    5. Start the application.

    $ ./bin/www
    

    This will start the Express server for your application on port 3000.

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

    On Windows:

    • Make sure you can log in to the server using PuTTY. Refer to your cloud provider's page in this wiki for more information on this.
    • Open a new SSH session to the server. In the PuTTY settings for the new session, click "Connection → SSH → Tunnels" section and create a secure tunnel for the application by forwarding source port "3000" to destination port "localhost:3000".
    • Click the "Add" button to add the secure tunnel configuration to the session.

      tunnel.png

    • Go back to the "Session" section and save your changes by clicking the "Save" button.
    • Click the "Open" button to open a new SSH session to the server.

    On Linux and Mac OS X:

    • Make sure you can log in to the server using SSH. Refer to your cloud provider's page in this wiki for more information on this.
    • Depending on whether you have aan SSH key for server access or not, open a new SSH session to the server using one of the two commands below:
      • If you have a private SSH key, use this command:
        $ ssh -N -L 3000:127.0.0.1:3000 -i bitnami-hosting.pem bitnami@xyz.bitnamiapp.com
        

        Remember to replace 'bitnami-hosting.pem' in the previous commands with the path to your private key file, and 'xyz.bitnamiapp.com' with the public IP address or hostname of your server. Note that if successful, this command will create an SSH tunnel but will not display any output on the server console.

      • If you don't have a private SSH key but your server uses an SSH username/password pair, use this command:
        $ ssh -N -L 3000:127.0.0.1:3000 bitnami@xyz.cloudapp.com
        

        Remember to replace 'bitnami' with the SSH username from your credentials pair and 'xyz.cloudapp.net' with the public IP address or hostname of your server. Enter your SSH password when prompted. Note that if successful, this command 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 your application through the secure SSH tunnel you created, by browsing to http://localhost:3000/.

    Virtual Machine

    1. Log in to your server console.

    2. Create a new folder for your project in the /home/bitnami directory.

    $ cd /home/bitnami
    $ mkdir projects
    

    3. Create a new Express project:

    $ cd /home/bitnami/projects
    $ express sample
    
     
    4. The MEAN stack already has the required components installed in Node.js, but if you prefer, you can install them in the new project folder:
    $ cd /home/bitnami/projects/sample
    $ npm install
    

    5. Start the application.

    $ ./bin/www
    

    This will start the Express server for your application on port 3000.

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

    On Windows:

    • Make sure you can log in to the virtual machine using PuTTY. Refer to this page for more information.
    • Open a new SSH session to the virtual machine. In the PuTTY settings for the new session, click "Connection → SSH → Tunnels" section and create a secure tunnel for the application by forwarding source port "3000" to destination port "localhost:3000".
    • Click the "Add" button to add the secure tunnel configuration to the session.

      tunnel.png

    • Go back to the "Session" section and save your changes by clicking the "Save" button.
    • Click the "Open" button to open a new SSH session to the server.

    On Linux and Mac OS X:

    $ ssh -N -L 3000:127.0.0.1:3000 bitnami@192.168.56.101
    

    Remember to replace '192.168.56.101' with the network IP address or hostname of your virtual machine. Enter the password when prompted. Note that if successful, this command 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 your application through the secure SSH tunnel you created, by browsing to http://localhost:3000/.

    Native Installer

    1. Load the Bitnami console.

    2. Change to the installdir directory and create a directory for your project.

    $ cd installdir
    $ mkdir projects
    

    3. Create a new Express project:

    $ cd installdir/projects
    $ express sample
    
     
    4. The MEAN stack already has the required components installed in Node.js, but if you prefer, you can install them in the new project folder:
    $ cd installdir/projects/sample
    $ npm install
    

    5. Start the application.

    $ ./bin/www (for Linux and Mac OS X native installers)
    > node bin\www (for Windows native installers)

    This will start the Express server for your application on port 3000.

    You can now access the application by browsing to http://localhost:3000 using your Web browser.

    Tabs end

    You can now proceed to enhance your project by connecting it with MongoDB or by adding AngularJS.

    Connecting to MongoDB

    You can connect your application with MongoDB using MongooseJS, an object modeling driver for Node.js. It is already installed in the MEAN stack so you only have to add the following lines to your app.js file:

    var Mongoose = require('mongoose');
    var db = Mongoose.createConnection('mongodb://USER:PASSWORD@localhost/DATABASE');
    

    On cloud servers, virtual machines and Linux and OS X native installers, you can also use the MongoDB socket instead of using the TCP/IP connection to MongoDB. Here is an example for cloud servers and virtual machines.

    var Mongoose = require('mongoose');
    var db = Mongoose.createConnection('mongodb:///opt/bitnami/mongodb/tmp/mongodb-27017.sock/DATABASE');
    

    And here is an example for native installers. Remember to replace the installdir placeholder below with the actual path to your stack installation directory.

    var Mongoose = require('mongoose');
    var db = Mongoose.createConnection('mongodb://installdir/mongodb/tmp/mongodb-27017.sock/DATABASE');
    

    Note that in both the previous examples, the socket name depends on the MongoDB port in use.

    Refer to this document for information on how to create a database and a database user in MongoDB.

    Adding AngularJS

    You can use install AngularJS in your application with Bower. Create a file named .bowerrc in your application with the following content:

    { "directory" : "public/javascripts/vendor" }
    

    Then, run this command in the project directory:

    $ bower install angular
    

    The necessary files will be copied into the public/javascripts/vendor/angular directory of your application.

    Learn more about testing and developing applications with the Bitnami MEAN stack.

    How can I access RockMongo?

    RockMongo is a web-based management tool for MongoDB.

    For security reasons, RockMongo is only accessible 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 have an SSH private key and be able to connect to your server over SSH in order to access this application 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.

    Cloud Images

    On Windows:

    • Make sure you can log in to the server using PuTTY. Refer to your cloud platform's page in this wiki for more information.
    • Open a new SSH session to the server and in the PuTTY settings for the new session, click "Connection → SSH → Tunnels" section and create a secure tunnel for the RockMongo application by forwarding source port "8888" to destination port "localhost:80".
    • Click the "Add" button to add the secure tunnel configuration to the session.

    • Go back to the "Session" section and save your changes by clicking the "Save" button.
    • Click the "Open" button to open a new SSH session to the server.

    On Linux and Mac OS X:

    • Make sure you can log in to the server using SSH. Refer to your cloud platform's page in this wiki for more information.
    • If you have a private key file for your cloud server, open a new SSH session to the server using the following command:
    $ ssh -N -L 8888:127.0.0.1:80 -i bitnami-hosting.pem bitnami@xyz.bitnamiapp.com
    

    Remember to replace 'bitnami-hosting.pem' in the previous commands with the path to your private key file, and 'xyz.bitnamiapp.com' with the public IP address or hostname of your server. Note that if successful, this command will create an SSH tunnel but will not display any output on the server console.

    • If you use an SSH username/password pair to access your cloud server, open a new SSH session to the server using the following command:
    $ ssh -N -L 8888:127.0.0.1:80 bitnami1@xyz.cloudapp.net

    Remember to replace 'bitnami1' with the SSH username from your credentials pair and 'xyz.cloudapp.net' with the public IP address or hostname of your server. Note that if successful, this command 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 RockMongo through the secure SSH tunnel you created, by browsing to http://127.0.0.1:8888/rockmongo.

    To log in, use username 'root'. For the application password, refer to the detail page for your cloud server.

    Virtual Machine

    On Windows:

    • Make sure you can log in to the server using PuTTY. Refer to these instructions for more information.
    • Open a new SSH session to the server and in the PuTTY settings for the new session, click "Connection → SSH → Tunnels" section and create a secure tunnel for the RockMongo application by forwarding source port "8888" to destination port "localhost:80".
    • Click the "Add" button to add the secure tunnel configuration to the session.

    • Go back to the "Session" section and save your changes by clicking the "Save" button.
    • Click the "Open" button to open a new SSH session to the server.

    On Linux and Mac OS X:

    $ ssh -N -L 8888:127.0.0.1:80 bitnami@192.168.1.1
    

    Remember to replace '192.168.1.1' with the network IP address or hostname of your virtual server. Note that if successful, this command 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 RockMongo through the secure SSH tunnel you created, by browsing to http://127.0.0.1:8888/rockmongo.

    To log in, use username 'root'. The default password is 'bitnami'.

    Alternative Approach: Allow Access from All Hosts

    Alternatively, if you are running the virtual machine in a secure environment, you can enable access to RockMongo from hosts other than 127.0.0.1 by editing the /opt/bitnami/apps/rockmongo/conf/httpd-app.conf file and modifying the Allow and Require directives as below:

      Default directive Modified directive
    Apache 2.2 Allow from 127.0.0.1 Allow from all
    Apache 2.4+ Require local Require all granted

    You can also use the example configuration file below if you wish:

    <Directory "/opt/bitnami/apps/rockmongo/htdocs">
    # AuthType Basic                                                                                                                                          
    # AuthName RockMongo                                                                                                                                     
    # AuthUserFile "/opt/bitnami/apache2/users"                                                                                           
    # Require valid-user                                                                                                                                      
      <IfVersion < 2.3 >
      Order allow,deny
      Allow from all
      Satisfy all
      </IfVersion>
      <IfVersion >= 2.3>
      Require all granted
      </IfVersion>
      ErrorDocument 403 "For security reasons, this URL is only accesible using localhost (127.0.0.1) as the hostname"
    </Directory>
    

    Restart Apache to have the changes take effect:

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

    You should now be able to access RockMongo by browsing to http://[virtual-machine-IP-address]/rockmongo.

    To log in, use username 'root'. The default password is 'bitnami'.

    Native Installer

    You should be able to access RockMongo directly, by browsing to http://127.0.0.1:8080/rockmongo or http://127.0.0.1/rockmongo.

    The username is 'root', and the password is the one specified by you during the installation process.

    Tabs end

    Here is an example of what you should see:

    rockmongo-1.png

    Tag page (Edit tags)
    • No tags
    Page statistics
    266900 view(s), 39 edit(s) and 18185 character(s)

    Comments

    You must login to post a comment.