Custom PHP session.save_path in php-fpm config

DrWizzle

Verified User
Joined
Aug 8, 2021
Messages
164
The reason no any report yet,
I guest most of web dev just using "session_set_save_handler" function, so no reason to use that "session.save_path".
On one of my servers (mainly my WHMCS + WP Sales Site), I use redis for both pieces of software. As it's an exclusive server, I have the luxuryy of being able to config a slightly different way and cheat 😁. I have commented out the php_admin_value[session.save_path] = |PHP_SESSION_SAVE_PATH| in /usr/local/directadmin/data/templates/php-fpm.conf and relocated the |CUSTOM1| variable below the [user] section
PHP:
|?PHP_VER=54|
|?OPEN_BASEDIR_PATH=`HOME`/:/tmp/:/var/tmp/:/opt/alt/php`PHP1_RELEASE`/usr/share/pear/:/dev/urandom:/usr/local/php`PHP_VE>
|?EMAIL=`USER`@`DOMAIN`|
|?MAX_CHILDREN=`MAX_CHILDREN_DEFAULT`|
|?MAX_REQUESTS=500|

[|USER|]

|CUSTOM1|

user = $pool
group = $pool

listen = /usr/local/php|PHP_VER|/sockets/$pool.sock
listen.owner = $pool
listen.group = |SERVER_GROUP|
listen.mode = 660

pm = ondemand
pm.max_children = |MAX_CHILDREN|
pm.process_idle_timeout = 20
pm.max_requests = |MAX_REQUESTS|

php_admin_value[sendmail_path] = /bin/true

|*if PHP_SESSION_SAVE_PATH!=""|
;php_admin_value[session.save_path] = |PHP_SESSION_SAVE_PATH|
|*endif|

|*if OPEN_BASEDIR="ON"|
php_admin_value[open_basedir] = |OPEN_BASEDIR_PATH|

This is so when you rewrite_confs the php-fpmXX conf file isn't overwritten with the system set savepath.
This allows me to use:
Bash:
php_admin_value[session.save_handler] = redis
php_admin_value[session.save_path] = "/home/mydomain/.redis/redis.sock?persistent=1&database=1&timeout=25&prefix=whmcs_"
in the CUSTOM1 section of the HTTPD Configuration section for my WHMCS install which is a subdomain of the main domain. The Main domain is able to access a different redis database through a plugin and the .htaccess
 
A new build is released. The php_home_tmp_session_save_path feature will use php_value instead of php_admin_value to keep the flexibility of changing it at script runtime. Thanks @ShinJii. The new build also fixes File Manager directory delete window showing NaN undefined message when the real directory size is not known, thanks @DrWizzle.
Thanks @fln

I've just replied above with the way i'm using php_admin_value[...] Will this be affected with the new build?
 
If you modify file .../data/templates/php-fpm.conf directly, it will get restored to the latest version that comes with DirectAdmin (it just gets replaced when new files are extracted). This means your changes will be lost every time DA is updated.

If you create a copy of this file and place it in .../data/templates/[B]custom[/B]/php-fpm.conf, then this file will not be touched by the updates, and it will always be used for generating configs. The file .../data/templates/php-fpm.conf that is bundled with DA will not be used at all.

The same rules apply for all the files that come with DirectAdmin, not just this particular file. Customisations are copies of the file that are used instead of the default files.



It is best to avoid creating customised copies of the configuration files. Because once a specific file is customised you will lose any updates we are making to that files in new DA releases. The file gets frozen in time. This means you need to manually check if your customised files is still in sync with the rest of the system.



I think you could avoid having to keep a customised version of this config file.

Try setting CUSTOM1 to:
Code:
|?PHP_SESSION_SAVE_PATH=|

And CUSTOM2to:

Code:
php_admin_value[session.save_handler] = redis
php_admin_value[session.save_path] = "/home/mydomain/.redis/redis.sock?persistent=1&database=1&timeout=25&prefix=whmcs_"

CUSTOM1 will make sure that variable is set to empty value, this will cause default template no NOT add the code to change session.save_path.
CUSTOM1 will add the custom PHP values you want to have.
 
I think you could avoid having to keep a customised version of this config file.

Try setting CUSTOM1 to:
Code:
|?PHP_SESSION_SAVE_PATH=|

And CUSTOM2to:

Code:
php_admin_value[session.save_handler] = redis
php_admin_value[session.save_path] = "/home/mydomain/.redis/redis.sock?persistent=1&database=1&timeout=25&prefix=whmcs_"

CUSTOM1 will make sure that variable is set to empty value, this will cause default template no NOT add the code to change session.save_path.
CUSTOM1 will add the custom PHP values you want to have.
Thanks @fln, I'll try that

Just want to triple check, if i've read that right, if I set CUSTOM1 to |?PHP_SESSION_SAVE_PATH=| in the httpd conf (php-fpmxx) area of DA, that with force the clearing of php_admin_value[session.save_path] value?

Reason I moved the CUSTOM1 in the conf template was that I was trying to put php_admin_value[session.save_path] in the CUSTOM1 section, but it wouldn't work declared outside of the |USER| section, and if I put it in the CUSTOM2 section, because php_admin_value[session.save_path] was already declared and set to file in the DA bult php-fpmXX.conf file, it's one of those variables that you can't declare more than once for some reason, unlike variables like opcache, which I can set on and off for different software on the domain via .user.ini files. (WordPress like it, and WHMCS doesn't)

And thanks for mentioning the ../custom/ folder. I was just being lazy editing the template in the templates folder.
 
Yes. Original template has:
Code:
|*if PHP_SESSION_SAVE_PATH!=""|
php_admin_value[session.save_path] = |PHP_SESSION_SAVE_PATH|
|*endif|

The |*if ... *endif| block makes this line conditional. Condition is false when PHP_SESSION_SAVE_PATH is empty. The |?PHP_SESSION_SAVE_PATH=| updates the PHP_SESSION_SAVE_PATH to be empty.
 
Yes. Original template has:
Code:
|*if PHP_SESSION_SAVE_PATH!=""|
php_admin_value[session.save_path] = |PHP_SESSION_SAVE_PATH|
|*endif|

The |*if ... *endif| block makes this line conditional. Condition is false when PHP_SESSION_SAVE_PATH is empty. The |?PHP_SESSION_SAVE_PATH=| updates the PHP_SESSION_SAVE_PATH to be empty.
Perfect, thank you, I thought so. I'll do that now as DA has already updated itself automatically. Much appreciated!!

Alan

*Quick edit* @fln ,
As DA updated itself automatically, that gave me a chance to set it up as you suggested and it worked like a charm. Huge thanks!
 
Last edited:
Back
Top