git "version" from PHP and Apache

git sysadmin backend

If you want to access git "version" information for the current commit you can type this in the console while in your the directory for the repository you are working on.

git describe --always

BUT, if you want to get this information using PHP on an apache webserver, you need to do a little bit more.

<?php

$app_version = str_replace(array("\r", "\n"), '', shell_exec('git describe --always'));
echo $app_version;

You need to mark the repository as a safe directory in you .gitconfig file

[safe]
    directory = /directory/to/repository

Finally, you need to make sure that the .git directory inside the repository is owned by the apache group and user.

> sudo chown www-data:www-data .git -R