Access MySQL Remotely in Ubuntu

Posted on 2010/09/04 by Randall.
Categories: Uncategorized.

Running an Ubuntu server on Amazon EC2. The server runs a standard LAMP setup, with MySQL. I’m building some deploy scripts that interact with the database. I want to be able to remotely access MySQL and this is what I did.

I edited the my.cnf file to exclude the bind-address line. At first I updated it to use my server’s IP address but MySQL would not restart. But when I commented out the line removing it from the configuration, this worked. Go figure…

The other thing that you’ll need to do is to fire up mysql and add in a couple of new users with a wildcard for the host. Run a command that looks like this:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

That should do it.

I found the tip originally over here.

CakePHP Console Cron Job Working on Godaddy Shared Hosting

Posted on 2010/08/29 by Randall.
Categories: Uncategorized.

Finally I think that I have seen my cron jobs working end-to-end on GoDaddy hosting.

See my previous post about how to get the command line basically working. It doesn’t work out of the box and you’ll need to adjust your shell script slightly, for everything to be working on the Godaddy shared hosting.

The final step was to setup my cron job through Godaddy’s control panel. This was a bit difficult, you cannot use a SSH command line to setup cron jobs with Godaddy. It’s tricky to run a cron job frequently, you can only run a cron twice in an hour, and you cannot have duplicate cron commands. Whatever…

Here’s my final command which invokes my custom CakePHP console as a cron:

cd $HOME/html/directory; ./cake/console/cake subscription_reminder;

No quotes surrounding the command at all. You must CD to where your app folder is located and then invoke the cake command with that ./cake/console/cake style.

If you get a “No such file or directory” error, your command is not working. Try to remove double quotes and follow the style I’ve set forth above.

Jungledisk on Ubuntu

Posted on by Randall.
Categories: Uncategorized.

The desktop edition of Jungledisk, Personal Desktop Edition Linux x64 3.1 beta to be specific, is working like a charm. It was a lot easier to install. I just did a sudo apt-get install fuse, which I’m not even sure was required, and then ran the junglediskdesktop executable. This prompted me for my account details and let me point the mount point to a folder in my home directory. This was all done on a Virtualbox Ubuntu v10 install running on top of Windows 7 x64. This is a vast improvement over my previous experience trying to get a slightly-older version of Jungledisk working on an Ubuntu v9 netbook remix install.

Update: so I moved over all of my shell scripts to the Jungledisk filesystem and tried running those scripts from my netbook running Ubuntu. The mount point settings needed to be adjusted in order to run my scripts. The fuse filesystem options included a “noexec” option and this prevented me from running executable files from the disk. I just took this out and it’s working great!

And It’s Running as PHP 4

Posted on by Randall.
Categories: Uncategorized.

Wtf. Even after the things I did to workaround my issues with Godaddy, the bloody thing still didn’t work. So I sat down with it for a good bit of time, called up Godaddy customer support, and their advice helped me out in the end.

Just change your cake/console/cake bash script to look like this:

exec /web/cgi-bin/php5 -q -d register_argc_argv=1 ${LIB}cake.php -working "${APP}" "$@"

This does two things that the out-of-the box script doesn’t do. It invokes php5 using a different path (the /web/cgi-bin/php5 part) and passes in a setting usually set in php.ini (the -d register_argc_argv=1 part).

Trouble with Godaddy

Posted on 2010/08/25 by Randall.
Categories: Uncategorized.

It took me a long time to figure this one out. I couldn’t run the CakePHP console…and the error message was not very helpful. I added in some echo statements to debug the problem. Eventually I found that the command line arguments were not getting passed in. I finally tracked this down to a PHP setting, from php.ini which is named register_argc_argv. This setting is “off” by default on Godaddy’s shared hosting. I think they will NOT allow me to set it to on, unfortunately.

What Remains

Posted on 2010/08/23 by Randall.
Categories: Uncategorized.

A 100% build/deploy script. This should probably be three scripts, one push-to-dev.sh, push-to-staging.sh, and push-to-live.sh. These should probably rebuild the database with appropriate data.

I also must put together scripts that install the appropriate data for each of these servers.

CakePHP Console on Godaddy

Posted on 2010/08/22 by Randall.
Categories: Uncategorized.

Working my way through some more kinks on the godaddy-hosted version of my site. I’m having to echo out some stuff in the cake/console/cake.php file to figure out just what is going wrong.

On the godaddy site, when I echo out print_r($this->args) at line 183 I find the array is empty. When I do this on my Ubuntu EC2 instance I get this:

Array
(
[0] => /var/www/www.directory.sdcweb.org/htdocs/cake/console/cake.php
)

It looks like godaddy’s command-line PHP isn’t passing through the bash shell command line arguments.

CakePHP mod_rewrite on Godaddy in a Subdirectory

Posted on 2010/08/07 by Randall.
Categories: Uncategorized.

Or on a sub-domain. Let’s say you have an existing website on your Godaddy hosting plan (example.com for example) and you want to add a sub-domain (temp.example.com). This is what I have done, and I think these instructions might apply for any additional domain you host on your account, but I have not tested that out yet.

First thing, my hosting is through Godaddy. They’re much maligned but one thing I will say in their defense, you can always get someone on the phone. I’m using the Grid Deluxe Linux hosting, I called them up and got confirmation that these servers run Apache 2.2. Legacy plans hosted though GoDaddy may or may not run this exact Apache version.

When you create the temp.example.com sub-domain it will create a folder in your ~/html folder, and the default name will be the same as the subdomain. In my case, the folder created was ~/html/temp.

My main site is a Joomla installation which is using mod_rewrite to do search engine friendly Urls.

The CakePHP site is inside of my ~/html/temp folder. The key to this setup was a fairly simple adjustment to the .htaccess files, using RewriteBase. Here are what my .htaccess files look like.

First, ~/html/temp/.htaccess


RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]

This is what ~/html/temp/app/.htaccess looks like


RewriteEngine on
RewriteBase /app/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]


Finally here is ~/html/temp/app/webroot/.htaccess


RewriteEngine On
RewriteBase /app/webroot/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

Hope this helps.

I’ve looked at a lot of different articles about these issues and did not find one that was 100% satisfactory. I’ll still point to them in case something there covers an aspect that I have not.

A really nice snippet

Posted on 2010/07/21 by Randall.
Categories: Uncategorized.

Some PHP code to handily get at the things in an array:

print_r(compact(explode(' ', 'count acw cols coldepth')));
?>

I suppose var_dump() and print_r() can do something like this but maybe not…

Model::find() Returning Extra Results

Posted on 2010/07/04 by Randall.
Categories: Uncategorized.

This one was tricky…if you pass in array('condition'=>array('id'=>1)), instead of array('conditions'=>array('id'=>1))…the engine will not complain, it will just return a whole lot of extra results from your Model::find() query. Remember to always use ‘conditions’.