Dev - consultant - artisan

Qualité, amélioration continue, agilité, professionnalisme.

Un besoin ? Un projet ? Écrivez moi !

symfony, composer, clear:cache issue with vagrant and virtualbox

Quick tip today,

I have just finished to setup a new development environment with vagrant for my Symfony project, I have struggled with the clear:cache command, every time this command is failing.

Virtualbox seems to be the one to blame, below some relevant links:

The solution I have chosen is to change the directories of logs and cache:

    public function getCacheDir()
    {
        if (in_array($this->environment, ['dev', 'test'])) {
            return '/tmp/cache/' .  $this->environment;
        }

        return parent::getCacheDir();
    }

    public function getLogDir()
    {
        if (in_array($this->environment, ['dev', 'test'])) {
            return '/var/log/symfony/logs';
        }

        return parent::getLogDir();
    }

And all is fine with Symfony and vagrant after that, composer run, do is clear:cache, and nothing is broken anymore !

 

Vagrant debian Stretch 9.4 for Symfony dev

I choose to have a parent directory for my vagrant projects, -p or –parents tells mkdir to create all the needed parent folders.

mkdir -p vagrant/myproject
cd vagrant/myproject

vagrant init

vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

Edit Vagrantfile:

In the Vagrantfile you have this by default:

config.vm.box = "base"

edit to use the box you choose, I choose this one https://app.vagrantup.com/debian/boxes/stretch64:

info: mainpage of debian boxes https://app.vagrantup.com/debian

config.vm.box = "debian/stretch64"

vagrant up

vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'debian/stretch64' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'debian/stretch64'
    default: URL: https://vagrantcloud.com/debian/stretch64
==> default: Adding box 'debian/stretch64' (v9.4.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/debian/boxes/stretch64/versions/9.4.0/providers/virtualbox.box
==> default: Successfully added box 'debian/stretch64' (v9.4.0) for 'virtualbox'!
==> default: Importing base box 'debian/stretch64'...                                                                                
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'debian/stretch64' is up to date...                                                                     
==> default: Setting the name of the VM: myproject_default_1523353141366_70143                                                       
==> default: Clearing any previously set network interfaces...                                                                       
==> default: Preparing network interfaces based on configuration...                                                                  
    default: Adapter 1: nat                                                                                                          
==> default: Forwarding ports...                                                                                                     
    default: 22 (guest) => 2222 (host) (adapter 1)                                                                                   
==> default: Running 'pre-boot' VM customizations...                                                                                 
==> default: Booting VM...                                                                                                           
==> default: Waiting for machine to boot. This may take a few minutes...                                                             
    default: SSH address: 127.0.0.1:2222                                                                                             
    default: SSH username: vagrant                                                                                                   
    default: SSH auth method: private key                                                                                            
    default:                                                                                                                         
    default: Vagrant insecure key detected. Vagrant will automatically replace                                                       
    default: this with a newly generated keypair for better security.                                                                
    default:                                                                                                                         
    default: Inserting generated public key within guest...                                                                          
    default: Removing insecure key from the guest if it's present...                                                                 
    default: Key inserted! Disconnecting and reconnecting using new SSH key...                                                       
==> default: Machine booted and ready!                                                                                               
==> default: Checking for guest additions in VM...                                                                                   
    default: No guest additions were detected on the base box for this VM! Guest                                                     
    default: additions are required for forwarded ports, shared folders, host only                                                   
    default: networking, and more. If SSH fails on this machine, please install                                                      
    default: the guest additions and repackage the box to continue.                                                                  
    default:                                                                                                                                                                                                                                                                   
    default: This is not an error message; everything may continue to work properly,                                                                                                                                                                                           
    default: in which case you may ignore this message.                                                                                                                                                                                                                        
==> default: Installing rsync to the VM...                                                                                                                                                                                                                                     
==> default: Rsyncing folder: /var/www/myfolder/vagrant/myproject/ => /vagrant

==> default: Machine 'default' has a post `vagrant up` message. This is a message
==> default: from the creator of the Vagrantfile, and not from Vagrant itself:
==> default: 
==> default: Vanilla Debian box. See https://app.vagrantup.com/debian for help and bug reports
  • « vagrant ssh » to log in your new virtual machine
  • « exit » to logout
  • « vagrant destroy » to stop the virtual machine

 

install php 7.1 on debian 9.4

Hi !

Here the solution that has work for me, I found others tutorials but I had to execute a few more step to complete the setup as I want.

First, the repository, thanks to https://deb.sury.org/, the readme file is here https://packages.sury.org/php/README.txt

Based on that:

wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

apt-get update

As a precision, the link for the lsb_release command man page, it is useful to get the name of your current distribution, try it on a terminal:

lsb_release -sc

In my case, I only want one PHP version, I don’t want to keep the 7.0, I just want have the 7.1 as default, to do that you need to install the new, remove the old without forgetting the apache module.

apt-get install php7.1
apt-get remove php7.0

apt-get remove libapache2-mod-php7.0

The php7.1 module is already installed as dependency of php7.1.

And if you need it you can do

dpkg-reconfigure libapache2-mod-php7.1

Now you have php7.1 running 😉

You may want to clean more for production, but I do not cover this here, I do this on my dev env