(-3)
(Install and configure mysql, install php)
Line 63: Line 63:
yum install php-mysqli
yum install php-mysqli
</source>
</source>
-
The configuration of php is in /etc/php.ini ... here is '''php.ini'''modified and the mysql configuration in '''/etc/my.cnf''':
+
The configuration of php is in /etc/php.ini ... here is '''php.ini''' modified and the mysql configuration stored in '''/etc/my.cnf''':
<source lang="diff">
<source lang="diff">
# diff /etc/01-php.ini /etc/php.ini
# diff /etc/01-php.ini /etc/php.ini
Line 108: Line 108:
mv phpMyAdmin-x.y.z-all-languages abc123
mv phpMyAdmin-x.y.z-all-languages abc123
</source>
</source>
-
phpmyadmin sarà ora accessibile da http://server_IP/abc123 ... ma prima bisogna modificare la linea di '''config.inc.php''' da:
+
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';
  $cfg['Servers'][$i]['auth_type'] = 'cookies';
-
a:
+
to:
  $cfg['Servers'][$i]['auth_type'] = 'http';
  $cfg['Servers'][$i]['auth_type'] = 'http';

Revision as of 23:53, 19 December 2012

(draft ...)

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

Installare 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';

Migrare i siti web ed i database da un server all'altro

Per trasferire il codice dei siti web da un server all'altro ho preferito fare un tar.gz della cartella html, trasferendola poi con scp ... esempio:

sul veccho server:

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

sul nuovo server:

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

per i database ho usato invece alcuni script per il dump ed il restore ... ho creato un file di testo con nome_db, utente e password:

db_list.txt, file di testo con le credenziali di accesso ai database

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

dumpdbs.sh, dump dei database presenti sul vecchio 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, caricamento dei database sul nuovo 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

Convertire i database mysql in utf8

Alcuni cms trasferiti,in particolare moodle, segnalano che il database non è utf8 ... ecco uno script che risolve: scarica il database .sql, lo converte in utf8 e lo ricarica in 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

Soluzione di alcuni problemi con i cms installati

Ecco alcuni dei problemi riscontrati in runtime e relative soluzioni

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 block sendmail via php by default, to solve:

setsebool -P httpd_can_sendmail 1

command line "mail", mail rejected

Sendmail invia le mail da linea di comando ma queste vengono respinte. E' spesso un problema di nome di dominio, per risolvere setta un nome di dominio valido collegato all'IP del server (come da pannello DNS):

hostname my_valid_domain.dom

Riferimenti

CentOS - install apache server
How to install MySQL
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"