Friday, August 28, 2015

New GIT Repository -> BitBucket -> Windows

No comments:
Just added my WordPress code to a Bitbucket Git repository. As always when I want to init a new project, I first head over to gitignore.io to quickly get a decent .gitignore file. If you use the service, and your starting from Linux, the tutorial video is worth watching before you start.

After setting up the .gitignore file, in Linux, the following will create your repository...

sudo git init
sudo git add .
sudo git commit -m 'initial commit'

After that, create a new empty repository in Bitbucket, select the "I have an existing project" link, and follow the instructions to your new repository on Linux added to the empty repository on Bitbucket.

Sidenote: when I switched from Mercurial to Git (Mercurial was fine for me... just wanted to get my feet wet with Git), my idea was to use GitHub. However, being in a startup, with a small team, I decided to keep some Euros in my bank account and use Bitbucket, which is free for up to 5 users. I used Bitbucket with Mercurial, so I was already familiar with it, and I'm very happy to stay there.

Next, since I develop on Windows (10), I needed to get the code locally. To do that, I use SourceTree, which makes cloning the repository on Windows a no-brainer.

Friday, August 21, 2015

Quickly Toggle MySQL Logging

No comments:
MySQL logging is a lifesaver when trying to understand applications at a low level. However, since I use it infrequently, I always have to consult the Google doc I have with the details on how to toggle the setting, and where to find the output.

For Windows, I've switched to a BAT file to speed up the process (which I call from SlickRun).

BEFORE using the script, you will want to have the following in your MySQL config file (in Laragon, use the right button menu -> mysql -> my.ini) in the [mysqld] section.

log-output=FILE
general_log_file = "C:/whatever/mylog.txt"
general_log      = OFF

@echo off
set /p state="Set MySQL Logging state ON or OFF: "
c:\xampp\mysql\bin\mysql -u "root" -e "SET GLOBAL general_log = '%state%';
%SystemRoot%\explorer.exe "C:\whatever"

A better alternative is to output to a table. In your MySQL config file (in Laragon, use the right button menu -> mysql -> my.ini) in the [mysqld] section, add

log-output=TABLE (see docs (MySQL 5.7))
general_log      = OFF

Then your script would be

@echo off
set /p state="Set MySQL Logging state ON or OFF: "
c:\xampp\mysql\bin\mysql -u "root" -e "SET GLOBAL general_log = '%state%';

You will find the data in the mysql.general_log table. What I do to make is easier to grok is to create a table with queries that I want to ignore (e.g. the standard PrestaShop code at the beginning of a page load).

create table mysql.general_log_ignores
(
argument_to_ignore mediumblob null
);

and then select only the interesting queries with


select 
       event_time, 
       convert(argument using utf8)
from 
    general_log gl 
    left join general_log_ignores gli on gl.argument = gli.argument_to_ignore
where
    gli.argument_to_ignore is null
order by 
    gl.event_time;

Wednesday, August 12, 2015

AWS S3, PHP, XAMPP, and cURL error 60

No comments:
Due to problems with VirtualBox and Vagrant on Windows 10, I've temporarily moved back to XAMPP for local development. While restoring the backed up databases to my local MySQL, I hit a cURL error 60.

The correct response to this problem was to download a CA Bundle and tell PHP to use it in the php.ini file, e.g.

[curl]
curl.cainfo="C:\xampp\php\extras\ssl\cacert.pem"

However, even after downloading a pem file from http://curl.haxx.se/docs/caextract.html, setting the above, and restarting apache, I was still getting the same error. Since I'm using a phar file for the AWS SDK, debugging the problem was difficult.

A post by GeoffGordon finally solved this for me... downloading a zip file of the pem, and then using the extracted version, fixed this for me. Thanks, Geoff!

--------------------

When using WampServer, I had the same problem, with a different cause. The php.ini file indicated by a php file served from my local server was different than the php.ini file being used by PHPStorm for debugging. I extracted the php.ini used by PHPStorm by debugging a file with the following code.

<?php
ob_start();
phpinfo();
$phpinfo = ob_get_contents();