I got a vServer by Hetzner and I chose a 64bit CentOS 5.5 install. Now I need to transfer Wordpress to it with all my stuff, like database, plugins, themes and special settings like pretty permalinks.
I want to achieve all of this without any additional tools or backup plugins. In my experience WP backup tools mess with SQL tables and produce more headaches than necessary.
If this is a fresh install of Linux you should read on.
Why not start with adding an user to your fresh CentOS install. It's never a good idea to login with a root password. You should rather elevate your rights with su or sudo when needed and login via SSH with a user with less permissions.
[root@CentOS ~]#useradd someName -g someMainGroup [root@CentOS ~]#passwd someName
The command -g someMainGroup will add the user to the any default group of your liking. -G would add the user to any secondary groups. You can always change these settings with usermod later.
I would use Public-key Authentication since it uses identity keys to authenticate individual users. The identity key has its own passphrase so it will protect my system login. Copies of the public key will have to be distributed to every host that I want to access. The private key should stay protected and must not be shared.
Secondly I would change the port to a nonstandard port because automated attack kits are likely to try brute-forcing their way in via port 22. This has the additional beneficial effect of lightening the load on any firewall logfiles.
As pointed out in the comments below by MidnighToker using plain FTP is a very bad idea. I decided to remove my FTP section completely because it wasn't secure. Because setting up SFTP on CentOS / RHEL with added security -a chroot jail- is rather difficult, I dedicated an entire [blog post] to that topic. The post will cover how you upgrade openSSH 4.6. to 5.6 on RHEL / CentOS by compiling from source building your own rpm package.
LAMP stands for Linux, Apache, MySQL and PHP. To deal with this in one go we log into our web server and type into the shell:
yum install mysql mysql-server httpd php php-mysql -y
Above line uses the Yellow Dog Updater Modified to install a complete LAMP system. The -y switch means "assume that the answer to any question which would be asked is yes" (yum manpage, 2010)
Next, we have to have to insure that our services that we installed just a minute ago will start up after reboot. We do this with chkconfig, a system startup linking tool. It manages the symbolic links of the services inside the /etc/rc[0-6].d directory. These links would point to the startup scripts inside /etc/init.d. You could do this manually for the runlevels you need, but Redhat, Fedora and thus CentOS features chkconfig. In Debian you would have to use update-rc.d
chkconfig --levels 235 mysqld on
Better do it in one go:
chkconfig --levels 235 mysqld on && chkconfig --levels 235 httpd on && /etc/init.d/mysqld start && /etc/init.d/httpd start
The operator && does execute the next command if the previous one executed was successful. Now that your Apache server and SQL server is running, we will have to setup some security in MySQL.
mysqladmin -u root password mysecretphrase
Rather use this command since it is more secure and sets also a root access mask:
If you now try to login into mysql and get an access denied then most probably your SQL server has no Grant-tables setup. Do this with the following file:
Create a database, furthermore a SQL user and give him permissions.
mysql -u adminusername -password=yourPass CREATE DATABASE databasename; GRANT ALL PRIVILEGES ON databasename.* TO wordpressusername@hostname IDENTIFIED BY "password"; FLUSH PRIVILEGES;
Flushing Privileges empties the SQL servers cache.
Restore your database with:
mysql -h mysqlhostserver -u mysqlusername -p databasename < blog.bak.sql
Go into the httpd.conf file which you can locate with find / | grep httpd.conf.
I would change below settings to get things started. You can use vi with its / slash to search for the respective setting.
KeepAlive On ServerLimit 40 MaxClients 40 ServerAdmin yourMailAdress ServerName www.yourDomain.com:80
KeepAlive On is one of the important features of HTTP 1.1, so enable it. With this enabled apache and a client will use a single TCP/IP connection to send continuous data instead of opening many simultaneous TCP connections. Every TCP connection goes through the slow start algorithm before reaching maximum transfer speed -the slow start threshold- so in essence KeepAlive On ensures faster loading of Web pages.
Lowering the ServerLimit ensures that your server will not hang or crash due to extreme swapping of memory. A server swaps memory from RAM to its pagefile or swap partition when for instance apache requests too many memory due too many open HTTP requests. The same goes for MaxClients. You should lower this value in both - the module section of prefork.c and worker.c
Set AllowOverride All to allow the file .htaccess do its magic. We will configure it later for pretty permalinks.
You could also add %T/%D in the LogFormat line to enable the module mod_headers to measure the time your server takes to process a HTTP request from the receival of the HTTP headers to delivery of the response headers.
If you want ErrorDocuments to be served properly, you should uncomment the line following #ErrorDocument 400.
Finally we setup our default virtual server, which will be taken as default server if any additional virtual servers cannot be resolved by apache. Since we defined ServerAdmin and ErrorLog earlier it is not necessary to define this again for our virtual server, but you could of course user alternate log file locations or ServerAdmins.
NameVirtualHost *.80 <VirtualHost *:80> DocumentRoot /var/www/html/yourdomain ServerName yourdomain.com ServerAlias www.yourdomain.com </VirtualHost>
Now create the directory for your domain at /var/www/html/ otherwise apache will not start. Give this directory permissions with chmod 775, in order for the owner and the group having full permissions. You can change the group of the directory with /usr/bin/groupmod.
To enable compression in Apache I would add the recommended code taken from the apache 2.2 documentation.
<Location /> # Insert filter SetOutputFilter DEFLATE # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0 no-gzip # MSIE masquerades as Netscape, but it is fine BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # Don't compress images SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-var </Location>
The Location directive makes sense as the apache documentation states:
"Location sections are processed in the order they appear in the configuration file, after the Directory sections and .htaccess files are read, and after the Files sections."
New Domain Name
In case you are not only moving WordPress but also changed your domain name you would have to alter the WordPress adress and Site address in the General Settings prior to making a SQL backup. Be aware you can lock yourself out if you change these settings. I would recommend to make the SQL backup and after restoring it on your new server I would change the domain settings with these SQL queries:
use yourDatabase; UPDATE 'wp_options' SET 'option_value' = 'http://newDomain.tld' WHERE 'option_id' =1 AND 'blog_id' =0 AND 'option_name' = 'siteurl' LIMIT 1 ; UPDATE 'wp_options' SET 'option_value' = 'http://newDomain.tld' WHERE 'option_id' =46 AND 'blog_id' =0 AND 'option_name' = 'home' LIMIT 1 ;
You can also do this with phpMyAdmin with these queries:
SELECT 'option_value' FROM 'wp_options' WHERE option_id =1 AND blog_id =0 AND option_name = 'siteurl' LIMIT 1 ; SELECT 'option_value' FROM 'wp_options' WHERE option_name = 'home' LIMIT 1 ;
Moving WordPress itself from one server to another is the simplest part. Just download your whole WordPress folder via FTP. That is the one where directories wp-content, wp-admin and so forth reside in. Then upload it via our secure openSSH/SFTP connection. Don't forget to include your .htaccess file in case you want to use permalinks.