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.
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:
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.
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:
<!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">
<dependency name="network" grouping="require_all"
<dependency name="filesystem" grouping="require_all"
<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"/>
<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">
<loctext xml:lang="C">node.js hello-world service</loctext>
To build a manifest, run this command and enter your information:
To specify the executable, determine where Node.js is running by entering:
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.