Solucionar “Configuration of pmadb… not OK” en phpMyAdmin

Puede que te aparezca este error en pmpMyAdmin:

phpmyadmin-pmadb

Para solucionarlo hay que importar/crear la base de daots phpmyadmin y sus tablas. Un script SQL llamado create_tables.sql debería existir en la carpeta scripts o examples de tu instalación de phpMyAdmin. Ejecútalo y crea un usuario llamado pma y dale permisos para la base de datos phpmyadmin:

CREATE USER 'pma'@'localhost' IDENTIFIED BY 'pmapass';
GRANT ALL PRIVILEGES ON `phpmyadmin`.* TO 'pma'@'localhost' WITH GRANT OPTION;

Ahora hay que editar el fichero config.inc.php y configurar/descomentar estas líneas:

/*
 * phpMyAdmin configuration storage settings.
 */

/* User used to manipulate with storage */
$cfg['Servers'][$i]['controlhost'] = 'localhost';
// $cfg['Servers'][$i]['controlport'] = '';
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = 'pmapass';

/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';

Ref: http://stackoverflow.com/questions/21033059/pma-database-not-ok-in-phpmyadmin-upgrade
https://wiki.phpmyadmin.net/pma/Configuration_storage

Fix “Configuration of pmadb… not OK” in phpMyAdmin

You may get this message in pmpMyAdmin:

phpmyadmin-pmadb

To fix this you have to import/create the phpmyadmin database with it’s tables. An SQL script called create_tables.sql should be in the scripts or examples folder of your phpMyAdmin installation. Run it and then create a user called pma and give it permissions to the phpmyadmin database:

CREATE USER 'pma'@'localhost' IDENTIFIED BY 'pmapass';
GRANT ALL PRIVILEGES ON `phpmyadmin`.* TO 'pma'@'localhost' WITH GRANT OPTION;

Now edit config.inc.php and configure/uncomment those lines:

/*
 * phpMyAdmin configuration storage settings.
 */

/* User used to manipulate with storage */
$cfg['Servers'][$i]['controlhost'] = 'localhost';
// $cfg['Servers'][$i]['controlport'] = '';
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = 'pmapass';

/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';

Ref: http://stackoverflow.com/questions/21033059/pma-database-not-ok-in-phpmyadmin-upgrade
https://wiki.phpmyadmin.net/pma/Configuration_storage

Enlazar eventos a elementos HTML añadidos de forma dinámica con jQuery

Si tienes definido en JavaScript un evento de esta forma:

$("a[product-id]").click(edit_product);

function edit_product(event) {
    ...
}

Al añadir elementos (nodos) de forma dinámica (después de una llamada AJAX por ejemplo) que cumplen el selectori al HTML DOM usando .append() o .html(), el evento no funcionará con ellos. Esto se debe a que el elemento se ha añadido DESPUÉS de la llamada que enlaza el evento con la función que se quiere ejecutar.

Para asegurarse de que todos los elementos que cumplen el selectori van a lanzar el evento hay que usar .on() por ejemplo con el antecesor $(document):

$(document).on('click', "a[product-id]", edit_product);

jquery-logo

Ref: http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements

Attach event to dinamically added HTML elements with jQuery

If you have an event handler defined like this in JavaScript:

$("a[product-id]").click(edit_product);

function edit_product(event) {
    ...
}

After adding elements (nodes) dinamically (after an AJAX call for example) that fit that selector to the HTML DOM with .append() or .html(), the event won’t work on them. That’s because the element was added AFTER calling the event method that links to the function we want to execute.

To ensure all elements that fit the selector will trigger the event you have to use .on() for example with $(document) as the ancestor:

$(document).on('click', "a[product-id]", edit_product);

jquery-logo

Ref: http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements

Manual install and configuration of blackfire.io for Mac Ports in Mac OS X

blackfire.io is an awesome profiler for PHP done by SensioLabs, the company behind Symfony2. It automatically instruments your code to gather data about consumed server resources like memory, CPU time, and I/O. It’s very useful to find bottlenecks in your code.

blackfire.io is made of five main components:

  • The Agent is a server-side daemon that aggregates and forwards profiles to blackfire.io
  • The Probe is a PHP extension that gathers the raw performance profiles
  • The Client is a CLI tool used to trigger profiling
  • The Companion is a web browser extension used to trigger profiling
  • The Website is used to visualize the profiles

blackfire

To use it in Mac OS X with Mac Ports you have to do a manual installation. Here is the different components installation process.

Agent

Download and install it’s files:

curl -O http://packages.blackfire.io/binaries/blackfire-agent/0.20.0/blackfire-agent-darwin_amd64.tar.gz
tar xzvf blackfire-agent-darwin_amd64.tar.gz
sudo chown -R root:admin etc usr
sudo mv etc/blackfire /opt/local/etc/
sudo mv usr/share/man/man1/blackfire-agent.1.gz /opt/local/share/man/man1/
sudo mv usr/bin/blackfire* /opt/local/bin/
sudo mkdir -p /opt/local/var/log/blackfire
sudo ln -s /opt/local/etc/blackfire /usr/local/etc/blackfire

Create an agent configuration file in /opt/local/etc/blackfire/agent changing the log/socket files to the paths inside Mac Ports installation (/opt/local) and with your server id and token from https://blackfire.io/account/credentials#server:

[blackfire]
ca-cert=
collector=https://blackfire.io
log-file=/opt/local/var/log/blackfire/agent.log
log-level=1
server-id=d8108598-7a7a-4c5e-8f03-d0bccadc0931
server-token=91bde3fa9350479ba84f90acab46b680142c0f6fe8154a649e82d0d2ddadfa93
socket=unix:///opt/local/var/run/blackfire-agent.sock
spec=

Now you can run it with this command:

sudo blackfire-agent

But it’s better to register a service using launchctl. Create a file called /Library/LaunchDaemons/com.sensiolabs.blackfire-agent.plist with this content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Disabled</key>
        <false/>
        <key>KeepAlive</key>
        <true/>
        <key>Label</key>
        <string>com.sensiolabs.blackfire-agent</string>
        <key>ProgramArguments</key>
        <array>
            <string>/opt/local/bin/blackfire-agent</string>
        </array>
        <key>RunAtLoad</key>
        <false/>
    </dict>
</plist>

Make sure this file is owned by root:

sudo chown root:wheel /Library/LaunchDaemons/com.sensiolabs.blackfire-agent.plist

Load the service configuration file:

sudo launchctl load /Library/LaunchDaemons/com.sensiolabs.blackfire-agent.plist

And from now on you’ll be able to start and stop it as any other service:

sudo launchctl start com.sensiolabs.blackfire-agent
sudo launchctl stop com.sensiolabs.blackfire-agent

You can check if it’s really running using :

sudo ps x | grep blackfire

Probe

This is the extension used in the HTTP server. You need a different binary file depending on your PHP version. This script will download and configure it for you, you only need to change the server id and token:

PHP_VER=`php -v | head -n 1 | awk -F ' ' '{print $2}' | tr -d . | cut -c1-2`
EXT_DIR=`php -i | grep 'extension_dir' | awk -F ' => ' '{print $2}'`
sudo curl -o ${EXT_DIR}/blackfire.so http://packages.blackfire.io/binaries/blackfire-php/0.20.0/blackfire-php-darwin_amd64-php-${PHP_VER}.so
sudo chmod 755 ${EXT_DIR}/blackfire.so
PHP_INI=`php --ini | grep "Loaded Configuration File" | awk -F ' ' '{print $4}'`
echo "

[blackfire]
extension=\"${EXT_DIR}/blackfire.so\"
blackfire.agent_timeout=0.25
blackfire.agent_socket=unix:///opt/local/var/run/blackfire-agent.sock
blackfire.log_file=/opt/local/var/log/blackfire/agent.log
blackfire.server_id=d8108598-7a7a-4c5e-8f03-d0bccadc0931
blackfire.server_token=91bde3fa9350479ba84f90acab46b680142c0f6fe8154a649e82d0d2ddadfa93" | sudo tee -a $PHP_INI

Restart your HTTP server (Apache in my case) and also test with this command if the extension is correctly loaded by PHP:

php -m | grep blackfire

Client

The client binary file is installed with the Agent in /opt/local/bin/blackfire but you can also download and install it separately:

curl -O http://packages.blackfire.io/binaries/blackfire-agent/0.20.0/blackfire-cli-darwin_amd64.tar.gz
tar xzvf blackfire-cli-darwin_amd64.tar.gz
rm cli.sha1
sudo chown root:wheel cli
sudo mv cli /opt/local/bin/blackfire

Now configure the client file with the credentials from https://blackfire.io/account/credentials#client:

blackfire config

This will create a file in your home folder called ~/.blackfire.ini. You’ll have to update it’s socket value so it’s the same as the one used in the Agent configuration file:

[blackfire]
agent-socket=unix:///opt/local/var/run/blackfire-agent.sock
ca-cert=
client-id=543425c4-cb4f-3aff-c543-34d5aeeff4fd
client-token=ec843b4356997915cabb0a1b7be129e73d7c22a587103e523ea8b9a1e541b2d4
endpoint=https://blackfire.io
timeout=15s

Companion

The companion is only available for Google Chrome at the moment from here: https://chrome.google.com/webstore/detail/blackfire-companion/miefikpgahefdbcgoiicnmpbeeomffld. Install it and you’ll see a new icon in your browser that displays the different profiler slots.

Once everything is installed, configured and running just go to the URL in your server you want to profile and click “Profile!” in the Companion.

blackfire-companion

Ref: https://blackfire.io/getting-started