Set up Google Cloud Platform + MEAN stack in 5mins

I believe in Google products, so it’s thus quite naturally that I use Google Cloud Platform to host my websites, apps, etc. GCP proposes a lot of pre-configured images for all your needs: blog, os, database, crm, or developer tools and infra like:

  • Jenkins
  • GitLab
  • Trac
  • NodeJS
  • MEAN
  • MySQL
  • Ruby
  • Cassandra

Images are delivered with all the tools you need to work efficiently! For example, the MEAN stack came with MongoDB, NodeJS, Express, Git, etc.

Well 🙂

But, a little configuration is needed to make your app listening on your custom port (3000 for example)

Steps

  1. Launch your server SSH console from Google Cloud Platform (Bitnami)
  2. Clone the project under /home/user/apps/
  3. Open up port 3000 in your Google Compute Network Firewall : Your VMs > Edit > Network > Click on default network_google_clud_mean_settingup
  4. Launch your own project on port 3000 (using your favorite grunt/node server command) and test if http://SERVER_IP:3000 works ? If it’s OK, go to step 5
  5. Edit the file opt/bitnami/apache2/conf/bitnami/bitnami.conf and replace the content with the configuration below (it’s only a proxy pass to route your server to the 3000 port)

Virtual Host Configuration

    <IfVersion < 2.3 >
      NameVirtualHost *:80
      NameVirtualHost *:443
    </IfVersion>

    <VirtualHost _default_:80>
    #  DocumentRoot "/opt/bitnami/apache2/htdocs"
    #  <Directory "/opt/bitnami/apache2/htdocs">
    #    Options FollowSymLinks MultiViews
    #    AddLanguage en en
    #    LanguagePriority en
    #    ForceLanguagePriority Prefer Fallback

    #    AllowOverride All
    #    <IfVersion < 2.3 >
    #      Order allow,deny
    #      Allow from all
    #    </IfVersion>
    #    <IfVersion >= 2.3 >
    #      Require all granted
    #    </IfVersion>
    #  </Directory>

    # Error Documents
      ErrorDocument 503 /503.html

    # Bitnami applications installed with a prefix URL (default)
    #  Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"

    # Redirect to port 3000 (proxy pass)
      ServerAdmin youremail@gmail.com
      ServerName yourservername.fr
      ProxyPass / http://localhost:3000/
      ProxyPassReverse / http://localhost:3000/
      ProxyPreserveHost On

    </VirtualHost>

    # Default SSL Virtual Host configuration.

    <IfModule !ssl_module>
      LoadModule ssl_module modules/mod_ssl.so
    </IfModule>

    Listen 443
    SSLProtocol all -SSLv2 -SSLv3
    SSLHonorCipherOrder on
    SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !EDH !RC4"
    SSLPassPhraseDialog  builtin
    SSLSessionCache "shmcb:/opt/bitnami/apache2/logs/ssl_scache(512000)"
    SSLSessionCacheTimeout  300

    <VirtualHost _default_:443>
      DocumentRoot "/opt/bitnami/apache2/htdocs"
      SSLEngine on
    SSLCertificateFile "/opt/bitnami/apache2/conf/server.crt"
    SSLCertificateKeyFile "/opt/bitnami/apache2/conf/server.key"

      <Directory "/opt/bitnami/apache2/htdocs">
        Options FollowSymLinks MultiViews
        AddLanguage en en
        LanguagePriority en
        ForceLanguagePriority Prefer Fallback
        AllowOverride All
        <IfVersion < 2.3 >
          Order allow,deny
          Allow from all
        </IfVersion>
        <IfVersion >= 2.3 >
          Require all granted
        </IfVersion>
      </Directory>
      # Error Documents
      ErrorDocument 503 /503.html

      # Bitnami applications installed with a prefix URL (default)
      Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf"
    </VirtualHost>
    # Bitnami applications that uses virtual host configuration
    Include "/opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf"
    # Status
    ExtendedStatus on
    <VirtualHost _default_:80>
    ServerName local-stackdriver-agent.stackdriver.com
    <Location /server-status>
      SetHandler server-status
      Order deny,allow
      Deny from all
      Allow from 127.0.0.1
    </Location>
    </VirtualHost>
  1. Restart apache with this command sudo /opt/bitnami/ctlscript.sh restart apache
  2. Now check your server IP in your favorite browser (chrome probably?), and your project should run there.