I am using PHP exec
$copyBeforeDir = '/test/';
$fileProcessing = 'test.csv';
$zipStatus = exec("gzip ".$copyBeforeDir.$fileProcessing);
The paths are correct. The file exists. But there is no .gz file in that directory. Running the same command in linux command line works though.
Edit: This isnt a duplicate as I have ran exec on the same script and server for other jobs. I have fixed the problem and will post it in the solved answers.