0

I'm using web server nginx, php 7.1 fpm and laravel in Centos 7. I want to install SQL Server following the official installation tutorial for Linux but I'm confused with this command:

echo extension=pdo_sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/pdo_sqlsrv.ini echo extension=sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/sqlsrv.ini 

What does it even mean? I tried to understand it write extension=sqlsrv.so then >> to php --ini (this means php.ini right?)

Then I tried to use this php --ini | grep "Scan for additional .ini files" and produce "Scan for additional .ini files in: /etc/php.d" now I'm confused with the sed command.

    3 Answers 3

    0

    The command is used to get the path to the directory of your additional php configuration files to create new *.ini files.

    If I run the command php --ini it lists my configuration files and paths like this:

    $ php --ini Configuration File (php.ini) Path: /etc/php/7.2/cli Loaded Configuration File: /etc/php/7.2/cli/php.ini Scan for additional .ini files in: /etc/php/7.2/cli/conf.d Additional .ini files parsed: /etc/php/7.2/cli/conf.d/10-opcache.ini, /etc/php/7.2/cli/conf.d/10-pdo.ini, /etc/php/7.2/cli/conf.d/20-calendar.ini, ... 

    You can see the line Scan for additional .ini files in: /etc/php/7.2/cli/conf.d. The grep is used to get this specific line and the sed command is used to strip off Scan for additional .ini files in: and leave the path to the config directory /etc/php/7.2/cli/conf.d.

    So the first command appends the string extension=pdo_sqlsrv.so to file /etc/php/7.2/cli/conf.d/pdo_sqlsrv.ini and in your case the path is /etc/php.d/pdo_sqlsrv.ini.

    1
    • thankyou for the explanation. now i understand the meaning of echo extension=pdo_sqlsrv.so >> php --ini | grep "Scan for additional .ini files" what about sed -e "s|.*:\s*||"/pdo_sqlsrv.ini ? still not understand this part. thanks beforeCommentedJul 3, 2019 at 10:20
    0

    The back ticks are sort of equivalent to $(), but harder to use. In this case they are equivalent. So the code can read as.

    echo extension=pdo_sqlsrv.so >> "$(php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||")/pdo_sqlsrv.ini" echo extension=sqlsrv.so >> "$(php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||")/sqlsrv.ini" 

    For each line, the bit in the $() is run first, and the output (stdout) is substituted in its place. The whole line is then re-scanned and run again.

    Therefore the bit in the $() is used to create the directory name, and the text extension=pdo_sqlsrv.so (for the first one) is appended to «directory»/pdo_sqlsrv.ini

    I have refactored as (not tested as I don't intend to install php). Hope it makes sense now.

    directory="$(php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||")" echo extension=pdo_sqlsrv.so >> "${directory}/pdo_sqlsrv.ini" echo extension=sqlsrv.so >> "${directory}/sqlsrv.ini" 
    2
    • i see that you made it as an environment variable right ? i will try it your way since i need to create a script for this without login as root 1st. (echo extension=pdo_sqlsrv.so >> php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"/pdo_sqlsrv.ini) the command cannot use sudo and produce error : permission deniedCommentedJul 3, 2019 at 10:24
    • Yes but not an environment variable. It i just a variable.CommentedJul 4, 2019 at 18:41
    0

    I already got the answer myself. It turns out, I can do command echo or curl using sudo if using bash -c like this :

    sudo bash -c 'echo extension=pdo_sqlsrv.so >> "$(php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||")/pdo_sqlsrv.ini"' 

    thank you for anyone who helped me :)

      You must log in to answer this question.

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.