Jul
28
This issue is mostly well documented elsewhere on the internet, but I recently found an unusual cause of this problem which I felt was worth documenting.
The following list should hopefully help you to isolate this problem, but if I’ve missed anything please let me know via comments:
- Firstly check you have updated the DB_USER, DB_PASSWORD and possibly DB_HOST in your wp-config.php file.
- Next, check the database is actually up and running. If you get a response from ‘mysql -u root -h DB_HOST -p’ then the database is running. (Replace DB_HOST with its value).
- Once you have logged into mysql as root (or with sufficient privileges) ensure the database is configured with the correct access rights with the following query (replacing DB_NAME, DB_USER, DB_HOST and DB_PASSWORD):
GRANT ALL ON DB_NAME.* TO 'DB_USER'@'DB_HOST' IDENTIFIED BY 'DB_PASSWORD'; FLUSH PRIVILEGES; - If you are having an issue where every time you go through these steps to configure one blog, another one throws this error in a vicious circle ensure that you don’t have two or more blogs all relying on the same DB_USER but different DB_PASSWORDs (even if you are using different DB_NAMEs) as every time you update the privileges for one password, you are effectively changing the password for that DB_USER, so any wp-config.php using that username but a different password will be unable to access the database.
Hopefully this will help at least one person.
Jul
7
Use PHP to text you everytime you get a new email
Filed Under PHP
This tutorial explains how to connect to gmail with php, and have an SMS alert sent to your mobile phone using Twitter every time you receive a new email. I used PHP 5.2.3 on Ubuntu 7.10 with MySQL 5.0.45 , but other combinations may work.
Firstly you need to open two twitter accounts (there is probably a way to do it with just one, but I already had one open so I used that): The first account (say ‘account1′) should be your main account and you should follow the introductory instructions to register your mobile phone with the account (it’s free, as is receiving text messages). The second account (’account2′) should be set to private feeds (you don’t want everyone being able to read your email). Login to ‘account1′ and follow ‘account2′, then login to ‘account2′ and accept the request. Finally, text “ON account2″ to twitter from your registered mobile number. Twitter is now setup for the script to work.
Next ensure gmail is configured to allow IMAP connections to your account by logging in, and ensuring IMAP is enabled in Settings->Forwarding and POP3/IMAP.
Now we need a database to store email IDs in (so you don’t get alerted about the same email twice). Also we create a second table here to hold the most recently updated status - this is because Twitter won’t allow a status update that is the same as the last status, but you might receive two emails with the same subject (especially if you are having a gmail conversation) so if the status matches the previous status a hyphen is appended just to make it unique.
mysql -u root -p
CREATE DATABASE Email;
USE Email;
CREATE TABLE TwitterEmail(email VARCHAR(20), id VARCHAR(980), PRIMARY KEY (email, id));
CREATE TABLE TwitterSubject (email varchar(20) PRIMARY KEY NOT NULL, last_subject text, FOREIGN KEY(email) REFERENCES TwitterEmail(email));
GRANT ALL TO ‘db_user’@'localhost’ IDENTIFIED BY ‘db_password’;
EXIT;
Save Email2Twitter.php into /home/user/ and ensure it is executable by you but not readable by anyone else (as it has your passwords in it):
chmod 700 Email2Twitter.php
which php # note the output here as we need it for crontab in a second
crontab -e
In the nano window that comes up, add a new crontab entry to run the program as often as you’d like, making sure to specify the full path of both php and Email2Twitter.php. For example:
00 * * * * /usr/bin/php /home/username/Email2Twitter.php
The above example will cause the program to run once an hour providing that machine stays turned on.
Troubleshooting:
If the machine can’t find ‘php’, ensure that php5-cli is installed. Likewise, if you get an error message complaining about IMAP functions not being found ensure php5-imap is installed.
I had a program running this script on one machine where it had trouble connecting to imap.gmail.com yet I could still telnet to it (so the firewall wasn’t causing the problem). If anyone can suggest why this particular machine was causing an issue it would be very much appreciated.
All comments, suggestions and corrections welcome.
UPDATE: Due to a change in the service offered by Twitter, this no longer works unless you are in the United States, Canada or India. It’s quite obvious this was coming as their SMS deliveries have been unreliable to say the least over the past months.
When I have time I’ll look into another free way of doing this (it may not be possible), and soon I’m planning on writing about controlling a linux machine using a mobile phone via Twitter (which should still work).
May
19
Installing Wordpress on Ubuntu 7.10
Filed Under Ubuntu
The idea of this blog is to detail solutions to anything technical I’ve tried that hasn’t been straightforward. What better way to start than with instructions on installing wordpress:
Instructions for Ubuntu 7.10 using bash, but should be similar for any *nix install.
Assuming the following:
- LAMP server already installed,
- Installation is for a single blog,
- The blog should be in the root directory of the website, eg. domain.com,
- The root directory is located in /var/www/
Downloading and extracting the latest version:
sudo su
cd /tmp/
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mv wordpress/* /var/www/
cd /var/www/
Configuring the mysql database:
mysql -u root -p
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpress’@'localhost’ IDENTIFIED BY ’somepassword’;
FLUSH PRIVILEGES;
EXIT;
Moving the default config file:
mv wp-config-sample.php wp-config.php
nano wp-config
Change it to look like this:
define(’DB_NAME’, ‘wordpress’);
define(’DB_USER’, ‘wordpress’);
define(’DB_PASSWORD’, ’somePassword’);
define(’SECRET_KEY’, ‘make this unique!’);
Next go to yourhostname.com/wp-admin/install.php and follow the steps. Once you have logged in it should take you to a configuration portal and yourhostname.com should be your blog - have fun!
If you get a directory listing instead of a portal, you need to ensure apache is configured to recognise index.php as an index file. Ensure the /etc/apache2/httpd.conf (or the vhost configuration file if you are using one) looks something like this:
DirectoryIndex index.php index.html index.htm
If you had to change this file, you need to reload apache:
/etc/init.d/apache2 reload