Wordpress and NodeJS on Azure

Larry Igna

Power Member
Joined
Nov 25, 2016
Messages
663
Reaction score
717
Hello, guys, need a bit of help. I've just signed up for the Azure 1 year free trial and I want to deploy a regular WordPress on there, plus I'd like to learn some NodeJS this year, so having that too would be nice. However, I don't know how to set it up in order to have it like this: WordPress on main domain and Node in a folder.
I have read that Azure hosts NodeJS apps on IISnode and that doesn't work so well, so I'm thinking about deploying an Ubuntu instance to work from scratch (Apache + PHP +Wordpess + Node install).
So, if you have any tips, hints, tricks, maybe links to instructional resources, feel free to post them. Thanks.
 
Yeah, go with the ubuntu setup and Install wordpress on main domain and run node on subdomain.
 
Thanks, managed to install everything as I wanted. I'll post below the steps, just in case someone needs it.
Getting Ubuntu deployed was fast, it's pretty easy actually, just click-click-click on Azure portal.
The only thing worth mentioning here is to setup now the inbound port you will be using for NodeJS. I've set it to (random) 3000, TCP, Allow, Any, Any..

WordPress

For the LAMP stack and WordPress I followed THIS tutorial, which is super easy , mostly a 5min copy/paste job.
I haven't used Azure CLI as instructed there, because I already SSHed into machine before reading that tutorial :D It should work either way.
Few things to know:
1. MySQL doesn't ask you for root pass during LAMP instaIl, you should set a root password for MySQL if you plan to be serious with security later on. I don't care.
2. Last two lines of code in that tutorial point your WordPress installation to
http://yourdomain.com/wordpress
Modify as you wish, I didn't, but again. . I don't care, I just needed wp installed.
Also, I don't have a domain for this, I will just use the IP address given by default.

NODEJS

This part was a bit more complicated, I will post the commands I used here.
Code:
sudo apt install nodejs
Code:
sudo apt install npm
The above will actually install Node
For testing in the next steps we need a http server running, so we will create one.
Code:
sudo nano http_server.js
Paste this
Code:
var http = require('http'), server = http.createServer(function            
(request, response) {                                                      
  response.writeHead(200, {'Content-Type': 'text/plain'});                  
  response.end('Hello World\n');                                            
});                                                                        
server.listen(3000);
Ctrl+X in Nano exits, press Y to save, Enter

If you do right now
Code:
sudo node http_server.js
your server will start and by going to
http://yourdomain.com:3000
you'll see a Hello World text.
However, that number in the URL looks so ugly.. To change that, some extra steps are needed.
To run Apache and NodeJS on same server we have two options:
1. Run Node on subdomain, as SpoonFeeder suggested. I don't have a domain for this thing and I think using a subdomain would complicate my life in this case.
2. ProxyPass: a nice feature in Apache that will send Node things to a folder, so your apps will be accessible from an address like http://yourdomain.com/node
I went with the second, here are the commands
Code:
sudo nano /etc/apache2/conf-available/CUSTOM.conf
This will create a custom conf file for Apache
Paste this in there, Exit, Save
Code:
ProxyPass /node http://localhost:3000

Enable custom configuration
Code:
sudo a2enconf CUSTOM
Enable proxy
Code:
sudo a2enmod proxy_http
Restart Apache
Code:
sudo service apache2 restart
Start previously created Node server
Code:
sudo node http_server.js
Bam, that's all, your Node server should be accessible by visiting either
http://yourdomain.com:3000
or
http://yourdomain.com/node

Hope this will help someone.
 
Back
Top