Categories
advice and tips

Move WordPress from Share Hosting to DigitalOcean

Reading Time: 4 minutes

(Original 11-12-2015)
I decided to give cloud server another try, after my failed attempt to move WordPress from shared hosting to Amazon AWS last year. This time I go with DigitalOcean as I heard good things from my friend Don (who made this cool makeyourcase site and api).

Decision choosing Apache or Nginx
I chose Nginx over Apache due to 2 reasons:
1) I had fairly bad experience running Apache web server on Amazon tc2 micro instance last year. It was fighting for resources with MySQL server;
2) I saw Nginx getting popular recently. And it must have its own strength (performance, scale better). Did read Apache vs Nginx: Practical Considerations.

Some tips and tricks
1) Need to fix the extension for php in nginx setting. Follow this instruction will help, for php the key is the location setting below:

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

2) I found again I could not update the plugins after the move, found again this is due to file permission problem. After I grant the correct file permission to wp-content folder, it appears update plugin fine (kebo twitter plugin). Actually the initial problem was the twitter feed was not showing, which leads me to the plugin update. In the process I also changed the twitter feed.

3) A related problem is I went to this maintenance page, after I started updating a bunch of plugins. It appears stopped at the “related post” plugin.

Briefly unavailable for scheduled maintenance. Check back in a minute.

The fix was to delete the .maintenance file in the website root folder (refer to this thread at wordpress site)

Useful links
WordPress
How To Install WordPress with Nginx on Ubuntu 14.04

How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 14.04

Virtual host
How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS

Host name (DNS)
How To Set Up a Host Name with DigitalOcean

Migrate
How To Migrate WordPress from Shared Hosting to a Cloud Server with Zero Downtime

Ubuntu initial setup
Initial Server Setup with Ubuntu 14.04

Additional Recommended Steps for New Ubuntu 14.04 Servers (think security 🙂

How To Add Swap on Ubuntu 12.04

In general, I think those articles/tutorials above made the job of newbie’s much easier. For me personally I have some UNIX/Linux/Mac experience (and concept), but I’ve never done system admin job full time. Those instructions made my life much easier.

Overall impression 
I spent about total 3 hours to spin up the Linux server, MySQL and nginx web servers, install and set up WordPress, and move site from shared hosting to droplet. The next step is to see the reliability of this setup, if everything is ok, I plan to move stlplace.com to here.

(Update 12-02-2015)
Started working on moving stlplace.com from shared hosting to droplet. That site is about 10 times bigger because it has my 10 years blogs. Encountered a few problems shown below. Was able to overcome so far. It’s up and running and let’s see if the droplet will hold up 🙂

1) Moving of mysql database: from my past experience, direct export via phpmysqladmin won’t work. I tried command line approach again. Note I tried the .gz file format as well, but it failed during import (may due to my data problem in the old mysql db). But regular .sql importing worked.

2) The permanent links stopped working, after looking at the php setting for nginx, file (folder) permission, finally I was able to compare this with uudaddy.com, and found I miss this line for /etc/nginx/sites-available/stlplace.com :
try_files $uri $uri/ /index.php?q=$uri&$args;

After adding this line, the permanent links worked.

The remaining task is to make Chinese characters show properly. I encountered this problem last time when moving it to Amazon AWS. Luckily I found this life saver from wordpress.org (I kind of sensed it as I read from the old wp-config.php, I something much simpler, it does not have the following 2 lines):
======
Not encoding – collation.
In the newer version of WP the config file has two new lines:

define(‘DB_CHARSET’, ‘utf8’);
define(‘DB_COLLATE’, ”);
If it is an upgrade, delete those two lines!
======

Last but not least, I found I could not update the plugin again after installation. After much try and error, trying to emualte uudaddy.com setup (which works), I found this article on digitalOcean about setup wordpress FTP user/keys for update. I followed along and was able to made it work as desired.

(Update 12-03-2015) I also moved a small wordpress site (happymandarin) from shared hosting to droplet. The one obstacle here was I manually changed the ‘siteurl’ and ‘home’ of wp_options table from happymandarin.stlplace.com (this is a legacy of shared hosting feature) to www.stlplace.com/happymandarin. Btw, this is my wife’s site.

(Update: sometime in the early part of 2019, likely between Apr to June) I updated the ubuntu from 14 to 16, in the process I also upgraded the PhP version. Had to do a small fix (change) to make sure the php continues to work on nginx side.

(Update 03-14-2020 Pi Day) I moved the uudaddy.com wordpress site under stlplace.com/uudaddy. There was some small technical challenges, but the steps are similar to the one above. I also found out the wordpress update (one click update) prompt me to the annoying ftp credentials. It seems the digital ocean article above (2013) no longer works. I changed the folder ownership from wp-user:wp-user to www-data:www-data, as well as adding this line define(‘FTP_METHOD’, ‘direct’ ); to wp-config.php , now the one click update seems to work. Not sure if it will have any other issues for example, upload a picture in wordpress etc. I will update as time goes.

Btw, the reason I moved uudaddy.com (not renewing the domain) is mainly for consolidation. The godaddy.com asks for $18 for domain per year. It seems to me it’s a bit overpriced. My stlplace.com domain expires in 2022. That’s the only dependency I have for godaddy. For some tech people, it seems Godaddy does not have high reputation.

Also, how to get free ssl cert.

Categories
Site Info Software development Web

Moving wordpress from shared host to aws ec2

Reading Time: 2 minutesI did an experiment recently trying to move my wordpress website from a shared hosting site to Amazon aws ec2 micro instance (t1). The migration was mostly successful, I did not make the move eventually due to some technical and non-technical reasons. Nonetheless, I would like to share some of the lesson I learned from this process. I followed this blog post form smashmagazine as a blueprint for “moving wordpress”. Note I already have ubuntu installed on ec2, and has setup keys for my laptop.

1) Setup wordpress on new host. This is the link I followed to setup wordpress on ubuntu on my aws ec2. Another useful article is here.

2) Upload files: I used FileZilla (SFTP) for uploading the files. Here is the link regarding setup keys. Note the file permission is also very important to make wordpress work, which is especially important when moving the sites. More on this later.

3) File permission, one thing I noticed quickly is I don’t have any writing privilege after moving, e.g., update plug-ins etc. Did google quite a bit, and tries to change the file permissions using FileZilla. No luck. Eventually I read this from wordpress official doc. Quote:…(a) file ownership: all of your WordPress files must be owned by the user under which your web server executes. In other words, the owner of your WordPress files must match the user under which your web server executes. The web server user (e.g., “apache”, “web”, “www”, “nobody”, etc.) is not necessarily the owner of your WordPress files…

I did “ps -ef|grep httpd” at my ubuntu server, and find the user for apache web server (not “root”). And changed the file owner to this user (via “chown” command).

4) MySQL server crash: I found this happens quite often (as often as once every 3 days). Turns out to be a memory problem for the t1 micro instance and apache web server and mysql fights for the memory, eventually mysql lost. The solution I found is add virtual memory to the system, and reduce the memory requirement for mysql in config file. Eventually I was able to have mysql run as long as 13 days without shutting down. Not ideal, but still meaningful improvement (13 days uptime vs 3). Another idea, people talked about is use a lightweight http server such as this one.

5) MySQL database migration. Found out for large database, php export will not complete, and will end up with some junk html in the database file (.sql), it will fail during import. The workaround is do the export and import in the mysql command line. But I still have one problem with database, it appears the Chinese character got lost during this process. This problem along with the mysql server problem mentioned above, and the relative higher cost of AWS compared to shared host, made me decide to not switch at this time.

Other links:
Setup php/mysql, and phpMyAdmin.

Craig Emerson has an up-to-date article on this topic WordPress CloudFront CDN Setup Using W3 Total Cache.

Categories
iPhone app Software development Web

Software updates

Reading Time: 2 minutesWordPress 3.1.1
Finally I got hands around my blog (this one stlplace) and did the WordPress upgrade. I put off the upgrade in the past primarily due to my laziness: there is no automatic update due to I was running on WP 2.0.2. The upgrade itself is not too bad, I followed those two articles on Backup database and Run manual update. I used phpMyAdmin for the WP database backup. For the WP upgrade the only tricky part for me is:

“…Upload the individual files from the new wp-content folder to your existing wp-content folder, overwriting existing files. Do NOT delete your existing wp-content folder. Do NOT delete any files or folders in your existing wp-content directory (except for the one being overwritten by new files)…”

I know “directory overwriting” generally works on Windows system, but we are talking about UNIX (Linux to be precise). The command I used goes like this (in the blog root directory):

cp -r -u new_wp-content_dir .
(here -r means recursive for directories; -u means update)
I believe it did the trick, as I can run upgrade database afterwards. After that I enabled the necessary plugins. The only plugin stopped working is the ultimate warrior tags. The rest are fine.

Btw, I also added WPtouch plugin so that this blog works better on iPhone.

Xcode 3.2.6
I found my old Xcode 3.2.2 can not handle block as it’s necessary to run Ray’s RSS reader example. Download the software from Apple, install, and found this “Base SDK missing” in the new Xcode. Did some google, the trick is to “use latest SDK” in the “project => build” setting. I noticed we can also build “older” targets by changing the target in “deployment target”. Obviously there is a limit as to how far we can go back (I have not checked that yet).

Btw, I found the iPhone 4 simulator looks cooler than iPhone 3 simulator 🙂

Categories
Site Info

Added tags

Reading Time: < 1 minuteI added the “tags” for this blog. There are two places you can see the “tags”: under the time in each post; the right side bar (under “tags”). So what is “tag” exactly? Using non-technical terms, tags is like “key words”. “Tag” helps organize and search the blogs.

To use it, you just simply click on the “tag”, and it will show the related articles which contains that “tag”. The “tags” cloud map in the right side bar ranks the popularity of each tag by the size of “tag”. The larger the font, the more popular it is.  

If you are really curious about how to make this work in WordPress blog, here is the link for “Ultimate Tag Warrior plug-in”.

Believe it or not, although “Google search” is so good, in lots of cases the “tags” created by human beings are much better in organizing and searching blogs. I am also including the definitions for “tags” from the blog search engine Technorati here. 

Categories
Site Info

Get started 使用说明

Reading Time: 3 minutes(Updated May 2011) “古人云,人不自信谁人信之.” Others won’t believe in you unless you believe yourself. –Chinese proverb

Hello, world 🙂 I am not another expert. I am an ordinary guy who believes: by lifetime learning, hard and independent work and discipline, little guys can achieve their dreams, too.

I grew up in China. Currently I am working on iOS (iPhone/iPad) app development. Here I’m also blogging about iOS app/software development, business, personal finance, and other fun stuffs in life. You can leave comment here or Email me: if you wish to remain private.

Tip: you can always hit “home” or type www.stlplace.com to get back to the home page.

Search: please refer to the “search this site” page, as this is a bit complicated.

Related post: I added “related post” functions to this blog today. Basically it will show “related posts” at the end of each article if you go to each post (by clicking on the title). Hopefully this will make navigation of this blog a bit easier. Now we have search on the side bar (search by word, search by Google), and this related post thing. I also added “save to del.icio.us” button at the bottom of each post.

Revisions
(5-28-2011) Converted Ultimate Tag Warriror to WordPress tag, by importing and enable tag cloud in side bar. More information on U can be read here.

(April, 2011) Upgrade to WordPress 3.1.2, the only thing not working is Ultimate Tag Warrior.

(12-12-2009) Added my twitter widget. The Google Conversation Elements were removed earlier due to lack of interest. Note “Share This” Button at the end of each post has the buttons for Twitter, Facebook etc. Enjoy!

Added Google Conversation Elements.(May 30, 2009): this is to facilitate interesting and intelligent discussions on things. Enjoy!

Used compact archive (May 30, 2009): link to plugin.

Added “Share This” button (May 22, 2009): this is for bookmark and sharing with your friends. Try it out 🙂

Switch to a three column theme (simplicity), this allows for more room for side bars. (Dec 2007)

Tanslation: I added a language tool at the right side bar. You can click on the flag to get an instant translation of this blog. This is not perfect and sometimes it does not work because of server problem. But at least you can get a glimpse of what I’m talking about. (May 20, 2007)

My view on stocks: Information is provided ‘as is’ and solely for informational purposes, not for trading purposes or advice. (Mar 15, 2007)

Pictures: some of the pictures (those hosted on flickr and yupoo) are clickable. You can see a bigger picture if you click on it. (Mar 12, 2007)

Subscription: besides point your web browser to stlplace.com, you can also use “Add to My Yahoo”, subscribe to “feedburner” or “newsgator” to get the latest post. Pick your favorite way to get the blog: type in web address and check if there is anything new (the so called “pull” method); or the RSS subscription (so called “push” method, the new post is pushed to your web page automatically). (sometime in 2006)

Dec 2005, initial release.

(Original Dec 2005) Hello, world. I am not another stock expert. I am an ordinary guy who believes that: by learning and disciplined investing little guy can beat many “experts”.

At STLPlace, we believe in independent research and value investing. We don’t blindly chase hot stocks, we don’t follow Jim Cramer, and we don’t catch falling knives…

I grew up in China and have been in the US since Fall 1997. Here I’m blogging about business, finance, stocks, other fun stuffs in the US and China.

This is a place I’m sharing my thoughts. Please don’t take this as a stock tip and run with it. One selfish reason for this blog is to organize my thoughts and actions on stocks, and be a better investor along the way. Hopefully you can also benefit from this process: the result matters, but more importantly is how we get there, so that we can repeat the success.

Any comments, please send email to: