(Installare phpmyadmin)
(-5)
Line 1: Line 1:
-
(draft ...)
 
= Migrate sites from a Linux dedicated server to a new webserver =
= Migrate sites from a Linux dedicated server to a new webserver =
In this tutorial some practical examples for who have to transfer data and webserver configuration from a dedicated Linux server to a new server. The information contained in this article are to be intended "as is" and without any warranty, however I believe that this brief history may be useful to someone (even to myself, when I will try to remember how I made it) .
In this tutorial some practical examples for who have to transfer data and webserver configuration from a dedicated Linux server to a new server. The information contained in this article are to be intended "as is" and without any warranty, however I believe that this brief history may be useful to someone (even to myself, when I will try to remember how I made it) .
Line 288: Line 287:
:[http://dev.antoinesolutions.com/apache-server CentOS - install apache server]
:[http://dev.antoinesolutions.com/apache-server CentOS - install apache server]
:[http://dev.antoinesolutions.com/mysql How to install MySQL]
:[http://dev.antoinesolutions.com/mysql How to install MySQL]
 +
 +
[[Categoty:How to]] [[Category:Highlight news]]

Revision as of 00:24, 20 December 2012

Contents

Migrate sites from a Linux dedicated server to a new webserver

In this tutorial some practical examples for who have to transfer data and webserver configuration from a dedicated Linux server to a new server. The information contained in this article are to be intended "as is" and without any warranty, however I believe that this brief history may be useful to someone (even to myself, when I will try to remember how I made it) .

The new server, get the features

After a long wait, here is new Linux dedicated server, I connect with ssh: ssh root @ server_ip_address. And now, how to get the features of the new server? These the commands at first login:

uname -a
cat /etc/issue
fdisk -l
free

so I get:

sistema a 64bit
CentOS release 6.3 (Final)
2HD da 2TB in RAID1
16G RAM

great machine!!! ...

Install basics services, install apache

The server is installed right at the bare minimum, "service httpd start" shows that apache is not installed; mcedit, my favorite text editor, there is no (ok, there would be vim, that s ...) ... I proceed with apache installation ... and Midnight Commander, of course:

yum install httpd
yum install mc
mcedit /etc/httpd/conf/httpd.conf
chkconfig --levels 235 httpd on
service httpd start
with "chkconfig ..." I made ​​permanent starting httpd
in /etc/httpd/conf/httpd.conf I uncommented the line "NameVirtualHost *:80"

... but http://server_IP in my browser still not will respond, in CentOS we should also enable the firewall to access to port 80:

echo "-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT" >> /etc/sysconfig/iptables
/etc/init.d/iptables restart

finally I see the default apache web page in my browser ... ok, apache is installed! ... I decided immediately to eliminate the indexes for safety:

# diff /etc/httpd/conf/01-httpd.conf /etc/httpd/conf/httpd.conf
---
331c331
<     Options Indexes FollowSymLinks
---
>     Options FollowSymLinks
554c554
<     Options Indexes MultiViews FollowSymLinks
---
>     Options MultiViews FollowSymLinks

Install and configure mysql, install php

mysql is also not installed, proceed with the installation:

yum install mysql mysql-devel mysql-server
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start

and php and mysql library, since these are missing:

yum install php
yum install mysqli
yum install php-mysql
yum install php-mysqli

The configuration of php is in /etc/php.ini ... here is php.ini modified and the mysql configuration stored in /etc/my.cnf:

# diff /etc/01-php.ini /etc/php.ini
729c729
< post_max_size = 8M
---
> post_max_size = 24M
878c878
< upload_max_filesize = 2M
---
> upload_max_filesize = 48M
#/etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set=utf8
default-collation=utf8_unicode_ci
character-set-server=utf8
collation-server=utf8_unicode_ci
 
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
 
[client]
default-character-set=utf8

How to install phpmyadmin

I decided also to install phpmyadmin for database migration ... but I will not use it, I will use some script much more reliable to dump and load the db ...

With wget I download the latest version of phpmyadmin da SF: http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/

and then I unzip the tar.gz in /var/www/html/ and rename the folder with a fancy name ("phpmyadmin" if the first name to search for network scanners):

cd /var/www/html/
wget ...
tar xzf phpMyAdmin-x.y.z-all-languages.tar.gz
mv phpMyAdmin-x.y.z-all-languages abc123

phpmyadmin will now be accessible from http://server_IP/abc123 ... but before we have to modify the line in config.inc.php from:

$cfg['Servers'][$i]['auth_type'] = 'cookies';

to:

$cfg['Servers'][$i]['auth_type'] = 'http';

Migrating data of websites an databases to another server

To move the code of the web sites from one server to another I decided to make a tar.gz of the html folder, then I move it using scp ... example:

in old server:

ssh root@old_server_IP
cd /var/www/html
tar -czplf /sites.tar.gz *
exit

in new server:

ssh root@new_server_IP
cd /var/www/html
scp root@old_server_IP:/sites.tar.gz .
tar -xzplf /sites.tar.gz

for databases, instead of phpmyadmin, I used some scripts to dump and restore contents ... I made a text file with db_name, user, and password:

db_list.txt, text file with the credentials to access databases

name_db1|user_db1|password_db1
name_db2|user_db2|password_db2
name_db3|user_db3|password_db3
...

dumpdbs.sh, dump of the database on the old server:

#!/bin/bash
# dumpdbs.sh - dump several dbs as listed in db_list.txt
ROOT_PW="old_rootpw_mysql"
 
IFS="|"
cat db_list.txt |
while read DB_NAME DB_USER DB_PASS
do
 
 echo "Dump DB $DB_NAME ..."
 mysqldump --user root --password="$ROOT_PW" $DB_NAME | gzip > $DB_NAME.sql.gz
 
done

restoredbs.sh, upload databases into new mysql server

#!/bin/bash
# restoredbs.sh - restore several dbs as listed in db_list.txt
ROOT_PW="new_pwroot_db"
 
create_db() {
 
EXPECTED_ARGS=3
E_BADARGS=65
MYSQL=`which mysql`
 
Q1="CREATE DATABASE IF NOT EXISTS $1;"
Q2="GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE, LOCK TABLES ON $1.* TO '$2'@'localhost' IDENTIFIED BY '$3';"
Q3="FLUSH PRIVILEGES;"
SQL="${Q1}${Q2}${Q3}"
 
if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Usage: $0 dbname dbuser dbpass"
  exit $E_BADARGS
fi
 
$MYSQL --user root --password="$ROOT_PW" -e "$SQL"
 
}
 
echo "DB in list are:"
echo "-"
 
IFS="|"
cat db_list.txt |
while read DB_NAME DB_USER DB_PASS
do
 echo -n "$DB_NAME "
done
 
echo
echo "-"
 
echo -n "Name of database you wish restore [all=restore all] : "
 
read DBX
 
if [ "a$DBX" == "a" ] ; then
 exit
fi
 
export BDX_RESTORE="$DBX"
 
IFS="|"
cat db_list.txt |
while read DB_NAME DB_USER DB_PASS
do
 
 if [ "a$BDX_RESTORE" == "a$DB_NAME" ] ; then
 
  echo "Restore $DB_NAME ..."
  create_db $DB_NAME $DB_USER $DB_PASS
  zcat $DB_NAME.sql.gz | mysql --user root --password="$ROOT_PW" $DB_NAME
 
 fi
 
 if [ "a$BDX_RESTORE" == "aall" ] ; then
 
  echo "Restore $DB_NAME ..."
  create_db $DB_NAME $DB_USER $DB_PASS
  zcat $DB_NAME.sql.gz | mysql --user root --password="$ROOT_PW" $DB_NAME
 fi
 
done

Convert mysql databases to utf8

Some cms that I moved, moodle in particular, shown that database is not utf8 ... here is a script that solves: dump database .sql, convert in utf8 and reload into mysql:

migratedb-utf8.sh

#!/bin/bash
 
if [ $# -ne 3 ]
then
  echo "Usage: $0 dbusername password dbname"
  exit
fi
 
#  $1-dbusername $2-password $3-dbname
mysqldump -u$1 -p$2 -c -e --default-character-set=utf8 --single-transaction --skip-set-charset --add-drop-database -B $3 > dump.sql
sed 's/DEFAULT CHARACTER SET latin1/DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci/' <dump.sql \
| sed 's/DEFAULT CHARSET=latin1/DEFAULT CHARSET=utf8/' >dump-fixed.sql
mysql -u$1 -p$2 < dump-fixed.sql

Solution of some problems with the cms installed

Here are some of the problems encountered at runtime and their solutions

phpmyadmin

error:

service mysqli not found in config.php.ini

solution:

yum install php-mysqli

phpbb

error:

function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.
We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead
[phpBB Debug] PHP Notice: in file /viewtopic.php on line 981: getdate(): It is not safe to rely on the system's timezone settings.
You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and
you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead

solution: add to /etc/php.ini

date.timezone = "Europe/Berlin"

moodle

Some errors in admin panel, solved installing these packages

yum install php-mbstring
yum install php-xmlrpc
yum install php-gd

php sendmail not send mail

In CentOS selinux inhibits sendmail via php by default, to solve:

setsebool -P httpd_can_sendmail 1

command line "mail", mail rejected

Sendmail sends mails with command line but these are rejected. Is often a problem of domain name, to resolve set a valid domain name associated to the IP of the server (as in the DNS configuration):

hostname my_valid_domain.dom

References

CentOS - install apache server
How to install MySQL

Categoty:How to

Retrieved from "http://www.zoros.org/wiki/index.php?title=Migrating_from_one_dedicated_Linux_server_to_another,_how_I_made_it,_a_simple_howto"