Wednesday, May 27, 2015

Setting up the default Database to be UTF8

Setting up the default Database to be UTF8

One mistake even seasoned developers make when starting a Symfony project is forgetting to set up default charset and collation on their database, ending up with latin type collations, which are default for most databases. They might even remember to do it the very first time, but forget that it's all gone after running a relatively common command during development:

Setting UTF8 defaults for MySQL is as simple as adding a few lines to your configuration file (typically my.cnf):

# vim /etc/my.cnf

[mysqld]
# Version 5.5.3 introduced "utf8mb4", which is recommended
collation-server     = utf8mb4_general_ci # Replaces utf8_general_ci
character-set-server = utf8mb4            # Replaces utf8

We recommend against MySQL's utf8 character set, since it does not support 4-byte unicode characters, and strings containing them will be truncated. This is fixed by the newer utf8mb4 character set.

# systemctl restart mariadb

SHOW VARIABLES LIKE 'char%';
SHOW VARIABLES LIKE 'collation%';

Symfony / Doctrine:

# vim src/Mycomp/DemoBundle/Resources/config/doctrine/Product.orm.yml

options:
    collate: utf8mb4_general_ci

# vim app/config/config.yml

doctrine:
    dbal:
        charset:  utf8mb4

Reference:

https://florian.ec/articles/mysql-doctrine-utf8/
http://symfony.com/doc/current/book/doctrine.html#book-doctrine-field-types

How to VLOOKUP with Multiple Criteria Using INDEX and MATCH

=INDEX(C4:H1159,MATCH(1,(C4:C1159=A2)*(D4:D1159=B2),0),6)

Basically your match is saying look for "true" if these two conditions are both "true".

When you enter the formula, don’t just press ENTER. Press CTRL+SHIFT+ENTER to tell Excel that it is an array formula. You can tell you’ve done it right because the entered formula will be surrounded in curly braces {}.

Reference:

http://superuser.com/questions/728000/index-match-based-on-2-criteria
http://thinketg.com/say-goodbye-to-vlookup-and-hello-to-index-match/
http://www.exceltactics.com/vlookup-multiple-criteria-using-index-match/4/#Using-INDEX-and-MATCH-with-Two-Criteria

Monday, May 25, 2015

Add embedded image in email through PHPMailer

Add embedded image in email through PHPMailer

<?php
  $mailer = new PHPMailer();

  $mailer->IsSMTP(); // telling the class to use SMTP
  $mailer->Host = 'localhost'; // SMTP server
  #$mailer->SMTPDebug = 2; // enables SMTP debug information (for testing)
                          // 1 = errors and messages
                          // 2 = messages only
  $mailer->Subject = 'My subject';
  $mailer->AddAddress($email, '');

  $mailer->SetFrom('do-not-reply@mydomain.com', 'My Name');

  $html = '<img src="cid:logo">';

  $mailer->MsgHTML($html . "\n");

  $mailer->AddEmbeddedImage('/tmp/logo.png', 'logo', 'logo.png');
  $mailer->AddAttachment($attach);

  if(!$mailer->Send()) {
    echo "[ERR] Mailer Error: " . $mailer->ErrorInfo . "\n";
  }
?>

Tuesday, May 12, 2015

Set up Symfony

Using mod_proxy_fcgi with Apache 2.4

If you are running Apache 2.4, you can easily use mod_proxy_fcgi to pass incoming requests to PHP-FPM. Configure PHP-FPM to listen on a TCP socket, enable mod_proxy and mod_proxy_fcgi in your Apache configuration and use the SetHandler directive to pass requests for PHP files to PHP FPM:

Note: mod_proxy_fcgi now supports network sockets since 2.4.9 ( Unix socket support for mod_proxy_fcgi ). https://wiki.apache.org/httpd/PHP-FPM

# vim /etc/httpd/conf.d/httpd-vhosts.conf

<VirtualHost *:80>
    ServerName domain.tld
    ServerAlias www.domain.tld

    # Uncomment the following line to force Apache to pass the Authorization
    # header to PHP: required for "basic_auth" under PHP-FPM and FastCGI
    #
    # SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

    # For Apache 2.4.9 or higher
    # Using SetHandler avoids issues with using ProxyPassMatch in combination
    # with mod_rewrite or mod_autoindex
    <FilesMatch \.php$>
        SetHandler proxy:fcgi://127.0.0.1:9000
    </FilesMatch>

    # If you use Apache version below 2.4.9 you must consider update or use this instead
    # ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/project/web/$1

    # If you run your Symfony application on a subpath of your document root, the
    # regular expression must be changed accordingly:
    # ProxyPassMatch ^/path-to-app/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/project/web/$1

    DocumentRoot /var/www/project/web
    <Directory /var/www/project/web>
        # enable the .htaccess rewrites
        AllowOverride All
        Require all granted
    </Directory>

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    ErrorLog /var/log/apache2/project_error.log
    CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>

Reference:

https://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html

Run Symfony IP address 192.168.x.x

# php app/console server:run 0.0.0.0:8000

Wednesday, May 6, 2015

To create a sitemap in Magento for Google Webmaster Tools

System > Configuration > Google Sitemap > Enabled > Yes

System > Configuration > Advanced > Mage_Sitemap > Enable

Catalog > Google Sitemap > Add Sitemap