Q:

Provision a vagrant box with PHP 7.0

I am trying to provision an ubuntu/trusty64 vagrant box with Apache 2.4 and PHP 7.0 but have not succeeded.
This is my provisions.sh script:
#!/usr/bin/env bash

# Vagrant instance provision script

# Php 7.0
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
sudo apt-get install php7.0 -y

# Apache 2.4
sudo add-apt-repository ppa:ondrej/apache2 -y
sudo apt-get update
sudo apt-get install apache2 -y
if ! [ -L /var/www ]; then
  rm -rf /var/www/html
  ln -fs /vagrant /var/www/html
fi

When I vagrant up, apache works fine but PHP does not. However, if I remove the PHP installation line,
sudo apt-get install php7.0 -y

and execute it from the command line after the VM is running, PHP works fine.
Any ideas why this is or how to fix the provisioning of the box so that PHP works from the start?

A:

The initial question already contains the answer. It is the order in which the commands are being executed. If PHP gets installed before Apache is installed, then certain configuration files will not automatically be configured. This can be done manually, but requires certain know-how. I yet have to come across easy tutorials or manuals.
#!/usr/bin/env bash

# Vagrant instance provision script

# Php 7.0
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update

# Apache 2.4
sudo add-apt-repository ppa:ondrej/apache2 -y
sudo apt-get update
sudo apt-get install apache2 -y
if ! [ -L /var/www ]; then
  rm -rf /var/www/html
  ln -fs /vagrant /var/www/html
fi

# Changed this line
sudo apt-get install php7.0 -y

I too have been facing this issue. So hopefully with this answer I provide some help to others.

