Sunday, April 5, 2015

Wordpress and OwnCloud on Android

End Results

I got Wordpress, OwnCloud, ssh, samba, ftp hosted on android device acting as my home server for movies, music (playlists of remote files) from an ext3 portable hard drive all on 9 watts.

What you need

Android device (duh), optionally rooted
Servers Ultimate($4 but worth it)
SambaDroid (Servers ultimate's ssh is broke, and SambaDroid supports users)
BSPlayer (Plays remote files, can create playlists with recursivly listing remote directories)
MXPlayer (best remote player bar none due to codec support)

Wordpress and OwnCloud

Php and MySql

Wordpress requires PHP and MySql. There are only a few contenders for this niche market. I've tried AndroPHP, PAW, Utli server, KSWeb, Bit web server, Palpa Web Server. AndroPHP was the only free functional one, while the rest cost past the 5 day trial. If you're going to spend the dough spend it on something that has the kitchen sink, and boy does Servers Ultimate Pro have every server you could want when you're interested in using android as a linux server.
After installing Servers Ultimate Pro Start up the MySql server (all configuration we care about is handled in phpmyadmin.)
Check the Start on Boot option, and repeat for all the servers below.
Now start the mysql server.
Create a "web" folder somewhere on an SD card or external storage where we'll be putting the wordpress root folder.
Create a php server. Check the "Enable PhpMyAdmin". Set the Document root to the "web" folder you created above. Start both servers up. If you have root enable root forwarding so your web server can take traffic on port 80 (the port all browsers default to when going to www.bla.com. Without root you'll be stuck with something like 8080. This implies that links to your site will need this unusual www.jim.no-ip.com:8080 link. Sites like no-ip.org have mechanisms to redirect sites(:80 -> :8080), but can't overcome this limitation)
In a browser navitate to 127.0.0.1/phpmyadmin
or 127.0.0.1:8080/phpmyadmin if you don't have root
On the login screen use username: root , password: <blank>
Welcome to the dashboard for your MySql server
change the password to whatever you like.
Go to the Users tab and create a new user called "wordpress". 
Under Host put localhost. 
Put in some password for wordpress's database needs that you can remember (best to have it different than the root password).
Be sure to select "Create database with same name and grant all privileges"
Then "Add user"
Do the same as above but for "owncloud"
You're done with phpmyadmin.

Wordpress

Download the wordpress zip and unzip it in the "web" folder.
In a browser navigate to localhost/wordpress
Enter the username and password you created above into the wizard for wordpress and choose localhost for the host that wordpress connects to.
Voila, you have wordpress. I'll walk you through making it pubically accessable later.
If you want to download the wordpress app on your android device for easy editing of your blog posts you'll need to be connected to the internet at least when entering in the hostname of your blog (localhost), but after that you can be offline and make edits to your local wordpress blog.

OwnCloud

Download the owncloud tar file. Unzip it in "web". Owncloud was a bit more tricky because they expect to be on a linux system more than wordpress does. I had to remove two checks in /lib/private/util.php. Because OwnCloud may update this file I'll simply point you to the code I had to delete. It'd be nicer if the code checked if it was running on android and ommitted this check, but eh. I had to delete the if statement around line 622 refering to isSetLocaleWorking. I also had to replace the contents of the function titled checkDataDirectoryPermissions. Simpy replace all the stuff inside the curly braces with  return array(); Android doesn't do that well with these permissions. I with I could do better here.
In a browser navigate to localhost/owncloud
Be sure to open the database section and put in the username and password you created above. It could use sqllite, but we're shooting for the stars here.

Samba network share

For some reason Servers Ultimate Pro's Samba server triggers a null pointer in ES File Explorer. SambaDroid (even the non pro version) I found sufficient. It allows one user username: android password:<blank> which you can change. It restricts you to one root directory to be shared, which I chose to be the /mnt folder. Because it's restricted by credentials I felt it was safe enough.
With this samba server running I was able to stream movies and music from MXPlayer and BSPlayer respectivly.
MXPlayer works great with ES File Explorer because with ES you can easily navigate to the NAS server using the device's IP address and credentials. Clicking on a movie will trigger MXPlayer to take over and stream across the network. MXPlayer has the added benefit of having 200% volume capability which helps with android devices and some movies.
BSPlayer was the best at being able to play an entire folder on a network share and create a playlist from it.

Remote Management

Use Servers Ultimate Pro's ssh server to open ssh access. Be sure to add a user in the ssh server settings before turning it on. Also install BusyBox if you want to make sure that the command line tools you want are there.

In another post I'll talk about how to open your server to the internet, as well as protecting your data.