4

Severity: Warning

Message: mkdir(): open_basedir restriction in effect. File() is not within the allowed path(s): (/home/thelazyppl/:/home/thelazyppl:/tmp:/usr/local/lib/php/)

Filename: drivers/Session_files_drivers.php

The site's root folder is a wordpress website, so i've create a subdomain for the Codeigniter site named "Bazaar" in the root folder. I've already setup the base_url in the config.php and wordpress htaccess to allow the folder "Bazaar" but still nothing is working.

My host do not allow modifications for the php.ini file to disable open_basedir, is there another way to allow it or did i do something wrong in the process?

Karl Wong
  • 594
  • 2
  • 7
  • 23

3 Answers3

9

Your CodeIgniter installation is trying to save its session files to somewhere that is unwritable. As you're on shared hosting, I would recommend storing your session data in a database.

Based on the filename causing the error, it looks like you're on CodeIgniter 3. There is some info in the user guide on how to configure it correctly.

To keep using the files driver, you will need to change the contents of the $config['sess_save_path'] variable to point it to something like /tmp or /home/thelazyppl/tmp (after you created the tmp folder in your FTP outside your www or public_html directory).

The better option would be to use the database driver, for which the details are just below that.

If you were having these issues on CodeIgniter 2, you would need definitely need to enable the database. To do this you would change the $config['sess_use_database'] option to TRUE and then run the SQL shown in the CodeIgniter 2 user guide.

Andrew Gould
  • 376
  • 1
  • 9
4

After reading the official documentation

In config.php

You need to modify

FROM

$config['sess_driver'] = 'files';
$config['sess_save_path'] = NULL; 

TO

$config['sess_driver'] = 'database';
$config['sess_save_path'] = 'ci_sessions';

as well as you need to create the table by the name ci_sessions in case if it doesn't exist.

In order to use the ‘database’ session driver, you must also create this table that we already mentioned and then set it as your $config['sess_save_path'] value. For example, if you would like to use ‘ci_sessions’ as your table name, you would do this:

Note

If you’ve upgraded from a previous version of CodeIgniter and you don’t have ‘sess_save_path’ configured, then the Session library will look for the old ‘sess_table_name’ setting and use it instead. Please don’t rely on this behavior as it will get removed in the future.

And then, of course, create the database table …

For MySQL:

CREATE TABLE IF NOT EXISTS `ci_sessions` (
        `id` varchar(128) NOT NULL,
        `ip_address` varchar(45) NOT NULL,
        `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
        `data` blob NOT NULL,
        KEY `ci_sessions_timestamp` (`timestamp`)
);

For PostgreSQL:

CREATE TABLE "ci_sessions" (
        "id" varchar(128) NOT NULL,
        "ip_address" varchar(45) NOT NULL,
        "timestamp" bigint DEFAULT 0 NOT NULL,
        "data" text DEFAULT '' NOT NULL
);

CREATE INDEX "ci_sessions_timestamp" ON "ci_sessions" ("timestamp");

You will also need to add a PRIMARY KEY depending on your ‘sess_match_ip’ setting. The examples below work both on MySQL and PostgreSQL:

// When sess_match_ip = TRUE
ALTER TABLE ci_sessions ADD PRIMARY KEY (id, ip_address);

// When sess_match_ip = FALSE
ALTER TABLE ci_sessions ADD PRIMARY KEY (id);

// To drop a previously created primary key (use when changing the setting)
ALTER TABLE ci_sessions DROP PRIMARY KEY;
Nɪsʜᴀɴᴛʜ ॐ
  • 2,756
  • 4
  • 33
  • 57
  • Yes its working..!! also we can SET ``$config['sess_save_path'] = '/home/public/session' `` It will be your session directory path – Chandan Sharma Jul 16 '20 at 02:09
0

I had the same issue with codeigniter website hosted in Plesk for reference im setting the solution worked for me

Cause

PHP script is trying to access the folder for which access is not allowed. This restriction is limited by the PHP open_basedir variable for each virtual host separately. By default, open_basedir is set to allows access for PHP files to the tmp and httpdocs directories. Resolution

Note: If you are a domain owner and the open_basedir setting is not available for you, please contact your service provider for assistance.

Adjust the value of open_basedir in order to include missing path from the error message:

In Plesk, go to Domains > example.com > PHP Settings.

Modify the value of open_basedir:

For Linux

Below is an example of including the directory /var/lib/php/session to open_basedir:

{WEBSPACEROOT}{/}{:}{TMP}{/}{:}/var/lib/php/session

For Windows

Below is an example of including the directory E:\custom_folder\sessions to open_basedir :

    {WEBSPACEROOT}{/};{TMP};{/};"E:\custom_folder\sessions\"

Apply the changes.

source Plesk

Ridha Rezzag
  • 3,672
  • 1
  • 34
  • 39