How to fix: WordPress updates and plugin installs require FTP login but shouldn’t.
WordPress is generally very good about working under any server situation you put it in. It even has fall back code if the preferred server settings are not available.
The plugin and update installation code is one example of this. If WordPress doesn't have the rights to directly update files, it will ask you for FTP login information.
However, there are times when you KNOW the permissions are correct to allow Apache to update files and WordPress doesn't detect it and insists on FTP. This should be extremely rare. However if you ever do come across this circumstance you can force WordPress to override this behavior and use direct updates.
Just add these lines to wp-config.php:
define( 'FS_METHOD', 'direct' );
define( 'FS_CHMOD_DIR', 0777 );
define( 'FS_CHMOD_FILE', 0777 );
You can read more about these constants on the WordPress Codex.
How do you restart a spamd on a cPanel server?
Let's keep this one simple. There are two main ways to restart Spamd.
The first way restarts spamd (aka spam assasin) itself:
/scripts/restartsrv_spamd
The next way is to restart the default mail server exim, which uses spam assassin. That's done with:
/etc/rc.d/init.d/exim restart
How to: Split path and filename in MS Excel, Google Docs or OpenOffice Calc
I did a code review along with Brad Williams yesterday and today we combined our results. The problem was, our spreadsheet columns didn't match. He'd combined path and filename into one column and I'd split them out into two columns. We decided the split path and filename was useful. So I had to come up with a quick set of formula to create the two extra columns, splitting path from filename.
For a short time, I thought it wouldn't be possible, and that my formula foo had finally failed me. The difficulty is of course that the find() doesn't have an option for returning the position of anything but the first occurrence of the search text. So, you don't have anyway to know where to split the string. Ahhh, but lo and behold the substitute function can be used to replace the nth occurrence of a character or string. If you replace the right duplicated character with something unique, you can come use find() to determine the right place do do the split.
The method I used was based upon formulas found on Excel Ticker in an article written by Mourad Louha. It took me several reads through to grok the concept of his method. (Actually I came back to the article hours later to figure out how the formula worked - long after hacking the formulas to do what I wanted). So, I thought I would boil it down for you here. Also his formula was based upon an unusual layout in his spreadsheet. What I've listed here simply assume a 3 column spreadsheet (Folder, File, Full Path) with a row for the title. If your third column (c2) has the concatenated/full path, just paste the right formula into the first and second columns (a2 and b2) in the second row and you are done.
Here is Mourad's method boiled down into simple steps:
1. Determine how many slashes there are. Subtract the length of the string, with slashes removed, from the original length of the string.
2. Replace the LAST occurrence of the slash with unique text we can find (we substitute $$$ but anything unique could be used)
3. We now use find() to get the position of the unique text and use that as the location to split the string.
Open Office Calc/Google Spreadsheet Filename Split Formulas
Linux Formula for splitting the path off a filepath:
= LEFT($C2;FIND("$$$";SUBSTITUTE($C2;"/";"$$$";LEN($C2) - LEN(SUBSTITUTE($C2;"/";""))))-1)
Linux Formula for splitting a file name off a filepath:
=RIGHT($C2;LEN($C2)-FIND("$$$";SUBSTITUTE($C2;"/";"$$$";LEN($C2)-LEN(SUBSTITUTE($C2;"/";"")))))
Windows Formula for splitting the path off a filepath:
= LEFT($C2;FIND("$$$";SUBSTITUTE($C2;"\";"$$$";LEN($C2) - LEN(SUBSTITUTE($C2;"\";""))))-1)
Windows Formula for splitting a file name off a filepath:
=RIGHT($C2;LEN($C2)-FIND("$$$";SUBSTITUTE($C2;"\";"$$$";LEN($C2)-LEN(SUBSTITUTE($C2;"\";"")))))
Microsoft Excel Filename Split Formulas
Microsoft Exceluses commas instead of semicolons.
Linux Formula for splitting the path off a filepath:
= LEFT($C2,FIND("$$$",SUBSTITUTE($C2,"/","$$$",LEN($C2) - LEN(SUBSTITUTE($C2,"/",""))))-1)
Linux Formula for splitting a file name off a filepath:
=RIGHT($C2,LEN($C2)-FIND("$$$",SUBSTITUTE($C2,"/","$$$",LEN($C2)-LEN(SUBSTITUTE($C2,"/","")))))
Windows Formula for splitting the path off a filepath:
= LEFT($C2,FIND("$$$",SUBSTITUTE($C2,"\","$$$",LEN($C2) - LEN(SUBSTITUTE($C2,"\",""))))-1)
Windows Formula for splitting a file name off a filepath:
=RIGHT($C2,LEN($C2)-FIND("$$$",SUBSTITUTE($C2,"\","$$$",LEN($C2)-LEN(SUBSTITUTE($C2,"\","")))))
How to: Resolve the error “did you run git update-server-info on the server? “
This is a fairly common error and a bit of a head smacker...
Before you look any further, ask yourself one question..
Are you trying to use a git client to check out an SVN repository?
Try using svn client instead
How to: Install MemCached on CentOS / Redhat using yum
Installing memcached on a server for use with W3Total cache can seem daunting if you haven't done it before. Once you've done it enough to work out a method and know the speed bumps you can come across, you can
Use this command to determine the CentOS/RedHat version. You need this to know if you are working with version 4 5 or 6.
cat /etc/redhat-release
Use this command to determine if the OS is 64bit or 32bit (look for x64 if it is not there, 99% of the time you're on 32 bit)
uname -a
Retrieve the IUS Community repository installation files to allow an easy install of the memcache module from the IUS repo.
NOTE: These are examples for 64 bit Redhat 5. Browse the repo at http://dl.iuscommunity.org/pub/ius/stable/Redhat/ to make certain you have the right files for your server: (current as of 10/10/12)
mkdir ~/temp
cd ~/temp
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1.0-10.ius.el5.noarch.rpm
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/epel-release-5-4.noarch.rpm
NOTE: These ALTERNATE examples are for 32 bit Redhat 5. Browse the repo at http://dl.iuscommunity.org/pub/ius/stable/Redhat/ to make certain you have the right files for your server: (current as of 10/10/12)
mkdir ~/temp
cd ~/temp
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/ius-release-1.0-10.ius.el5.noarch.rpm
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/i386/epel-release-5-4.noarch.rpm
Install both of these files:
rpm -Uvh *-release-*.rpm
Perform the install:
yum -y install memcached
service memcached start
chkconfig memcached on
pecl install memcache
Note: If you get a "Can't compile c code" error, try making your tmp folder executible before running the pecl command:
mount -o,remount,rw,exec /var/tmp
Make sure you remount the tmp directory securely with noexec when you are done:
mount -o,remount,rw,noexec /var/tmp
Make sure this line has correctly been added to the php.ini file for your site:
extension="memcache.so"
Sometimes the php.ini file has been overridden for a specific directory. Look for that if phpinfo() tells you memcache is not active. This picture shows a site with the default php.ini overridden by a local copy. It required the extension line to be manually added to the overriding ini file.
How to: Refresh your WordPress page unless a comment is being typed
A customer wanted a piece of code that allowed a page to be refreshed once the client has remained on the page after a certain amount of time. They'd used a refresh command previously, but the problem was that this interrupted anyone who was in the middle of typing a comment.
This is my solution to refresh the page every 5 minutes:
<script language="JavaScript">
var sURL = unescape(window.location.pathname);
var intValue = 0;
function doLoad()
{
intValue=setTimeout( "refresh()", 300*1000 );
}
function refresh()
{
window.location.href = sURL;
}
function noRefresh(e)
{
switch (e.keyCode) {
case 40:
case 39:
case 38:
case 37:
case 34:
case 33:
break;
default:
clearTimeout(intValue);
}
}
if ($.browser.mozilla) {
$(document).keypress(noRefresh);
} else {
$(document).keydown(noRefresh);
}
$(document).ready(doLoad());
</script>
<noscript>
<meta http-equiv="refresh" content="300">
</noscript>
Fixing mysqldump: Got error: 1016: Can’t open file & mysqldump: Got error: 23
When doing exports of large databases using mysqldump, it is common to get errors that are along the lines of:
mysqldump: Got error: 1016: Can't open file: './databasename/tablename.frm' (errno: 24) when using LOCK TABLES
or maybe
mysqldump: Got error: 23: Out of resources when opening file './databasename/tablename.MYD' (Errcode: 24) when using LOCK TABLES
Both come from the same cause and don't worry - your database is not currupt..
The first action that mysqldump takes is to lock all of the tables so that the database cannot go out of sync from the beginning to the end of the export. Of course, that means that your users can't make changes while doing the dump. And that's just one more reason you need to be careful using mysqldump.
The solution to this problem is simple add --skip-lock-tables to your command line.
At that point the tables won't be locked, and the export will run much faster. There is a slight downside in that people can use the table as it is being exported and you could potentially get an update written as you are exporting that table. But it is unlikely that you'll hit any real world problems when doing this, especially with things like blog exports.
Notty Notty! re:”All my Server CPU is used by root@notty!! Have I been hacked?”
First - Breathe. "notty" stands for "no teletypewriter". Programs that connect to the server but don't want the output displayed any where use a "No TTY" connection. So if you see "ssh: *@notty" on a task list somewhere, it just means there's an ssh login on your server does not have a visual interface assigned to it.
This can appear during many different relatively common server activities. So it is not the tag of some hacker as you might have feared. One of the most common examples is the use of the scp command. scp remotely copies files from one computer to another. When it connects to the remote computer, it isn't displaying that communication to a screen, so the connection is a notty connection.
Below is a partial screen scrape of a "top -c" command when scp is running:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 32706 root 15 0 14284 7116 2336 S 68.1 0.3 6:15.37 sshd: root@notty 32709 root 18 0 6788 1468 1124 R 4.0 0.1 0:20.84 scp -r -f /home2
As you can see the cpu usage was pretty high and that's what gets people worried. They are probably looking at "top" see how much longer it will take to finish copying files. Then they see that scp is taking up nothing while a task named "notty" is taking up huge amounts of CPU and they think someone is being "naughty". Now you know what is really happening.
So relax! It's all good.
How to Add a TXT record to your 1and1 domain & How to use external DNS for a 1and1 hosted site.
Unfortunately there are lots of registrars that don't allow you full access to your DNS settings. 1and1.com is one of these. If you host your site with 1and1.com and you want to add a TXT record to your domain for verification purposes or to set a SPF record whatever, you simply can't do it... unless...
If you have access to another DNS server that allows you to edit your DNS zone and add TXT records, you can set your 1and1 domain to use that DNS server. However, THEN you must edit the DNS zone on that server and have all of the A records point back to the IP address for you 1and1 account.
Here are the steps:
- Ping your site and write down the IP address
- Go to the 1and1 admin domain listing
- Select the row for your domain (should be the only one checked) and the click DNS->Edit DNS.
- Select My DNS Servers
- Enter the URLS for your other DNS server (Something like ns1.example.com and ns2.example.com
- Close and save and allow a few hours for this to update before testing it.
- In the mean time, go to your other DNS server and setup a new DNS zone for your domain. It needs to have at LEAST an a record pointing to the IP address you wrote down for step one. You probably also want setup a cname for your www subdomain. You also can setup your TXT record.
- After hitting save wait for a few hours and you should be done.
If you are a visual learner, here is a screen cast.
Generating random names in MySQL
I've improved my earlier random string generation procedures to better suit my needs. So I created a Random Name Generator for MySQL.
I've created two new procedures. They pick from the 100 most popular first names (well actually the 50 most popular male and 50 most popular female first names for the US) and the 100 most popular surnames (for the US).
Using these two procedures generate_fname() and generate_lname() you can create realistic random names and email addresses for your tests.
You can download the SQL here.
