<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Control WebPanel Wiki &#187; open_basedir</title>
	<atom:link href="https://wiki.centos-webpanel.com/tag/open_basedir/feed" rel="self" type="application/rss+xml" />
	<link>https://wiki.centos-webpanel.com</link>
	<description>CentOS WebPanel Wiki</description>
	<lastBuildDate>Wed, 12 Feb 2025 20:38:16 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>PHP open_basedir</title>
		<link>https://wiki.centos-webpanel.com/php-open_basedir</link>
		<comments>https://wiki.centos-webpanel.com/php-open_basedir#comments</comments>
		<pubDate>Tue, 24 Jul 2018 13:18:36 +0000</pubDate>
		<dc:creator><![CDATA[publisher]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[open_basedir]]></category>

		<guid isPermaLink="false">http://wiki.centos-webpanel.com/?p=988</guid>
		<description><![CDATA[How to enabled PHP open_basedir in CWP ** Note this is only for PHP-CGI We have two options - global config, one config file in the include folder /usr/local/php/php.d/ and in PHP selector include folders - per-user config, the securest option as it restricts the user to his /home/USERNAME folder and also disables users from [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><strong>How to enabled PHP open_basedir in CWP</strong><br />
** Note this is only for PHP-CGI</p>
<p><strong>We have two options</strong><br />
- global config, one config file in the include folder /usr/local/php/php.d/ and in PHP selector include folders<br />
- per-user config, the securest option as it restricts the user to his /home/USERNAME folder and also disables users from using custom php.ini files.</p>
<p><strong>Global Configuration </strong><br />
The securest method do this correctly and to prevent users from overriding this is to place the config into the include file. Please note that if you set this into /usr/local/php/php.ini then custom user php.ini will be able to disable it. Please note that global config allows full /home folder access while per user restricts users to /home/USERNAME folder which is much more secure.</p>
<p>One line command to create a file and config:</p>
<pre>echo "open_basedir = /home:/tmp:/var/tmp:/usr/local/lib/php/" > /usr/local/php/php.d/open_basedir.ini</pre>
<p>You can also do it by yourself by creating a file: /usr/local/php/php.d/open_basedir.ini with the following content:</p>
<pre>open_basedir = /home:/tmp:/var/tmp:/usr/local/lib/php/</pre>
<p>To enable it for other php versions from the PHP selector you can create this config files with the same content:</p>
<pre>
/opt/alt/php44/usr/php/php.d/open_basedir.ini
/opt/alt/php52/usr/php/php.d/open_basedir.ini
/opt/alt/php53/usr/php/php.d/open_basedir.ini
/opt/alt/php54/usr/php/php.d/open_basedir.ini
/opt/alt/php55/usr/php/php.d/open_basedir.ini
/opt/alt/php56/usr/php/php.d/open_basedir.ini
/opt/alt/php70/usr/php/php.d/open_basedir.ini
/opt/alt/php71/usr/php/php.d/open_basedir.ini
/opt/alt/php72/usr/php/php.d/open_basedir.ini
/opt/alt/php7/usr/php/php.d/open_basedir.ini</pre>
<p><strong>Testing:</strong><br />
Create a phpinfo file on some account/domain/subdomain ... and open it with a browser.<br />
open_basedir value should show info from the config</p>
<p>PHP info file example phpinfo.php</p>
<pre>
&lt;?php phpinfo(); ?&gt;
</pre>
<p><strong>Per User open_basedir</strong><br />
To enable per-user open_basedir you can create a php.ini file in the users /home folder.<br />
Example: /home/USERNAME/php.ini ,make sure the file is owned by root so that the user can't disable it.</p>
<pre>
echo "open_basedir = /home/USERNAME:/tmp:/var/tmp:/usr/local/lib/php/" > /home/USERNAME/php.ini
chown root.root /home/USERNAME/php.ini
chmod 555 /home/USERNAME/php.ini</pre>
<p><em>** Don't forget to replace the USERNAME.</em></p>
<p>Please note that this option will also disable all further custom users php.ini files per folder, for example: /home/USERNAME/public_html/php.ini will not be loaded.</p>
<p>You can also place it into public_html folder but then users will be able to run custom php.ini files per folder and they can disable open_basedir.</p>
<p><strong>RECOMMENDATION</strong><br />
We recommend using the per-user configuration of open_basedir as it will provide much higher security and isolate each client.</p>
<hr />
<strong>NGINX + PHP-FPM</strong><br />
configuration files are:<br />
/etc/nginx/conf.d/vhosts/DOMAIN.conf<br />
/etc/nginx/conf.d/vhosts/DOMAIN.ssl.conf</p>
<p>under fastcgi_param add one more line and reload/restart nginx</p>
<pre>fastcgi_param   PHP_ADMIN_VALUE "open_basedir =/home/USERNAME:/tmp:";</pre>
<p>** Note that manual editing of the webserver vhost files is not recommended as those files get rebuilt from the template on each change.<br />
<a href="/webservers-vhost-templates" title="How to create a webserver template file" target="_blank">Try checking the instructions here for the custom template build.</a></p>
<hr />
<strong>APACHE + PHP-FPM</strong><br />
Configuration files are all user existing php-fpm configuration files, to get the list of files you can use this</p>
<pre>ls -la /opt/alt/php-fpm*/usr/etc/php-fpm.d/users/USERNAME.conf</pre>
<p>Add at the bottom</p>
<pre>php_admin_value[open_basedir] = /home/USERNAME:/tmp</pre>
<p>** Note that editing any of those files requires to restart php-fpm version you edited.</p>
<p>** Note that manual editing of the webserver vhost files is not recommended as those files get rebuilt from the template on each change.<br />
<a href="/webservers-vhost-templates" title="How to create a webserver template file" target="_blank">Try checking the instructions here for the custom template build.</a></p>
]]></content:encoded>
			<wfw:commentRss>https://wiki.centos-webpanel.com/php-open_basedir/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
