Need help to host your simple private website or save future cost by migrating your simple SME company’s website to your personal NAS such as WDMyCloud? For a generous donation you can make it work! Professional freelance web coding design services are also available for your needs. Do send in your enquiries.
This guide has been separated for generic implementation of WebHosting on the WDMyCloud V4 Firmwares. Purpose of this guide is mainly for those who’s new to personal web hosting (maybe Linux itself) and interested in running sites like OwnCloud or WordPress on their WDMyCloud firmware v4 NAS. If you’re not familiar with HTTP Servers and CGIs, then maybe this is not for you.
Why Nginx not Apache2? Apache2 is great but when there’s multiple or concurrent connections, the WD’s Apache2 MPM_PREFORK and MOD_PHP5 configs may cause lots of swapping as they have high memory print thus slowing down everything with high I/O Wait. At some point you’ll need to unplug the power as even SSH not responding.
Disclaimer: As I’m frequently updating the original guides and installers here on TeaNazaR.com, I will not be responsible for any brick issues if you were to follow my obsolete guides copied elsewhere. Thus subscribe to this post to get latest updates. Modifying any part of a device may void its warranty.
WDMyCloud is a pretty small server, dual-core ARM Cortex-A9 650MHz CPU with 256MB DDR3 RAM running on Debian Wheezy OS. But with some mods, tweaks and caches, it should be able to host a small personal site (not those thousands daily hits). The idea here is to switch Apache2 to a lower memory consumption threaded MPM_EVENT process which is compatible with PHP5-FPM and together with a light-weight Nginx, hopefully there’ll be lesser swapping. We can’t totally remove Apache2 because lots of WD’s stuffs depends on it like WebDav remote login for example will require revamp of the PHP scripts.
1) Get free DNS forwarder if not done so [Optional]
To easily access your WDMyCloud without needing to remember your external ISP IP address especially if it’s dynamic, get those easy to setup and free Dynamic DNS forwarder such as http://freedns.afraid.org/signup/moreinfo/. They provide free DDNS forwarding up to 5 subdomains. Your router many already have such DDNS service but I find it rather limited. I’m using GoDaddy’s DNS service which bundled with my paid domain (www.TeaNazaR.com). Tips: If your owned domain provider doesn’t provide an easy method of updating your dynamic ISP IP, you can also make use of this freedns service by pointing your owned domain CName (Alias) to the freedns subdomain. Cool huh? (-:
Updated: If you’re using GoDaddy’s DNS service, do refer to my latest GoDaddy DDNS Updater post.
After reading the FAQ and signing up with email confirmation, login and click on the left “Registry” menu to find a nice suitable DNS for yourself like “mooo.com”, click on it. On the next page, all you need to submit is your “Subdomain” e.g. my-freedns-subdomain.mooo.com. Note this down if you’re setting up OwnCloud or WordPress from my other guides as we’ll need it later to setup Nginx’s “server_name“. Leave the rest as default. Next we’ll need to ensure the DNS is always up-to-date with your ISP IP address. Click on the left “Dynamic DNS” menu where you’ll see your new DNS list, right-click and copy the link “Direct URL“. The URL should point to something like http://freedns.afraid.org/dynamic/update.php?RllWcksfRUY5afdyUGNgdVcwQs43ejROhjEyNTfxgjQw. Then schedule a 5mins repeating cronjob on your WDMyCloud to automatically update the DNS incase your ISP IP address changes. SSH into your WDMyCloud, issue crontab -e and add a new line:
*/5 * * * * /usr/bin/curl freedns.afraid.org/dynamic/update.php?RllWcksfRUY5afdyUGNgdVcwQs43ejROhjEyNTfxgjQw >/dev/null 2>&1
When done, “CTRL+x” to exit and “y” to save changes to the file.
Note that if you have several subdomains, obviously you’ll need one cronjob for each to auto update the DDNS unless if you have enabled the “Link updates of the same IP together” option. This option allows you to update the subdomains of the same IP all at once. Useful if you have several subdomains all pointing to your current ISP IP address so you can just trigger one update. I’m not using this option because sometimes I need some of the subdomains to be pointed elsewhere.
Test out once if it’s working, issue the same command and you should get ERROR: Address 22.214.171.124 has not changed where “126.96.36.199” is your external ISP IP address which you can find out by Googling “what is my IP“:
2) Prepare your router if not done so
This is usually unnecessary for standard Nginx install which you could just forward the same ports 80/443 between externally and internally. But since we’re integrating with Apache2, you’ll need to perform some changes else there’ll be port conflicts between Nginx and Apache2 as both are by default using ports 80/443.
Forward TCP external port 80 on your router to the WDMyCloud internal IP/HOST address PORT:5080. If port 80 is already taken on your router or port 80 is blocked by your ISP, you can choose other ports like 5080 itself but you’ll then need to specify the port manually when accessing from the internet e.g. http://my-freedns-subdomain.mooo.com:5080/ or http://your-ISP-IP-address:5080/. Also if your forwarded external port is other than 80 due to these two reasons, you’ll need to change all occurrences of Nginx’s fastcgi_param SERVER_PORT $server_port variable to whatever external port you’ve chosen. One example of the occurrences is in /etc/nginx/fastcgi_params.
If you have a valid SSL certificate (HTTPS), forward port 443 to wdmycloud:5443 as well. With the port routing below, you can have multiple websites running on single port 80/443 of your router thanks to Nginx’s “server_name” which is similar to Apache2’s VHOST:
Router TCP port(80) -> WDMyCloud TCP port(5080)
Router TCP port(443) -> WDMyCloud TCP port(5443)
Note however that some routers (especially those ISP bundled) have limited or restricted capabilities i.e.:
a. Lack of PAT. Meaning if you specify a rule to forward external port 80, it can only be forwarded to internal port 80. And since WDMyCloud is already using port 80 for Apache2, you’re left with no choice but to use port 5080 as both external and internal port for Nginx.
b. Unable to route back external port to internal port if the request is being made within LAN. Meaning if you try to browse your ISP IP via LAN, your router will return error. So you’re accessing Nginx from LAN, you’ll need to use internal IP instead of ISP IP.
c. You have more than one router i.e. one for the gateway and the other is set to bridge/AP (Access Point) mode.
These could be overcome but requires much more complex options and changes . Do send in your enquiries if you need personalized support.
3) Prepare your WDMyCloud
You’ll first need to install all the necessary apps (Nginx/PHP5-FPM/Perl/MySQL/ESMTP) tweaked for the WDMyCloud firmware v4, available on my post at the WD Forum. Get them installed at this post here, [APP] WebHosting for firmware V4+. Even though the WDMyCloud is already equipped with Apache2/MOD-PHP5/SQLITE, it’s still very sluggish as mentioned earlier maybe due to high I/O Wait and swap trashing. Sometimes it freezes the WDMyCloud for hours when there’s lots of concurrent PHP request and the only solution is to unplug the power cord. I’ve been trying to tweak it out but I finally gave up and switched to Nginx/PHP-FPM.
4) Prepare sendmail if not done so [Optional]
Some Web Apps uses local sendmail to send out email notifications. With ESMTP, you can simulate Postfix’s sendmail MTA by relaying emails to a SMTP server.
Edit ESMTP config:
You can use your ISP email if you know its settings or example here, Gmail. Edit below as needed:
# Config file for ESMTP sendmail
# The SMTP host and service (port)
# SECURITY WARNING: Do NOT set username and password in the system wide
# configuration file unless you are the only user of this machine. See
# The user name
# The password
# Whether to use Starttls
# The certificate passphrase
# The Mail Delivery Agent
When done, “CTRL+x” to exit and “y” to save changes to the file.
Test out once if it’s working, you should see no output but still receive the email in your inbox:
echo -e "To:$TO\nFrom:$FROM\nSubject:ESMTP Test\n\nHello World" | sendmail $TO;
Now your should be able to host simple websites on the WDMyCloud with Nginx/PHP5-FPM/Perl/MySQL/ESMTP e.g. http://my-freedns-subdomain.mooo.com/ or http://your-ISP-IP-address/ and still able to access your WDMyCloud Dashboard from Apache2 http://wdmycloud/ (or whatever internal IP or hostname you have set it to).
And if at anytime you have issues with any of these web apps like very long response time (especially PHP5-FPM after too much concurrent request will result in swap file trashing), a restart is the best way to resolve it:
service nginx restart;
service apache2 restart;
service php5-fpm restart;
service perl-fcgi restart;
service mysql restart;
Checkout my other related guides for WebHosting:
- Dealing PHP-FPM Crash & Nginx 502 Bad Gateway Error with Shell Scripts
- Dealing PHP-FPM Crash & Nginx 502 Bad Gateway Error with Perl FastCGI