This is my recipe for replicating an existing Magento instance to a new Centos 6 Linux dedicated server. Note that there are many variations on this theme and your setup will vary depending on your configuration and particular requirements. Always do backups first and always do tests in a development environment before trying anything risky in a production environment. If you are copying to a new server that is not already running Magento, it is also good idea to do a vanilla install fronm Magento installation package first. This will ensure that you have all appropriate software pre-requisites and allow you to test email and credit card validation.
Backup Magento files with tar command. Create a tar.gz backup file.
tar cfzv /home/myMagentoScriptBackup.tar.gz /var/www/where:
mysqldump -uUSERNAME -pPASSWORD DATABASENAME > /someDirectory/dumpfile.sqlwhere:
Verify that you have php pre-requisites set up. To do this, create a program with phpinfo().
Look for section in phpinfo page with mcrypt module. If you can't find it, then try enabling it php.ini. If this does not work then install it.
To install mcyryptwget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm yum update yum install php-mcrypt*
if you get error on yum command, try
sudo yum upgrade ca-certificates --disablerepo=epel
Many Magento sites use apache mod_rewrite module. If your sites requires this, you have to make sure it is enabled.
check httpd.conf file. Make sure mod_rewrite.so is not commented out
LoadModule rewrite_module modules/mod_rewrite.sothen find all occurences of
AllowOverride Noneand change to
AllowOverride All
Create a new new VirtualHost in http.conf file. In this example, Magento code should be found in /var/www/MYSTORELOCATION and site will be called MYSITE.example.com
vi /etc/httpd/conf/httpd.conf
<VirtualHost *:80> DocumentRoot /var/www/MYSTORELOCATION ServerName MYSITE.example.com </VirtualHost>
Reboot the apache server and watch for errors
service httpd stop service httpd start
You may first have to create database and assign rights in mySQL.
Restore database from SSH (Linux command line)
mysql -uUSERNAME -pPASSWORD DATABASENAME < /someDirectory/dumpfile.sqlwhere:
You may have to delete and re-create database first if it already exists (this is simpler than clearing all tables). You may also have to GRANT ALL PRIVILEGES to specific user if you are not using default user to access mySQL.
drop database DATABASENAME; create database DATABASENAME DEFAULT CHARACTER SET UTF8 COLLATE UTF8_UNICODE_CI;
If old copy of target Magento directory is already on the target server, you may want to remove it.
cd /var/www/ rm -r MYSTORELOCATION or rm -r /var/www/MYSTORELOCATION
Use tar command to restore backed up files
tar zxvf /home/myMagentoScriptBackup.tar.gzwhere:
Depending how you created the backup, you may have to move the restore to the correct location.
mv /var/www/MYSTORELOCATION/var/www/MYSTORELOCATION/ /var/www/or a recursive copy
cp -R /var/www/MYSTORELOCATION/var/www/MYSTORELOCATION/ /var/www/
You may also want move the directory it with the move command if old name is not the same as new name.
mv OLDNAME MYSTORELOCATION
These SQL commands will indicate to Magento the name of the secure (checkout) and unsecure (everything else) base_urls
UPDATE core_config_data SET value= 'http://MYSITE.example.com/' WHERE path= 'web/unsecure/base_url';
UPDATE core_config_data SET value= 'http://MYSITE.example.com/' WHERE path= 'web/secure/base_url';
Indicate to Magento correct SQL username and password. This is contained in app/etc/local.xml. In XML below, make sure that host, username, password and dbname correspond to values in mySQL database.
vi /var/www/MYSTORELOCATION/app/etc/local.xml
<host><![CDATA[localhost]]></host> <username><![CDATA[SQL-UserName]]></username> <password><![CDATA[SQL-Password]]></password> <dbname><![CDATA[DATABASENAME ]]></dbname> <initStatements><![CDATA[SET NAMES utf8]]></initStatements> <model><![CDATA[mySQL4]]></model> <type><![CDATA[pdo_mySQL]]></type> <pdoType><![CDATA[]]></pdoType> <active>1</active>
Remove cache and session data imported from source server. This is more important than you may think. Many apparent problems can be resolved by clearing the cache.
rm -rf /var/www/MYSTORE/var/cache/m* rm -rf /var/www/MYSTORE/var/session/*
Find the web server user. This is usually the user 'apache'. To do this:
grep User /etc/httpd/conf/httpd.conf
change the owner of all files and directories in your magento root directory. Example:
chown -R apache /var/www/magento
These are recommended permissions as per Magento documentation. The idea is to give minimal required permissions.
400 permissions for files (-r--------) prevent any user (even the web server user) from overwriting files. This prevents attacks that depend on overwriting existing files with malicious content.
500 permissions for directories (dr-x------) gives the web server user read and execute privileges to prevent the accidental deletion or modification of files in the directory. Other users have no access to Magento directories.
700 permissions (drwx------) for the media/ and var/ directories give full control (that is, read/write/execute) to the owner and no permissions to anyone else.
600 permissions (-rw-------) for files in the media/ and var/ directories enable the web server user to write to them and to overwrite them.
To adjust persmissions
find . -type f -exec chmod 400 {} \; find . -type d -exec chmod 500 {} \; find var/ -type f -exec chmod 600 {} \; find media/ -type f -exec chmod 600 {} \; find var/ -type d -exec chmod 700 {} \; find media/ -type d -exec chmod 700 {} \; chmod 700 includes chmod 600 includes/config.php
Two additional places where program dynamically creates and deletes files
chmod 660 var/locks chmod 777 var/locks - verify? chmod 660 /var/log
Note that other custom modules may require different permissions.
goto your site and test...
http://MYSITE.example.com/
Are you doing tests behind a proxy server?
to set up for your current session
export http_proxy="999.999.999.999:3128" export https_proxy="999.999.999.999:3128"replace above values with your proxy server IP and port number
to set up permanently, for all users, edit /etc/profile and add
export http_proxy="http://999.999.999.999:3128" export https_proxy="https://999.999.999.999:3128"replace above values with your proxy server IP and port number
Specify a default value for the media type charset parameter. The most common type is utf-8.
In file httpd.conf add, or change if it's already there
AddDefaultCharset utf-8
or this line to your .htaccess
IndexOptions +Charset=UTF-8
If your site has some special log files make sure that your application has write permissions
set directory to rwx------
chmod 700 /var/www/mysite/myAPI/log
set files to rw-------
chmod 600 /var/www/mysite/myAPI/log/*
You may also want to clean out your custom logs
echo "" > /var/www/mysite/myAPI/log/api-access.log echo "" > /var/www/mysite/myAPI/log/api-error.log
You may want to identify this site differently, if so you may want to change some store parameters:
Change store name
Configuration -> General -> Store Name
Change store address
Configuration -> Store Email Addresses
Change Sales emails
Configuration -> Sales Email
If you use credit card interface