Letting WordPress users install themes, plugins without FTP credentials

Quick answer: Put this in the user’s wp-config.php file:
define(‘FS_METHOD’, ‘direct’);

If you are having trouble updating the core wordpress, remember that no matter what the permissions are, wordpress needs it to be owned by apache:apache.

Posted in Linux | Comments Off on Letting WordPress users install themes, plugins without FTP credentials

Redirecting MySQL

To redirect traffic from one db to another (as a temporary measure if you have multiple places in your app to change the login data) you might try this:

iptables -t nat -A PREROUTING -p tcp –dport 3306 -j DNAT –to :3306

I ran across this when a customer wanted to redirect traffic from the mysql instance on his server to the CloudDB that he was creating. He wanted to make sure that if he missed an update in the app, he stil got data. I definitely put the YMMV with this one!

Posted in Linux | Comments Off on Redirecting MySQL

Which script sent this email

Sometimes you have multiple php scripts that send email and want to find out which one sent a specific email. I followed the instructions here:

http://www.iezzi.ch/archives/217

Worked like a charm.

Posted in Linux | Leave a comment

Browser-Side Caching with Apache

Browser-side caching relies on HTTP headers to know whether or not the content it has in its local cache is still valid. If it is, then it uses the local copy, rather than downloading the file from the server again. Many sites like whysoslow.com will report that you’re missing this HTTP header on your static files, which is normal, since you aren’t explicitly setting that in the files, since they’re mostly images and the like. In order to improve browser-side caching of your static content you could add mod_expires to your Apache configuration. This would add the necessary HTTP headers to make browser-side caching of your static content possible.

Install mod_expires and add the following to the .htaccess:

# Deflate output configuration
#
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/javascript
#AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

ExpiresActive On
ExpiresDefault “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType image/gif “access plus 1 month”
ExpiresByType image/jpeg “access plus 1 month”
ExpiresByType text/css “access plus 1 month”

AddType image/x-icon .ico
ExpiresByType image/x-icon “access plus 1 year”
ExpiresByType image/ico “access plus 1 years”

Posted in Apache, Linux | Leave a comment

Magento Notes

Deleting magento cache:

You may safely delete the content of var/cache/* and var/session/* or use the “Refresh Cache” functionality within the Admin.

To determine magento version:
include ‘app/Mage.php’;
php > echo Mage::getVersion();
1.6.2.0
php >exit();

Posted in Uncategorized | Leave a comment

Subversion Stuff

To establish a subversion repository anew:

svnadmin create /var/svn/myrepos
svn mkdir -m “creating the trunk dir” file:///var/svn/myrepos/repo1
svn import -m “Adding first directory” /var/www/vhosts/mydomain.com/wordpress file:///var/svn/myrepos/repo1
**Note that if you don’t specify a directory to copy, subversion is happy to add the one you are in to the repo.
svnadmin verify /var/svn/myrepos/

Subversion is not so forthcoming with the meaning of errors. If there is corruption in one of the revisions, it will just output the error when you do a

svnadmin verify repos/
[…]
* Verified revision 907.
* Verified revision 908.
* Verified revision 909.
svnadmin: Corrupt representation ‘907 21815 45 30922 158d3e72732f45bf6f02919b22fc899a’
svnadmin: Malformed representation header

This means that Revision 909 is good but Revision 910 is corrupted. The next step is to dump all the repos from 911 through the end of the repo which is in this case revision 947.

$ svnadmin dump –incremental -r 911:947 master/ > repo_name.svn_dump
* Dumped revision 911.
* Dumped revision 912.
* Dumped revision 913.
[…]
* Dumped revision 947.

svnadmin create /path/to/newrepo
svnadmin load /path/to/newrepoy < repo_name.svn_dump svnadmin verify repos/ * Verified revision 0. * Verified revision 1. * Verified revision 2. [...] * Verified revision 945. * Verified revision 946. * Verified revision 947.

Posted in Linux | Leave a comment

Grepping (and egrepping) with Style

Grep is a powerful tool. It can do many things well. It can also be used in conjunction with other tools. If you are new to grep, it is a supercharged search tool. The basic format of the command is:

grep [options] PATTERN [FILE…]

Many options are available and described in the man page, so I won’t go into them here. I will just list some of my favorite grep commands. (who am I kidding? I just want a place to copy them from when I am not at my own computer)

#This command searches for a string and includes the preceding 5 lines and the 5 lines that follow it and shows the line numbers as well.

grep -n -B5 -A5 searchstring /tmp/filename

#This command uses grep to traverse the output from a find command.
find . -exec grep searchstring {} \; -print

#This command allows you to output a sorted list of connections from the month of Mar 2013
grep Mar/2013 /var/log/apache2/access.log |  awk ‘{ print $1 }’ | sort -n | uniq -c | sort -rn | head

#Finding warnings and errors in your log
egrep -w ‘warning|error|critical’ /var/log/messages

Posted in Linux | Leave a comment

zend_mm_heap corrupted messages in apache logs

zend_mm_heap corrupted
if php5.2. google for patch
if php5.3 increase apc memory size in apc.ini

Posted in Linux | Leave a comment

Access Control Lists

Add ACL for apache user:

First see what ACLs exist already:

root@server1 mysite.org]# getfacl /var/www/vhosts/mysite.org/uploads
getfacl: Removing leading ‘/’ from absolute path names
# file: var/www/vhosts/mysite.org/uploads
# owner: user1
# group: user1
user::rwx
group::rwx
mask::rwx
other::r-x
default:user::rwx
default:group::rwx
default:mask::rwx
default:other::r-x

If apache user isn’t listed, do this:

setfacl -R -m u:apache:rwx /var/www/vhosts/mysite.org
setfacl -R -m d:u:apache:rwx /var/www/vhosts/mysite.org

Once you have them working as you want, back them up for safe keeping:
getfacl -R –absolute-names /foo/bar > /home/user/faclbackup

Posted in Linux | Leave a comment

Tune MySQL

wget http://www.day32.com/MySQL/tuning-primer.sh

sh tuning-primer.sh

Posted in Linux | Leave a comment