Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change php.ini values from shell script

Tags:

shell

php

vagrant

I am new to shell scripts. I am running Vagrant, and find myself needing to adjust these setting in the php.ini:

upload_max_filesize 120M
post_max_size 120M
max_execution_time 200
max_input_time 200

How can I add those to a shell script so I can just provision my machine on first vagrant up?

like image 966
Chris Avatar asked Apr 17 '14 03:04

Chris


2 Answers

with below script, you can easily adjust php.ini values. Every time, just need update top 4 lines.

make sure, your sed command supports -i option.

#!/usr/bin/env bash

upload_max_filesize=240M
post_max_size=50M
max_execution_time=100
max_input_time=223

for key in upload_max_filesize post_max_size max_execution_time max_input_time
do
 sed -i "s/^\($key\).*/\1 $(eval echo = \${$key})/" php.ini
done
like image 91
BMW Avatar answered Nov 02 '22 15:11

BMW


There is a shell script for this purpose https://github.com/StanAngeloff/vagrant-shell-scripts#php

php-settings-update(name, value)

Update a PHP setting value. This function will look for all php.ini files in /etc. For each file, a conf.d directory would be created in the parent directory (if one doesn't already exist) and inside a file specifying the setting name/value will be placed.

Example (create a default timezone):

php-settings-update 'date.timezone' 'Europe/London'
like image 41
ihsan Avatar answered Nov 02 '22 15:11

ihsan