Click here to Skip to main content
13,900,896 members
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 29 Dec 2012
Licenced CPOL

Setting Up a SmartOS Machine With Node.js and an AMP Stack

, 25 Jan 2013
Rate this:
Please Sign up or sign in to vote.
How to set up a SmartOS machine with Node.js and an AMP stack.


Recently I started experimenting with Node.js on Joyent with SmartOS, but I still wanted to be able to fall back on Apache, MySQL, and PHP before I fully migrate over to a Node.js solution, and I found that it was pretty simple to set up.


You may not have heard of SmartOS before, but maybe Solaris will sound a bit more familiar. Basically some of the guys that worked on Solaris ended up forking it into SmartOS with corporate support from Joyent. What you end up with is a cloud service virtual machine that runs very close to the metal and scales up with a click. Exactly what I wanted, but along with all the Node.js and MongoDB goodness, I wanted Apache, MySQL, and PHP.

Turns out that the 'Standard' SmartOS package on Joyent included almost everything I needed - Apache, PHP, and MySQL, as well as Node.js already baked in. What I wanted to add was phpMyAdmin, and this is how to do it.

Adding phpMyAdmin

This assumes that you have already provisioned a machine and already signed in via SSH. There's details on how to do that on Joyent's site.

Install phpmyadmin, type:

pkgin in phpmyadmin

and then add this line to httpd.conf:

Include /opt/local/share/examples/phpmyadmin/apache.conf

by doing:

nano /opt/local/etc/httpd/httpd.conf

and restart apache as root by doing: svcadm restart apache

That's it! You should now be able to launch phpMyAdmin by going to http://YOUR-IP/phpmyadmin/, remember the last forward slash.

File Locations

SmartOS places things into slightly different locations, so HTML files go here: /opt/local/share/httpd/htdocs.

You will need to do this to set up your admin account rights for this folder:

chown -R admin /opt/local/share/httpd/htdocs

Directories in this folder will need the execute permission set to be traversible, so type:

chmod a+x /opt/local/share/httpd/htdocs/

Now you should be able to SFTP into your machine, using the admin account name and password. Remember to set the port to 22 for SFTP to work.

Keep a Node.js Script Running

Something else I discovered is that although it is super simple to test a Node.js script, the moment you close down your terminal, it stops running.

This is fairly easy to solve though. I'll show the longer way first and then the short and easy way, you can choose which one you're more comfortable with, I honestly don't know what the pros and cons of each are at this point. 

To enable a Node script to keep on running, install Manifold to create a manifest:

pkgin in manifold

This is a sample manifest:

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">

<service_bundle type="manifest" name="node-hello-world-service">

  <service name="site/node-hello-world-service" type="service" version="1">
    <create_default_instance enabled="true"/>
    <dependency name="network" grouping="require_all" 

               restart_on="refresh" type="service">
      <service_fmri value="svc:/milestone/network:default"/>
    <dependency name="filesystem" grouping="require_all" 

              restart_on="refresh" type="service">
      <service_fmri value="svc:/system/filesystem/local"/>
    <method_context working_directory="/home/admin/hello-world">
      <method_credential user="admin" group="staff" privileges='basic,net_privaddr'  />
        <envvar name="PATH" value="/home/admin/local/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin"/>
        <envvar name="HOME" value="/home/admin"/>



      exec="/opt/local/bin/node /home/admin/hello-world/server.js"





    <property_group name="startd" type="framework">
      <propval name="duration" type="astring" value="child"/>
      <propval name="ignore_error" type="astring" value="core,signal"/>
    <property_group name="application" type="application">
    <stability value="Evolving"/>
        <loctext xml:lang="C">node.js hello-world service</loctext>

To build a manifest, run this command and enter your information:

manifold myservice.xml

To specify the executable, determine where Node.js is running by entering:

which node

Once you generate a manifest, you can import it by running:

svccfg import myservice.xml

After importing, you will need to enable it with:

svcadm enable myservice

This is another way to make your Node script run forever, is to use, well, Forever. Install it like this:

npm install forever -g

Then run your script forever with:

forever start /opt/local/share/httpd/htdocs/server.js

Actually pretty cool way to run Node scripts, since you can get lists of running scripts, start, stop, etc.

That's the end of this little article on setting up a SmartOS machine on Joyent. 

Have fun! Smile | <img src=


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chief Technology Officer
United States United States
I have a passion for programming, a love for art, and a wide range of management experience, ranging from large corporations where I managed multiple branches to small start-ups where I had to do everything myself, including coding.

I've gone from Desktop to Mobile to Web and J2ME to Android in 14 years of programming experience. Notched up over 15 years of experience in the advertising industry, almost 7 years of Java experience, and have a keen sense of UX driven by a background in Art.

I understand of how people interact with code, which is driven by an advanced degree in Sociology and experience in delivering numerous commercial applications. I have management experience ranging from small groups to multiple branches, and have managed projects from single apps to multi-million dollar transformations.

You may also be interested in...


Comments and Discussions

GeneralThanks! Pin
Anthony Trimble31-Jul-13 16:37
memberAnthony Trimble31-Jul-13 16:37 
GeneralRe: Thanks! Pin
simsam772-Aug-13 15:15
professionalsimsam772-Aug-13 15:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190306.1 | Last Updated 25 Jan 2013
Article Copyright 2012 by simsam77
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid