Moving WordPress to another Linux Operating System

The reason for moving WordPress from fedora to another OS is that other operating systems have longer support for patches and I am tired of doing a full upgrade every 6 months to a year just to pull in critical patches. This  should reduce my maintenance load and increase my security since the new OS will receive patches longer then the current version of Fedora. What I lose is all the bleeding edge software that Fedora has. But, for a production site that only provides a web service, I should not need bleeding edge. This guide is divided into three parts.

  1. Preparation for moving WordPress
  2. a test Site that uses a different DNS name from the production site
  3. Changing the OS and restoring the site in production

The preparation section should be applicable to the other two sections, Section two, where a test site is created, is highly recommended to help iron out any special needs your production site will need and also to create a test and QA site. Which is always necessary.

These notes are written for someone who has root access to their servers. Nearly all of this is done from the command line. This is basically a check list with some guidance. YMMV.

1. Preparation for moving wordpress

  • backup the settings of the theme you are using  if that is an option
  • Theme name here – download the backup
  • make a list of all nicknames. these will probably be imported. but it does not hurt.
    • Site 1
    • Site 2
  • Make a list of all the active plugins
    • Active
      • Site 1
        • Active
          • Add list here
        • Inactive
          • Add list here
      • Site 2
        • Active
          • Add list here
        • Inactive
          • Add list here
  • Foe each plugin, save all settings that are savable. Download them to another computer if that is an option.
    • Site 1
      • Add list here of plugins that have savable settings
    • Site 2
      • Add list here of plugins that have savable settings
    • Site 1
      • permalinlks
        • month-name:
      • Settings -> reading
        • Front page displays:
        • your latest posts
          • Front page:, post page
          • for each article in a feed show: summary
      • widgets – use widget import exporter to save your widgets
        • Note. This is not a perfect solution. you will still need to clean up your widgets. And dont change themes until the restore is done. Disable the plugin after you use it. Only enable plugins that you need.
    • Site 2
      • permalinlks
      • Front page displays:
        • a static page
          • front page: home
          • posts page: blog
          • for each article in a feed show: summary
      • widgets – use widget import exporter to save your widgets
        • Note. This is not a perfect solution. you will still need to clean up your widgets. And dont change themes until the restore is done. Disable the plugin after you use it. Only enable plugins that you need.
  • export your wordpress site Tools->export ( use wordpress import/export plugin)
  • backup website configuration files. Use what ever method you want. I recommend rsync.

If you are building the same site, it might be possible to just restore the files, restore the database, install the needed packages or rpms and reconfigure any special configuration files. See the third section of this post.
New packages will need to be installed since you will be migrating to a new operating system.
grabbing a systems inventory is always nice but not completely necessary in simple cases. This is a collection of important configuration settings and the actual runstate of the box. How you take an inventory is left for you to decide.

2. Creating a test site that uses a different DNS name:

This procedure is for creating a test site or local copy of your production. It’s good practice before you completely destroy production and rebuild it.
It also allows you to have a good test site for further development. Once this is set up, you should be able to do periodic imports of the data to keep the sites in sync. I would not use this as a backup method, since this is a test site and as such will not be 100% in sync with production.

  • Make sure DNS is set up correctly for the test site (or use host files).
  • Install OS of your choice. At this point in time I will be using CentOS.
  • Shutdown all unneeded services as soon as possible. basically, the only thing you need at this point is ssh.
    • service httpd stop
  • Set up firewall if necessary for the test site. Usually, you want to do this to obtain as close an emulation of production as possible.
    • Install and configure the firewall manager of your choice.
  • set up ssh.
    • Disable root logins
    • Make any other security refinements according to your standards
  • secure the site further according to your standards and best practices.
  • set up Apache configuration files. these should be copied off the main site with modifications to point to the test site.
  • Install mysql
# service mysqld start
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

	/usr/bin/mysqladmin -u root password 'new-password'
	/usr/bin/mysqladmin -u root -h baloo password 'new-password'

Alternatively you can run:
	/usr/bin/mysql_secure_installation

which will also give you the option of removing the test databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
  • Secure mysql to your sites standards and best practices
    • add skip-networking to the /etc/my.cnf file
    • default-storage-engine=[database engin of your choce]
      • Wordrepss default is MyISAM, but others can be used. You will need to do a little research regarding this if you want to change from the default. Maybe more then a “little” research.
  • Secure postfix
    • inet_protocols = ipv4
    • inet_interfaces = localhost
    • Set up /etc/aliases according to your needs
    • test using mailx. this may not work depending upon where your server is located and who you are trying to send mail to. You may have ot install the packages that contain mailx
  • Install and secure memcached if you are using it- force it to run on 127.0.0.1
  • Secure the http site
    • remove any unneeded conf files by renaming them or moving to a disable directory
      • This list will be specific to your site
  • install wordpress – use their 5 minute guide. I use the command line to install the database.
    • Using the MySQL Client
You can create MySQL users and databases quickly and easily by running mysql from the shell. The syntax is shown below and the dollar sign is the command prompt:
$ mysql -u adminusername -p
Enter password:
 
Welcome to the MySQL monitor. Commands end with ; or \g.
 Your MySQL connection id is 5340 to server version: 3.23.54
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)
 
mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname" IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)
  
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> EXIT
Bye
  • update wp-config.php
FORCE_SSL_LOGIN
FORCE_SSL_ADMIN
//  MySQL settings - You can get this info from your web host  //
/** The name of the database for WordPress */
/** MySQL database username */
/** MySQL database password */
/** MySQL hostname */
Authentication Unique Keys and Salts.
WordPress Database Table prefix.
  • Set up wordpress proxy if necessary in wp-config.php
define('WP_PROXY_HOST', 'ip-address-or-FQDN');
define('WP_PROXY_PORT', 'port-number');
#define('WP_PROXY_USERNAME', 'my_user_name');
#define('WP_PROXY_PASSWORD', 'my_password');
define('WP_PROXY_BYPASS_HOSTS', 'localhost,  domain-name,comma-separated-list')
  • change the table_prefix in the actual database to what ever you were using before and to what is set in the wp-config.php file.
RENAME table `wp_commentmeta` TO `my_new_prefix_commentmeta`;
RENAME table `wp_comments` TO `my_new_prefix_comments`;
RENAME table `wp_links` TO `my_new_prefix_links`;
RENAME table `wp_options` TO `my_new_prefix_options`;
RENAME table `wp_postmeta` TO `my_new_prefix_postmeta`;
RENAME table `wp_posts` TO `my_new_prefix_posts`;
RENAME table `wp_terms` TO `my_new_prefix_terms`;
RENAME table `wp_term_relationships` TO `my_new_prefix_term_relationships`;
RENAME table `wp_term_taxonomy` TO `my_new_prefix_term_taxonomy`;
RENAME table `wp_usermeta` TO `my_new_prefix_usermeta`;
RENAME table `wp_users` TO `my_new_prefix_users`;

UPDATE `my_new_prefix_usermeta` SET `meta_key` = REPLACE( `meta_key`, 'wp_', 'my_new_prefix_' )
UPDATE `my_new_prefix_options` SET `option_name` = 'my_new_prefix_user_roles' WHERE `option_name` = 'wp_user_roles'
  • delete the sample page
  • delete the “hello world” post
  • Set default boot up serttings
    • chkconfig mysqld on
    • chkconfig httpd on
    • chkconfig iptables off
    • chkconfig shorewall on
  • set up permalinks the way you want them to be. do this before the next step. See your preparation notes.
  • activate plugins
  • install the theme you are using
  • Import the file and choose download attachments since the original site will still be available. You want to use the wordpress import tool because it will adjust all the links and so everything will point to your new test site. If you just try to restore the database from production then your post and images may be pointing to your production site.
    • You may have to change /etc/php.ini file to allow uploading of large files.
    • /etc/php.ini file setting:  upload_max_filesize = [large number of your choice]
  • import all the specific plugin settings

3. Changing the OS and restoring the site in production

Note: due to caching, it may take some time for the site to register it’s new views if you make changes to widgets or formatting.

  • Make sure you have good backups
    • WP-DBmanager
    • mysqldump -u root -p database-name
    • Make sure you get the “mysql” database. This has all your user names and privileges for the database. If you dont have this you will have to recreate the database users.
      • mysqldump -u root -p mysql
  • backup all settings where possible
  • backup all pertinent files and folders
  • export your wordpress site Tools->export
  • backup website configuration files
  • backup the wordpress original site, I use rsync to backup to another computer.
/etc/
/home, 
crontabs,
/root
/var/www
/nagios
/usr/share/[whatever-you-are-using]
  • Install new OS of your choice
    • secure root
      • change password
      • disable root logins via ssh
    • update OS with news patches
      • yum -y update
        • reboot if necessary.
    • secure ssh
      • Disable root logins
      • Make any other security refinements according to your standards
    • install firewall manager of your choice
    • set up ntp as a client
  • secure system further according to your standards
  • Install extra packages
    • yum install memcached.x86_64
    • yum install perl-Digest-SHA.x86_64 perl-Digest-SHA1.x86_64 perl-Digest-HMAC.noarch perl-Digest-BubbleBabble.noarch
    • yum install 64 perl-DBD-MySQL.x86_64 _64 MySQL-python.x86_64
    • yum install mysql-server.x86_64
    • yum install mod_ssl.x86_64
    • yum install logrotate.x86_64
    • yum install logwatch.noarch
    • yum install aide.x86_64
    • yum install perl-CPAN.x86_64
      • yum install perl-YAML.noarch perl-YAML-Syck.x86_64 perl-YAML-Tiny.noarch
      • yum install perl-ExtUtils-CBuilder.x86_64 1:0.27-136.el6
      • yum install perl-ExtUtils-CBuilder.x86_64
      • yum install perl-Parse-CPAN-Meta.x86_64
      • yum install perl-Test-Simple.x86_64 perl-ExtUtils-MakeMaker-Coverage.noarch perl-Test-CPAN-Meta.noarch perl-Test-Harness.x86_64
      • yum install readline.x86_64 perl-Term-UI.x86_64
      • yum install perl-TermReadKey.x86_64
  • cpan>
    • install Term::ReadLine::Perl
    • install IO::Scalar
    • install other packages needed by your site and are not provided by your package manager such as yum or apt-get.
  • NOTE: I use php55w becuase i want to use php-fpm / opcache,
    • https://webtatic.com/projects/yum-repository/
    • php55w-gd-5.5.18-1.w7.x86_64
    • php55w-xmlrpc-5.5.18-1.w7.x86_64
    • php55w-pecl-igbinary-1.2.1-2.w7.x86_64
    • php55w-xml-5.5.18-1.w7.x86_64
    • php55w-mbstring-5.5.18-1.w7.x86_64
    • php55w-5.5.18-1.w7.x86_64
    • php55w-mysqlnd-5.5.18-1.w7.x86_64
    • php55w-mcrypt-5.5.18-1.w7.x86_64
    • php55w-common-5.5.18-1.w7.x86_64
    • php55w-cli-5.5.18-1.w7.x86_64
    • php55w-opcache-5.5.18-1.w7.x86_64
    • php55w-pecl-memcached-2.2.0-1.w7.x86_64
    • php55w-pdo-5.5.18-1.w7.x86_64
    • php55w-devel-5.5.18-1.w7.x86_64
    • php55w-fpm-5.5.18-1.w7.x86_64
    • php55w-pear-1.9.4-7.w7.noarch

Note: I used maraidb instead of mysql

  • mariadb-5.5.40-1.el7_0.x86_64
  • mariadb-libs-5.5.40-1.el7_0.x86_64
  • mariadb-server-5.5.40-1.el7_0.x86_64
  1. edit /etc/sysconfig/memcached
    • OPTIONS=” -l 127.0.0.1″
  • restore data base
    • install mysqld
      • add the following to /etc/my.cnf
        • skip-networking
        • default-storage-engine=innodb
          • make sure you know what type of engine you are using and set the default properly in the /etc/my.cnf file
  • Run this script: /usr/bin/mysql_secure_installation
  • mysql -u root -p database-name < msql-backup-file-for-databasename.sql
  • restore /etc/httpd files
    • conf
    • conf.d
    • Any other files you may need according to your standards.
  • Start httpd
    • httpd -t # do this to check syntax before you apply the next step
    • service httpd start
  • restore wordpress settings
    • If you restored the files and the database, you may not have to do anything here. The possible exception might be w3-total cache.
  • restore logrotate settings if needed
  • update /etc/aliases
    • newaliases
  • Set up and secure postfix
    • in /etc/postfix/main.cf
      • inet_protocols = ipv4
      • inet_interfaces = localhost
    • test using mailx. this may not work depending upon where your server is located and who you are tryin to send mail to.
      • mailx -s test username@sitename.TLD
  •  restore any local users and groups to the system

Leave a Reply

Your email address will not be published. Required fields are marked *

*