Wednesday, 8 June 2011

Setting Up a Website with PHP & MySQL




.
One of the most common tasks ReadyNAS users wish to use their devices for is to host a small personal web site

Creating a basic Personal Web Server is very easy to do and documented on the ReadyNAS site here.

This basic setup is perfectly sufficient for hosting HTML only based web sites, but many users would like to go that step further and create more advanced setups, perhaps using common Open Source CMS systems such as WordPress (like this site) or Joomla. To support such setups, the ReadyNAS typically needs to be updated to support both PHP - a common programming language used for creating web sites - and MySQL - a relational database application.

Here's how to add the PHP and MySQL missing pieces:

Note: Where addons are linked to, the applicable version is as follows:
  • sparc version for  ReadyNAS Duo / NV / NV+ / 600 / 1100
  • x86 version for ReadyNAS Ultra, Ultra Plus / Pro / NVX and all rack mount units excluding the 600 & 1100

Installing PHP


PHP support can be enabled by installing one of PHP addons available from the ReadyNAS Community Addons forum. Personally I would recommend the "WhoCares?" PHP 5.2 addons - x86 version, sparc version - as these tend to be compatible with all other addons, have worked well for me over the years and come with the modules required for PHP access to MySQL databases. Other versions of PHP addons may provide  additional features that may be required, so check them out.

Note: Unless you know that you need PHP 5.3 - which includes language construct changes vs PHP 5.2, not just enhancements - I would not recommend installing that PHP addon

Enabling MySQL


MySQL is included in the default ReadyNAS firmware for all devices as it is used by the ReadyNAS Photos application. However, if you are not using the ReadyNAS Photos application, then MySQL is disabled by default. It can be enabled by installing the MySQLON addon: x86 version, sparc version

Note: MySQLON and ReadyNAS Photos should not be enabled at the same time as the 2 may conflict

Managing MySQL Databases


Once MySQL is enabled, there is of course a requirement to create and manage the MySQL databases. If you have enabled root SSH access to your NAS, then you can of course manage MySQL from the command line. For those less adept with commandline access, there is an application called phpMyAdmin (x86 version, sparc version) that can be installed to provide a web based graphical front end to managing MySQL.

Once installed, browse to the address http://<nas-ip-address>/phpadm - using "admin" and your ReadyNAS admin password if prompted for access to the page. Once loaded you should see this:



To login for the first time use the user name "root" and leave the password blank. This should give you access to the following page:



From here you can create and manage you databases, create new MySQL users and, of course, set a password for the root MySQL account.


Backing Up Your MySQL Database


Due to the nature of database applications, care must be taken when backing them up - as most users would prefer their databases to continue to run while being backed up, stopping the MySQL server and copying the actual database files is not usually acceptable.

There are 2 options to over come this:

1. Use phpMyAdmin to export the data from a database. This has the advantage of allowing you to make a backup on demand while the database continues to be functional, but is a very manual process

2. Install the MySQLBackup addon (x86 version, sparc version). This addon allows you to schedule regular database backups maintaining daily, weekly and monthly archives of all databases in your backup share.


Finally...


Often a user will want to edit the web site on the NAS via a share protocol such as CIFS or AFP, and will connect to the NAS using a personal user account. To ensure that the ReadyNAS web server can read files created and edited by users, it is important that "everyone" is granted read permission to files created within the share. Details of how to set this up are covered in this post

And that's it.





15 comments:

  1. sphardy,

    I have been thinking about hosting my Joomla site from my ReadyNAS duo for a while but it seemed too complex until I came across your guide. I was wondering two things. First, Joomla requires Apache 2.x + and I don't see it mentioned in your guide. Is it already included on the ReadyNAS (Duo)? Second, if I wanted to install the latest version of Joomla the recommended requirement is for php 5.3 + and I see you made a note about avoiding it. The minimum requirement for Joomla 1.7 is 5.2.4 + so it is possible to avoid 5.3 but I was curious what the warning is about?

    Thanks!

    ReplyDelete
  2. Jørgen Thulstrup18 August 2011 at 22:07

    This is a stupid question - I know - but after having installed the "WhoCares?" php add-on I have not been able to find the website folder.
    On my Ubuntu it is in /var/www
    Where can I find the equivalent folder in my ReadyNas?

    ReplyDelete
  3. Apologies for the late reply – my site seems to have stopped notifying me of new comments

    Apache2 is installed on all ReadyNAS devices - it is the web server used to support Frontview. As for PHP5.3 - the warning was made as there are a number of addons available for the ReadyNAS devices that do not work well with PHP5.3 and have caused users issues as the source of the problem was not readily apparent. (The phpMyAdmin addon I mention is a good example, but there is now a newer version of that addon now available that works with 5.3)

    So if you are confident your application will work with 5.3, then by all means go ahead and install that.

    ReplyDelete
  4. Apologies for the late reply – my site seems to have stopped notifying me of new comments

    It is most typical to use a regular share as the website folder. For example create a share called "web", enable read-only http access to the share, and then specify that share as the default web folder in Frontview >> Services >> Standard File Protocols >> HTTP

    ReplyDelete
  5. Hi there, i followed the instruction, i want to install joomla, but i got error when i browse to the address http:///phpadm :
    Not Found
    The requested URL /phpmyadmin was not found on this server.
    Help
    Thanks

    ReplyDelete
  6. You are not using the correct address - you need to include the name or IP address of your NAS as appropriate. For example if your NAS IP address is 192.168.1.100, then the phpmyadmin page would be at http://192.168.1.100/phpadm

    ReplyDelete
  7. Hi sphardy, I noticed that the whocares php addon is now automatically at version 5.3.8. i can't find anywhere to get the older versions even if I wanted them. It also looks like I have to pay for it. While I don't mind donating money for a working addon, I would like to try it out first. Do you still recommend this addon or is there another one that I should try?

    ReplyDelete
  8. I'd most definitely recommend that addon.

    Still first ensure your application is compatible with PHP5.3 but also you MUST read (and follow) the guide in the FAQ for the addon which gives precise details of how to set it up on your NAS and ensure correct integration with MySQL.

    ReplyDelete
  9. One more question. I followed all of the instructions so far and have the basic site up and running. I still need to install php 5.3 and phpmyadmin but I found something curious. For some reason my website URL redirects to the share I created so instead of just showing wyattwatty.com as the URL it shows wyattwatty.com/website. Did I miss something in the setup?

    Thanks

    ReplyDelete
  10. Nope - that's how it works. Go to my home page at http://sphardy.com and you will see the same

    ReplyDelete
  11. Sorry for bugging you but you mention that you can change the password for the root user using phpmyadmin. Upon reading the whocares FAQ for the phpmyadmin addon he says that leaving the root password blank is ok because the connection is via a local socket only. So I have two questions, first should I change the password just for that extra bit of security? Second where in phpmyadmin do you set the password for the root user?

    I tried finding that information on the web but I got some conflicting thoughts about whether or not to change the root password without creating any other users first and I only found command lines that would show how it is done.

    Thanks!

    ReplyDelete
  12. WhoCares? is correct if you choose to use the socket connection as advised. As only applications running on your NAS can access the database, a hacker would need command line access to your NAS to gain database access.

    If you had an application on another server that needed to access the NAS MySQL database over the network (requires network access to be enabled), then it would be advisable to set a non-null root password

    Note the are some addons that also use MySQL and assume the root account has no password set - ReadyNAS Photos is one - so be aware of that if you decide to change the password

    ReplyDelete
  13. Hey sphardy I am running into a problem installing Joomla. When I get to the step that asks for my MySQL username, password, and database name I input them and I get an error message "Could not connect to the database. Connector returned number: 2"

    I followed all of the instructions and phpmyadmin is up and running. I used it to create a database and a new user and password with access to the database. I tried this combination as well as using the default root user combination and both failed. Any ideas what could be causing this error?

    Thanks

    ReplyDelete
  14. A quick web search shows that error is typically due to an incorrect username/password.

    You should be able to test the username and password in phpmyadmin - log in using those credentials and if all is well you should be able to access the joomla database you created.

    ReplyDelete
  15. I worked through it with Whocares? on his forum. It was a whole bunch of problems related to Joomla and the PDO php extension and well... too much for me to figure out. Whocares? helped me figure it out but after all of that I see that a site hosted on a ReadyNas Duo is pretty useless since it runs sooooooo slowly. Each page was taking 20+ seconds to load. Now I have to look at other options.

    Thanks for your help. If nothing else I learned a lot.

    ReplyDelete