Access Mysql without password and recover root password

You don’t remember your mysql password, be quiet, this is how you can access your mysql server without password and query for a new root password.

Step 1 : Stop mysql service

/etc/init.d/mysql stop

Step 2: Start to MySQL server without password:

mysqld_safe --skip-grant-tables &

Step 3: Connect to mysql server using mysql client:

mysql -u root

Step 4: Setup new MySQL root user password

mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Step 5: Stop MySQL Server:

/etc/init.d/mysql stop

Step 6: Start MySQL server and test it

/etc/init.d/mysql start
mysql -u root -p
Access Mysql without password and recover root password

Symfony2 // [Symfony\Component\DependencyInjection\Exception\InvalidArgumentException] unable to parse file…

When reorganizing my bundles, I decided to load my services from my bundle dependency injection.
My bundle name is “UserBundle” and my vendor name “xxx”.

So, I created an extension file from my bundle called “xxxUserExtension.php” in “UserBundle/DependencyInjection/”

This was my content file:

<?php

namespace xxx\UserBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
 * This is the class that loads and manages your bundle configuration
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
 */
class xxxUserExtension extends Extension
{
    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('user.yml');
        $loader->load('forms.yml');        
        $loader->load('validation.xml');       
    }
}

And of course, I’ve got this error:

    [Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
    Unable to parse file "C:\wamp\www\xxx\src\Headoo\UserBundle\DependencyInjection/../Resources/config\user.yml".

Maybe you want to know the cause, right?

This error simply occured because I was loading an yml file with an xmlFileLoader. Also, i was loading an xml file, we never have to load two different file types with a single file type loader.

Look here:

        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('user.yml');
        $loader->load('forms.yml');
        $loader->load('validation.xml'); 

So to solve this error, you have to use only one extension for your services and choose the correct loader.
This is the correct file:

<?php

namespace xxx\UserBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
 * This is the class that loads and manages your bundle configuration
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
 */
class xxxUserExtension extends Extension
{
    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('user.yml');
        $loader->load('forms.yml');               
    }
}

Hope, this helped.

Symfony2 // [Symfony\Component\DependencyInjection\Exception\InvalidArgumentException] unable to parse file…

Symfony2 // How to organize your bundles

When creating a new project, you probably already asked yourself this question, how can I organize my bundles?

The answer is that there is no standard good practice, it all depends of the nature of your project.

For small projects in which you don’t need to reuse some codes, you can decide to put all your sources in a single “appBundle”.
By against, for bigger projects that are frequently evolving, it is a good practice to organize more properly your bundles.

Usually we proceed like this: one bundle per module and one controller per functionality.
So, you’ll have to clearly identify your modules and make them bundles like this:

- MySiteName
    - UserBundle
        - RegistrationController
        - ChangePasswordController
    - ContactBundle
        - ContactController
    - PaymentBundle
        - PaypalController
        - MoneyBookerController

One advantage of this method is that you could publicly share some bundles to the community in public platforms.

More informations on the official Symfony Doc: http://symfony.com/doc/current/quick_tour/the_architecture.html

Symfony2 // How to organize your bundles

Symfony2 // Differences between Roles and Acl

Let’s imagine you have a blog with two users (Ana and Edouard), and want to manage specific actions like:

  • authorize Edouard to add a new contributor to the blog
  • authorize Ana to create, edit and delete her own blog post
  • authorize Edouard to delete Ana’s blog post

What is a Role

A role is a set of permissions hard coded in your application, and you can hard code yourselves. in your application. When checking if Edouard is able to delete Ana’s blog, your application checks in your code the current role the user has..

ACLs

Access Control Lists are useful when you need to take an authorization decision based on a Role + a domain object. Explicitely, they allow to give specific permissions to a specific object for a specific user.

Ana is allowed to edit blog entries written by her only. To check this authorization, you need Ana’s Roles and the Post model she’s trying to edit.

So, Edouard is allowed to all blog entries because he has the ROLE_ADMIN. The decision here is only based on a Role.

 

See Symfony documentation on Security/Roles and Symfony’s documentation on ACLs.

Symfony2 // Differences between Roles and Acl

Install dropbox on linux server debian 7 (wheezy)

Installing dropbox in command line can be very paintful if you don’t know some tips.
I will give you a complete tutorial based on my personal experience.

First you have to check how many bits your CPU server can handle (x64 or x86), just type this:

    uname -m

 

Then choose the correct repository

    wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86"
    OR
    wget -O dropbox.tar.gz "http://www.dropbox.com/download/?plat=lnx.x86_64"

 

If you don’t have Python installed in your server, install it because Dropbox will need it

    apt-get install python

 

Ensure that you’re not going to clog your home directory and extract the content

    tar -tzf dropbox.tar.gz
    tar -xvzf dropbox.tar.gz

 

Now, you can run dropbox

    ~/.dropbox-dist/dropboxd

 

You should now see output like this

    This client is not linked to any account... Please visit https://www.dropbox.com/cli_link?host_id=7d44a557aa58f285f2da0x67334d02c1 to link this machine.

 

Dropbox will loop on this message, copy this link, target it in your browser and log in to your Dropbox account, you will see a confirmation that your machine has been linked to your dropbox account.
PS: MAKE SURE TO NOT STOP THIS LOOP ! Copy the link by right clicking, but don’t press ctrl+C, it will stop the loop and your account will not be logged.

 

Now, we will get a python file from the dropbox site in order to start dropbox server.

    mkdir -p ~/bin  
    wget -O ~/bin/dropbox.py "http://www.dropbox.com/download?dl=packages/dropbox.py"  
    chmod 755 ~/bin/dropbox.py  

 

Right ! Now we can have the list of available commands Dropbox has to offer

    python ~/bin/dropbox.py help

 

Alright ! Now start dropbox server

    python ~/bin/dropbox.py start

 

Check that server has been successfully started

    python ~/bin/dropbox.py status

 

Congratulations, your dropbox folder is now on this directory

    ~/Dropbox

 

CONGRATULATIONS, it can’t be much simpler :).

Install dropbox on linux server debian 7 (wheezy)