Symfony configuration for Apache

Edit /etc/hosts

127.0.0.1       symfony.io

Add VirtualHost in /etc/apache2/sites-available/symfony.conf


    ServerName symfony.io
    #ServerAlias www.domain.tld

    DocumentRoot /var/www/html/learningSymfony
    
        AllowOverride All
        Order Allow,Deny
        Allow from All

        
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ web/app_dev.php [QSA,L]
        
    

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeeScript assets
    
        Options FollowSymlinks
    

    ErrorLog /var/log/apache2/learningSymfony.log
    CustomLog /var/log/apache2/learningSymfony.log combined

Create symlink to file configuration

ln -s /etc/apache2/sites-available/symfony.conf /etc/apache2/sites-enable/symfony.conf

Enable mod_rewrite in Apache:

sudo a2enmod rewrite

Restart apache:

sudo service apache2 restart

Go!

First steps mocking with PHPUnit

Our class:

class CanviPool
{
    public function retValue($val)
    {
        return $val;
    }
}

Our mocking class:

class CanviPoolTest extends TestBase
{
public function test_UT_ReturnValue()
{
// A mock object is created using CanviPool class
// The method 'retValue' will be mocked
$conConfig = $this->getMock('CanviPool', array('retValue'));

// We expect to use 'retValue' method ANY times in this test
// The mocked method is 'retValue'
// The mocked method will return the value 3
$conConfig
->expects($this->any())
->method('retValue')
->will($this->returnValue(3));

// We call the mocked method passing the required parameter
$res = $conConfig->retValue(1);
// Wen we compare the result with the value 3, the assert is true
$this->assertEquals(3, $res);

// We can do a new test
$res = $conConfig->retValue(1);
// And the result will be 3 again, because of the parameter ANY "->expects($this->any())"
// if insted of "any" the word was "once" this test would fail
$this->assertEquals(3, $res);
}
}

	

First steps with docker

Create a directory to play with.
Create a file called Dockerfile.
Edit this file and write:

FROM ubuntu
RUN touch test.txt && \
    apt-get update && \
    apt-get -y install nano

type the following command to build the container:

docker build -t ubuntu_example .

If you type the following command, you will see the container created:

docker images

Run the container:

docker run -i -t ubuntu_example /bin/bash

Run the container and leave it in foreground:

docker run -d -i -t ubuntu_example /bin/bash

Stop all containers

docker stop $(docker ps -a -q)

Remove all containers

docker rm $(docker ps -a -q)

Remove all images

docker rmi $(docker images -q)

Change name of an image

docker tag image_tag myname/server:latest

Docker login

docker login

Push image to Docker Hub

docker push 

Remove a single container and id

docker ps
docker stop
docker rm 
docker rmi 

Creation of a most “complex” docker container:

FROM ubuntu:trusty

RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get -yq install \
        curl \
        apache2 \
        libapache2-mod-php5 \
        php5-mysql \
        php5-mcrypt \
        php5-gd \
        php5-curl \
        php-pear \
        php-apc

EXPOSE 80
WORKDIR /var/www/html

RUN apt-get update && apt-get -yq install nano

ADD . /var/www/html

Binding an external port (local) to an internal port (docker)

docker run -d -p 9999:80 ubuntu_juanma /usr/sbin/apache2ctl -D FOREGROUND

We obtain the container_name or uuid

docker ps

Accessing inside a docker container to the terminal, where 83a0172358da is the

docker exec -it 83a0172358da /bin/bash

How to create a desktop icon in Linux

Yesterday I had to download a java software called PhpStorm which is used to develop PHP scripts. If you do it right you will make a symbolic link of the executable file in /usr/share/applications, but if you want a desktop icon of this software you have to creta e file with the following text:

[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=phpstorm
Exec=/bin/phpstorm
Terminal=false
StartupNotify=true

How to start a project using composer

First of all it is obvious that is necessary to hace composer.phar downloaded in our system.

For example, in order to install the laravel framework it is possible to do by two ways:

1. Using the following command:

php composer.phar create-project laravel/laravel laravel

2. Building the composer.json file with the following content:

{
	"name": "laravel project",
	"description": "test de instalacion de laravel por composer",
	"require": {
		"laravel/laravel": "5.1",
		"phpunit/phpunit": "4.1"
	},
        "config": {
                "disable-tls": true
        }
}

and executing the command:

php composer.phar install