![]() |
![]() |
![]() |
![]() |
![]() |
Vsebina
|
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) .
Let's start: after a long wait, here is new Linux dedicated server, I connect for the first time 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:
great machine!!! ...
The server is just installed 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
... 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
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
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';
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
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
Here are some of the problems encountered at runtime and their solutions
error:
service mysqli not found in config.php.ini
solution:
yum install php-mysqli
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"
Some errors in admin panel, solved installing these packages
yum install php-mbstring yum install php-xmlrpc yum install php-gd
In CentOS selinux inhibits sendmail via php by default, to solve:
setsebool -P httpd_can_sendmail 1
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