3 useful scripts when moving Wordpress sites, or when the domain changes:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.domain.com', 'http://www.new.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.domain.com', 'http://www.new.com');

UPDATE wp_posts SET guid = replace(guid, 'http://www.domain.com', 'http://www.new.com');

Wordpress

On a Magento site, I was getting a very non-descriptive "HTML Error" when trying to upload an image.  Some images worked, some did not.

When checking my logs, the error was:

ModSecurity: Input filter: Failed to create temporary file: /root/tmp

Heres the steps to fix:

  1. Find the right php.ini file.  
    php -i | grep php.ini
  2. Update the upload_tmp_dir and session_save_path entries to
    /tmp
  3. Find custom.conf in the modsec directory (under Apache dir.)
  4. Add
    SecUploadDir /tmp
  5. Add
    SecTmpDir /tmp
  6. Restart Apache

Programming

Spam protection

 

In wp-comments-post.php at the top:


<?php if(!empty($_SERVER['SCRIPT_FILENAME']) && 'wp-comments-post.php' == basename($_SERVER['SCRIPT_FILENAME']) && !isset($_SERVER['HTTP_REFERER'])) : 
header('HTTP/1.1 403 Forbidden');
header('Content-Type: text/plain');
exit;
?>

Add to .htaccess:

#Security
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*gregolsen.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) http://%{REMOTE_ADDR}/$ [R=301,L]

Wordpress

I came across this helpful way to debug SQL in Magento.  Go to
/lib/Varen/Db/Adapter/Pdo/Mysql.php
and change $_debug to be true.  Then you will get a file that shows all the SQL goings on:
/var/debug/sql.txt

Magento

From time to time I want to transfer a site from one host to another.  I am not saying this is the best way, but it works for me.  Some FTP/SCP clients allow you to drag and drop from window to window, but I haven't had success with that method.  Assuming I have SSH and SCP, heres what I do:

  1. tar the public_html dir.  ex:  go to the public_html dir and type tar -cvf website.tar ./
  2. ssh to the new host and go to the target path
  3. scp root@<host>:<path to file, incl. filename> ./  ex:  scp Denne email adresse bliver beskyttet mod spambots. Du skal have JavaScript aktiveret for at vise den. :/home/site/public_html/website.tar ./  (it will prompt for password)
  4. Untar.  ex:  tar -xvf website.tar
  5. Fix group and ownership.  Ex:  chown -R owner.group ./
  6. Next, you got to transfer databases. 
  7. For this, I simply export from one side, then import at the other.  Fix configs and connection strings if necessary.

For large databases:

  1. mysqldump databasename -u username -pPassword | gzip >databasename.sql.gz
  2. from new host, scp root@<host>:<path to file, incl. filename> ./  (will be prompted for password)
  3. gzip -d databasename.sql.gz
  4. login to mysql - mysql -u username -p
  5. use <databasename>;
  6. source <name of .sql file>;
  7. test.

 

Programming

Side 1 ud af 5

Search My Site