Comparing nginx memory usage to apache2

I’ve trimmed down my apache conf to work ok for a small site, but after uploading my exported data from my old site to my new, the 4x apache2 processes have grown considerably and consumed all my VPS memory. Knowing nginx has a much lighter footprint, I wondered what it would look like in comparison.

Here’s the memory usage after completing my exported data file imports – I get that after completing this imports to the new site this is the memory usage of the apache processes after load from importing about 20x 10MB xml export files. At idle after a restart the memory usage does start considerably lower, but here’s where I’m at right now:

$ ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r
%MEM %CPU   RSS    VSZ COMMAND
32.2  1.7 169228 904300 /usr/sbin/mysqld
24.5  1.2 128684 385360 /usr/sbin/apache2 -k start
20.2  0.2 105968 355004 /usr/sbin/apache2 -k start
18.4  4.0 96740 352540 /usr/sbin/apache2 -k start
 2.5  0.0 13144 283312 /usr/sbin/apache2 -k start

So following the guide here just to install nginx and the fastcgi php, and then here for WordPress specific config, here’s what it looked like on restart:

$ ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r
%MEM %CPU   RSS    VSZ COMMAND
 9.3  0.4 49124 576488 /usr/sbin/mysqld
 6.0  0.0 31516 235504 php-fpm: pool www                                                       
 4.5  0.0 23860 232660 php-fpm: pool www                                                       
 2.6  0.0 14032 230016 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)                    
 0.5  0.0  2804  86472 nginx: worker process
 0.3  0.0  2004  86128 nginx: worker process
 0.3  0.0  2004  86128 nginx: worker process
 0.3  0.0  1988  86128 nginx: worker process
 0.3  0.0  1900  33188 init
 0.2  0.0  1452  85832 nginx: master process /usr/sbin/nginx

This is looking better, still need to work on getting the mysql usage down, but at least now I’m not maxed out:

$ free
             total       used       free     shared    buffers     cached
Mem:        524288     431192      93096      68180          0     259440
-/+ buffers/cache:     171752     352536
Swap:            0          0          0

 

Exporting WordPress content from one site and importing to a new site

WordPress has built in tools to export existing content which you can import into another WordPress site, but if you have a large site, you might run into this error when importing your exported data file:

Sorry, there has been an error.
File is empty. Please upload something more substantial. This error could also 
be caused by uploads being disabled in your php.ini or by post_max_size 
being defined as smaller than upload_max_filesize in php.ini.

There’s two parameters here that you can increase: upload_max_filesize and post_max_size. If you increase these, post_max_size should be larger than upload_max_filesize (more info here).

Next up, if you have a very large site, no matter how much you increase these params, they still might not large enough to upload a single export file. In which case, there are utilities to split the exported data xml into multiple smaller files. Here’s one example here I just and it seemed to work well.

Setting up WordPress on Apache and MySql on a Linux VPS host

I’ve run this blog for the past couple of years on OpenShift Online. I’ve been excited that the new Online v3 is moving to a container based service, but the cost per month is now much more than I wanted to pay. I was about to setup WordPress on AWS in an EC2 instance (if for nothing more than to get some experience playing with EC2), but after posting on Twitter for suggestions, there was a suggestion to check out cheap Virtual Private Server (VPS) offerings. The lowendbox.com site covers many offers from hosting companies offering VPS based services, so I took a look and picked up a 2 CPU core, 512MB, 200GB disk VPS for $2.50 a month. That’s a manageable cost and looks like a comparably price for a low end VPS server.

To get started after provisioning my VPS , I created a new user with sudo access instead of using the default root user created on initial setup:

  • adduser newuser
  • usermod -aG sudo newuser

On my Ubuntu 14.04 minimal server install, apparently even sudo is not yet installed, so per steps here, su’d to root, and then installed sudo:

  • su -
  • apt-get update
  • apt-get install sudo

Installed mysql-server. There’s many guides for installing MySQL, but here’s one as a reference.

  • sudo apt-get update
  • sudo apt-get install mysql-server

During installation I got this error, and the server failed to start during installation:

/var/lib/dpkg/info/mysql-server-5.5.postinst: line 150: logger: command not found
ATTENTION: An error has occured. More info is in the syslog!

From this post here, the fix is to:

  • apt-get --reinstall install bsdutils

As this ran, the mysql install started showing additional input and the server started up.

Next, setup:

  • sudo mysql_secure_installation

Followed the prompts and remove anonymous user access, test database etc.

Created a new MySQL database with user/password that WordPress will use to access the database, following steps here.

Installed apache:

sudo apt-get install apache2

Installed php modules for apache:

sudo apt-get install php5 libapache2-mod-php5

Hitting the WordPress setup url, got this error:

Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

This is fixed by installing the php mysql package (discussed here):

apt-get install php5-mysql

Installing WordPress from scratch is covered in detail here. The only additional step I needed to do was to tell Apache to server index.php so you’d see the WordPress site when hitting the site root url.

This can be done by editing /etc/apache2/apache2.conf and adding a DirectoryIndex:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        DirectoryIndex index.php
        Require all granted
</Directory>

Restart apache and you should be up and running:

sudo service apache2 restart

As  start this is pretty good. It looks like the default apache and mysql settings are maxing out my 512MB so I’ve got some tuning to do, and then I need to migrate my WordPress database across, but so far so good!

WordPress Permalink formats

Having just moved my WordPress blog to OpenShift, it’s amazing how many settings apparently I had tweaked and customized on my previous site. I just followed a Google search link to one of my own posts and got a 404, and realized that the link format to my posts had changed.

I used to have links like /year/month/day/postname and now only URLs that looked like ?p=number. The first format is one of the Permalink formats. You can customize this in Settings/Permalinks. More info here.