简体   繁体   中英

Apache: How to add to the path for a virtualhost

I need to add an additional path to my Apache configuration for PHP. Ideally, it would be Serverwide but as I'm using ServerPilot it's easier to just affect the individual VirtualHosts.

The Path is currently set to PATH /opt/sp/php7.3/bin:/sbin:/usr/sbin:/bin:/usr/bin but I need to additionally add /opt/sqlanywhere17/res

eg /opt/sp/php7.3/bin:/sbin:/usr/sbin:/bin:/usr/bin:/opt/sqlanywhere17/res

I have tried adding

export PATH=$PATH:/opt/sqlanywhere17/res but apache fails to start

What syntax do I need to use in the VirtualHosts.conf file to make this work???

You can set env variblae using SetEnv in Apache httpd.

SetEnv VARIABLE_NAME variable_value

Refer link for more information.

You can set path environment variable inside VirtualHost.

SetEnv path  /opt/sp/php7.3/bin:/sbin:/usr/sbin:/bin:/usr/bin:/opt/sqlanywhere17/res

Then you can retrieve the path variable in PHP using below sample code:

<?php
$path = getenv("path");
echo $path;
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM