Install PHP via Yocto

I was able to add the apache2 package to the version 2.7.3 linux and build a new image using bitbake. I modified local.conf and bblayer.conf as mentioned in this link Installing Apache via Yocto - Toradex Community

How do I go about adding PHP to the linux image?

You can use the OpenEmbedded Layer Index to search for recipes in layers:

https://layers.openembedded.org/layerindex/branch/master/recipes/?q=php

It seems that PHP is available in the meta-oe layer, so simply adding php and php-cli to IMAGE_INSTALL_append should give you PHP and CLI PHP support. To use PHP with Apache 2 you need also to configure PHP packageconfig e.g. in your local.conf:

PACKAGECONFIG_append_pn-php = " apache2"

And then add php-modphp to IMAGE_INSTALL_append.