Friday, June 10, 2016

Recommended platform for Android Studio (not Ubuntu)

In principle, one could develop applications for Android using any tools that support Java and on any platform where the SDK can run. In practice, the setup is so complicated and tedious that it makes sense to use a tool that is specifically designed for Android development.

The only officially-supported development stack for Android is Android Studio from Google. Android Studio is based on JetBrains IntelliJ and depends on the Android SDK, also provided by Google.

In principle, Android Studio should work approximately the same on Mac OSX, Microsoft Windows, and Linux. In practice, it works best on Mac OSX, fairly well on Microsoft Windows, and very poorly on Linux.

With Linux you must expect to encounter numerous undocumented and frustrating problems related to package compatibility, UI and functional differences among different versions of Studio, contradictory instructions and tutorials that people cobbled together based on older versions of the tools and/or idiosyncrasies of their own computers that aren't an issue on your computer, nearly impossible-to-follow documentation from Google, Studio becoming confused between 32-bit and 64-bit emulation in a multi-arch Linux instance, and a bewildering mass of disjointed questions and answers on StackOverflow and on people's blogs, every one of which will lead you on a different and unique wild goose chase. In addition, the look and feel of the UI is just plain terrible on Linux.

I'm rambling on and on about this because Linux is my preferred environment for almost all kinds of development. I'm very disappointed in the quality of Linux support that Google is providing for Android Studio. It's simply not worth the hassle.

Android Studio has fewer issues on Microsoft Windows. The launcher may or may not detect the location of your Java SDK. If it doesn't, then you'll have to set the JAVA_HOME environment variable. This is the case with many other Java-based software products on Windows as well, so if you often use Windows you're probably familiar with this step.

I've found Android Studio to work more-or-less out of the box on Mac OSX. If you prefer to spend your time learning to write Android applications rather than struggling with configuration problems, I suggest you do your Android development on a Mac.

A second reason to consider Mac as the platform of choice for Android development is that if you're writing something for Android you're probably also writing a version of it for iOS. Might as well work on a single system rather than two systems.

Sunday, June 5, 2016

Wordpress sandbox installation notes

These are my notes from copying a site from wordpress.com to a local sandbox environment running Wordpress, in preparation for moving my site to a hosting service that supports ecommerce plugins.

Product versions

Wordpress runs on the LAMP stack. These notes pertain to:

  • Ubuntu Linux 16.04 LTS multi-arch
  • Apache HTTP server (apache2)
  • MySQL database v 5.7.12-0ubuntu1
  • PHP 7.0.4 7ubuntu2.1 (cli)

Here is what worked for me on June 3, 2016. Who knows if it will ever work again!

Userids and passwords

This procedure is meant to set up a local, insecure sandbox environment for experimentation and learning, and not a public site, so the passwords are all "wordpress" except the Wordpress password, which has to be generated by Wordpress. If you later migrate the site to a public server, remember to define better passswords at that time.

  • Ubuntu: [userid] / wordpress
  • MySQL: root / wordpress
  • phpMyAdmin: root / wordpress
  • Wordpress MySQL user: wordpress / wordpress
  • Wordpress administrator: [userid] / [generated-password]
  • Wordpress email address: [site owner email]

1. Install Ubuntu 16.04 Desktop

I used VMware Fusion 7.0.0 on Max OSX 10.11.4 "El Capitan" with 8 GB RAM. I did not use Easy Install, as the VMware Tools installer fails when Ubuntu is installed with Easy Install.

In my case, the video resolution was way off and there was no way to adjust it until after the installation had been completed. The windows presented by the installer were larger than the available space on the screen. I tabbed through the UI elements until I thought I had reached the "Next" button on each panel of the installer. The "Next" button was often not visible due to the video resolution problem. If you have installed Ubuntu before, then you can guess when the correct UI element has focus. Otherwise...good luck.

I configured the VM to use 3 GB of RAM, and to support USB 3.0. USB support is for 2.0 by default.

2. Install VMware Tools

With the VM running, open the Virtual Machine menu from the VMware Fusion main menu and choose "Install VMware Tools". (If your host operating system is not OSX, then I must trust you to know the equivalent steps for the virtualization product you're using.) This will mount a virtual drive. Copy the compressed installation files from the virtual drive to a more convenient location, such as Desktop. Note the product version number is embedded in the filename, so look before you copy/paste.

sudo cp "/media/[userid]/VMware Tools/VMwareTools-9.8.3-2075148.tar.gz" ~/Desktop/.

Uncompress the file with File Manager or on the command line with

cd ~Desktop tar -zxvf "VMware Tools/VMwareTools-9.8.3-2075148.tar.gz"

The VMware prompt suggests you run vmare-install.pl but doesn't tell you where to find it. It's in a directory named vmware-tools-distrib in the location where you unpacked the gzip file.

cd vmware-tools-distrib
./vmware-install.pl

3. Install Apache, MySQL, and PHP packages

This is where the multitude of helpful posts online are all wrong in different respects. After some trial and error, the following packages worked for me:

sudo apt -y install apache2-bin \
    mysql-server \
    php \
    libapache2-mod-php \
    php-mcrypt \
    php-mysql \
    php-mbstring \
    php-gettext \
    phpmyadmin

The MySQL installer will prompt you for the root password. Otherwise, these pretty much just run unattended.

4. [optional] Install some additional packages that may be helpful

These packages are not required for Wordpress to run. Atom is a better text editor than the Ubuntu default editor, Gedit. Gimp is useful for preparing images you want to upload to the site. You could just as well use any suitable tools according to your own preferences, or none, if you don't need to work with text or images outside of Wordpress.

sudo add-apt-repository ppa:webupd8team/atom
sudo apt update
sudo apt -y install atom
sudo apt -y install gimp

The Microsoft TrueType fonts are generally useful. They are not required for Wordpress, but it's good to test your site with them as many of your users will be running a Microsoft operating system that has these fonts installed by default. The installer will prompt you to accept the license agreement.

Be careful of the spaces and dashes in the fc-cache command. The command is fc-cache with no spaces. The command-line argument is -fv. There is a space between the command and the argument, and the agrument starts with a dash.

sudo apt -y install ttf-mscorefonts-installer
sudo fc-cache -fv

5. Tell Apache about phpMyAdmin

With sudo, edit the file /etc/apache2/apache2.conf. Add the following line:

Include /etc/phpmyadmin/apache.conf

Then restart the apache server so it will pick up the change:

sudo systemctl restart apache2

6. Install vsftpd

To support the import of the old Wordpress site, we need ftp support. On Ubuntu, that means installing vsftpd.

sudo apt-get -y install vsftpd

Now configure vsftpd to support writing to local files. With sudo, edit the file /etc/vsftpd.conf and uncomment the following line:

write_enable=YES

7. Configure PHP to allow larger file uploads

By default PHP will support file uploads of up to 2 MB. To enable Wordpress to import the exported site from wordpress.com, we need to increase this limit. (Well, to upload most anything, really.) With sudo, edit the file /etc/php/7.0/apache2/php.ini. Find the line that specifies upload_max_file_size and increase the value to support the exported Wordpress site file.

upload_max_file_size=20M

8. Download Wordpress from wordpress.org and install it

Using a web browser, navigate to wordpress.org and download the latest version of Wordpress. Unpack the distribution and copy all the files under the wordpress folder to /var/www/html/. Don't copy the wordpress folder itself; just its contents.

Follow the instructions documented at http://codex.wordpress.org/Installing_WordPress">http://codex.wordpress.org/Installing_WordPress>http://codex.wordpress.org/Installing_WordPress and http://codex.wordpress.org/Editing_wp-config.php to complete the basic installation. Use the userids and passwords listed above.

9. Set file permissions to allow copying the existing site content

sudo chmod -R 777 /var/www/html/wp-content

10. Export the old site from wordpress.com

Log into the source Wordpress site, go to Dashboard -> Tools -> Export and choose "All content". Copy the downloaded file to the target VM.

11. Import the old site content to the new Wordpress instance

On the new site, go to Dashboard -> Tools -> Import and choose the Wordpress import plugin. First the plugin will be installed. Then you can use it to import the site content you extracted from the old site. Use Upload file and import and select the extracted content. You will be prompted to change the username of the owner of the content. Change it to the user you defined when you completed the Wordpress installation in step 8.

12. Apply a theme

The export/import process does not copy the theme in use on the original site. On the new site, go to Dashboard -> Appearance -> Themes and choose "Add new theme". You'll be taken to the collection of themes available from wordpress.org. Choose the one you want and apply it to the new site. (I selected Storefront at the time I did this.)

13. Configure the new site to have a static front page

This configuration is not copied by the export/import process. On the new site, go to Dashboard -> Appearance -> Customize -> Static Front Page. Select the radio button labeled "A static page" and choose "Neo Pragma" as the front page and "Blog" as the posts page.

14. Configure the subtitle of the new site

The subtitle (or "tagline") is not copied by the export/import process. On the new site, go to Dashboard -> Appearance -> Customize -> Site Identity. Replace the default text with "[your tagline]".

15. Install plugins to support ecommerce

On the new site, go to Dashboard -> Plugins -> Add New. Install the following plugins:

  • WooCommerce
  • WooCommerce Bulk Discount

When you are ready to put your site online, you'll want to be sure the Paypal settings are correct, and configure whatever payment gateway plugin you're using. Those steps are out of scope for this article.