How to change Php default session directory

What you need?

  • Apache Server 
  • Php module enabled on Apache server

Why you need this?
 If there is Php module enabled on your machine but you don’t have right permission on the default directory that Php uses for writing session information, you need to change it so that Php works normal.

What you have to do?
There are more than one way to change Php session directory. I am going to introduce one way. In your Apache webroot directory add a file called .htaccess with the following in it:

php_value session.save_path ‘/home/user1/tmp’ (you should change the path to your own desired one) 

How to test if Php is enabled?
Create a file called phpinfo.php and have the following in it:

<?php phpinfo(); ?>

Navigating to that file (e.g. localhost/phpinfo.php). Apache should bring you information about your php installation like below. Navigate to the session section and you can see if the session path for your Php has been changed or not.

Leave a Reply

Your email address will not be published. Required fields are marked *