LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
Your LoadModule directive in httpd.conf file points to php71 path. You may want to change that to php73 path. Also, set the handler properly:
SetHandler application/x-httpd-php73
If you just had one php version, then x-httpd-php would work.
Restart apache to ensure new configurations are loaded.
You may also need to do additional setup mentioned below. I am not sure if that's necessary, but you may give it a try.
If you want to force web request to specific PHP version, you have 2 options:
1. php.ini modifications
In your php_info() output, you would see loaded configuration file - php.ini path. Go to that path and add the
AddHandler application/x-httpd-php73 .php
2. Add the following directives in the .htaccess file of your website.
To switch to PHP 7.3
AddHandler application/x-httpd-php73 .php
To switch to PHP 7.1
AddHandler application/x-httpd-php71 .php
Details
PHP lets you load multiple php.ini files with a provision to override them in particular folder.
When you run the PHP script with phpinfo(), it would load the nearest php.ini to that file. It may be the root level or any other php.ini that is present in the folder hierarchy above.
Whereas when you run from terminal, it would run PHP from the path that is registered in your environment variable. When you run from terminal, I doubt apache configuration would come into the picture, so changing anything in apache configuration won't have an effect on terminal execution. The Apache PHP module and the PHP command line binary are two different things that don’t interfere with each other.
If you want to force your terminal to use the version that you want, there are two options
1. Change the environment variable to run PHP in a specific version
printenv PATH
This would have a path to your PHP. Remove that and put new one by
export PATH=/usr/local/php73/bin:$PATH
2. Change the PHP alias
You can also use an alias instead. Add the following to your .bash_profile file.
alias php='/usr/local/php73/bin/php'
This works the same as the export PATH when added to your .bash_profile.