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)

Debian // Could not reliably determine the server’s fully qualified domain name

When you try restarting your apache server and get this error:

    [....] Restarting web server: apache2apache2: apr_sockaddr_info_get() failed for "yourdomain"
    apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

 

You have this error because you didn’t specified the server name to which your web server will respond to.

To solve this, open “/etc/apache2/apache2.conf” file.

    nano /etc/apache2/apache2.conf

 

Add at the end of the file, add a server name

    ServerName "yourdomain.com"

 

Now restart your apache server:

    service apache2 restart

 

PS: If you’re not admin, use “sudo” command before any of these instructions.
That’s all :).

Debian // Could not reliably determine the server’s fully qualified domain name

Sf2 // Neither the property … nor one of the methods … exist and have public access in class …

Imagine you have two entities correctly written with a relation and you still have this error: “Neither the property … nor one of the methods … exist and have public access in class …”.

This error occured because you need to map your relations with an existing field, the solution is in your form type.

Check these entities:

SubCategory.php with a manyToOne relation on category.php

<?php

namespace Headoo\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * SubCategory
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class SubCategory
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var integer
     *
     * @ORM\ManyToOne(targetEntity="Category")
     * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
     */
    private $categoryId;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=30)
     */
    private $name;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set categoryId
     *
     * @param integer $categoryId
     * @return SubCategory
     */
    public function setCategoryId($categoryId)
    {
        $this->categoryId = $categoryId;

        return $this;
    }

    /**
     * Get categoryId
     *
     * @return integer 
     */
    public function getCategoryId()
    {
        return $this->categoryId;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return SubCategory
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }
}

And the other one, Category.php.

<?php

namespace Headoo\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Category
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class Category
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=30)
     */
    private $name;

    /**
     * @var boolean
     *
     * @ORM\Column(name="valid", type="boolean")
     */
    private $valid;

    
    /**
     * Transform to string
     * 
     * @return string
     */
    public function __toString()
    {
        return (string) $this->getId();
    }     

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return Category
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set valid
     *
     * @param boolean $valid
     * @return Category
     */
    public function setValid($valid)
    {
        $this->valid = $valid;

        return $this;
    }

    /**
     * Get valid
     *
     * @return boolean 
     */
    public function getValid()
    {
        return $this->valid;
    }
}

In your form type, you need to add this in the builder:

->add('categoryId', 'entity', array(
            'class'    => 'HeadooCoreBundle:Category',
            'property' => 'name'))

The “property” attribute is the property you have to link your relation with.
In this case, the “name” property exists in the category entity, so, no error will be triggered.
But, if you specify a property that doesn’t exist, you will have the beginning exception “Neither the property … nor one of the methods … exist and have public access in class …”.

Sf2 // Neither the property … nor one of the methods … exist and have public access in class …

Sf2 // Object of class… could not be converted to string on relation

I have two entities “category.php” and “subCategory.php” with a correct manyToOne relation on subCategory.php to category.php, like this.

    /**
     * @var integer
     *
     * @ORM\Column(name="categoryId", type="integer")
     * @ORM\ManyToOne(targetEntity="Category")
     * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
     */
    private $categoryId;

When saving a form I have the error “Object of class… could not be converted to string”.

This error occured because when specifying a relation (manyToOne, oneToMany, oneToOne, etc…), you have no need of specifying “@ORM\Column” again, because the property is already mapped by the relation.

The answer is:

    /**
     * @var integer
     *
     * @ORM\ManyToOne(targetEntity="Category")
     * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
     */
    private $categoryId;
Sf2 // Object of class… could not be converted to string on relation