0

I need the following lines added to the top of my PHP file using a single bash script.

I'm new to the Sed / Awk commands specifically. I'm familiar with many other Linux commands.

Here are the lines.

[xdebug]
zend_extension=/usr/lib/php/20150306/xdebug.so
xdebug.remote_host = notsharingmydomainsorry.com
xdebug.idekey = "MYKEYIMNOTSHARING"
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.show_local_vars=0
xdebug.var_display_max_data=10000
xdebug.var_display_max_depth=20
xdebug.show_exception_trace=0
xdebug.remote_handler=dbgp

The second line: I'd like to replace the hard coded location with find / -name "xdebug.so" but I keep mangling the syntax.

The php.ini file is located in /etc/php/7.0/fpm/php.ini

I need to add these lines right after the initial [PHP] at the top of the file. This is going into the automated deployment for our dev server.

I'd rather not do a Sed / Awk command that utilizes an external file. I have the entire deployment script for each server in one file and I'd like to keep it that way.

I know you can do things like sed -i filenamewithbits.txt filenametochange.txt

I'm not interested in this, however well it works.

Community
  • 1
  • 1
CarComp
  • 1,929
  • 1
  • 21
  • 47
  • 1
    Can you just `cat` those lines with your php.ini and `mv -f` over the top of the original php.ini. You can use [heredoc with cat](https://stackoverflow.com/questions/2953081/how-can-i-write-a-heredoc-to-a-file-in-bash-script) so it can be contained in your script without a separate file. – JNevill Nov 29 '17 at 20:44
  • Ok after attempting the idea, it seems that cat doesn't want to append after a specific line... i'm still googling. – CarComp Nov 29 '17 at 21:11
  • That sounds not right. Are there tabs before the lines in the bit inside the heredoc? [heredocs can be picky about indentation](https://unix.stackexchange.com/questions/353076/how-to-indent-an-heredoc-inside-an-heredoc-the-right-way) – JNevill Nov 29 '17 at 21:14
  • No, but i end up with my lines either at at the end of the file or the beginning, but never after [PHP] because i can't figure that part out. – CarComp Nov 29 '17 at 21:15

0 Answers0