Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to write an install script and i need to change the sendmail line in php.ini

but I want to do this automatically

at the moment I'm doing this manually:

  • sudo nano /etc/php5/apache2/php.ini
  • finding the line containing sendmail_path =
  • then editing it to be
  • sendmail_path = /usr/bin/msmtp -t

then saving the file.

Is it possible to just auto script this to make the change?

Thanks a lot

share|improve this question

closed as off-topic by Dennis Kaarsemaker, mdpc, cole, Nathan C, kce Nov 14 '13 at 17:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must demonstrate a minimal understanding of the problem being solved. Try including attempted solutions, why they didn't work, and the expected results. See How can I ask better questions on Server Fault? for further guidance." – Dennis Kaarsemaker, mdpc, cole, kce
If this question can be reworded to fit the rules in the help center, please edit the question.

The better solution might be using something like augeas. – Zoredache Nov 9 '13 at 19:47
up vote 2 down vote accepted

Use sed:

sed -e '/^[^;]*sendmail_path/s/=.*$/= \/usr\/bin\/msmtp -t/' -i.bak /etc/php5/apache2/php.ini


sudo sed -e '/^[^;]*sendmail_path/s/=.*$/= \/usr\/bin\/msmtp -t/' -i.bak /etc/php5/apache2/php.ini

This is a work by word translation of your request to sed commands:

  • open the file /etc/php5/apache2/php.ini
  • find the line containing sendmail_path (whithout havin char ; before)
  • replace from the sign = to end of line by = /usr/bin/msmtp -t

Warning -i mean inplace modification. Using this will modify your php.ini (and create a php.ini.bak)

For trying only, don't use -i switch:

sed -e '/^[^;]*sendmail_path/s/=.*$/= \/usr\/bin\/msmtp -t/' /etc/php5/apache2/php.ini
share|improve this answer
thanks that's great, but do you know how i also uncomment the sendmail_path line in that command? the actual line i edit is ;sendmail_path= ... and i want it sendmail_path (without the ;) – Theston .E Fox Nov 9 '13 at 16:25
I've tried this command: sudo sed 's/;sendmail_path = /sendmail_path = \/usr\/bin\/msmtp -t/' /etc/php5/apache2/php.ini and it doesn't seem to update anything. I've also tried your command and it doesnt update. – Theston .E Fox Nov 9 '13 at 16:35
also, this doesn't work or seem to do anything: sudo sed -i 's/;sendmail_path/blahblah/' /etc/php5/apache2/php.ini i think something is wrong :( – Theston .E Fox Nov 9 '13 at 16:47
Ok this seems to work: sudo sed -i 's/;sendmail_path\s=.*/sendmail_path = \/usr\/bin\/msmtp -t/' /etc/php5/apache2/php.ini thanks for your help – Theston .E Fox Nov 9 '13 at 16:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.