NULL folder inside public folder on CI 4 project - codeigniter

What is NULL folder inside public folder in my CI 4 project? seems like session cookies. How to set folder name so not appear as NULL, Thank you

Here you opted for the Driver FileHandler of Codeigniter 4 which stores session in files. In order to work properly you also need to give him a session save path.
Session configs are driven in the .env file and/or in app/Config/App.php.
Example of the config in App.php file with a session save path :
public $sessionDriver = 'CodeIgniter\Session\Handlers\FileHandler';
public $sessionCookieName = 'ci_session';
public $sessionExpiration = 28000; // 8h
public $sessionSavePath = 'hello/world';
public $sessionMatchIP = false;
public $sessionTimeToUpdate = 300;
public $sessionRegenerateDestroy = true;
Watch out :
It currently looks like that setting config in both files for the FileHandler driver is a bad idea. Setting it in App.php file seems a better option since it allows you to use multiple directories like dir1/dir2/my_session where this syntax catch an error in the .env file. But still be aware that the .env config ALWAYS takes over the one set in App.php

Related

Cannot get value from config in Lumen

I want to change the timezone in lumen, but I cannot get the value from config, it always give the default value UTC.
I've tried everything I know, to the point changing the default value to what I wanted. But still the timezone wont change
AppServiceProvider
public function register()
{
//set local timezone
date_default_timezone_set(config('app.timezone'));
//set local date name
setLocale(LC_TIME, $this->app->getLocale());
URL::forceRootUrl(Config::get('app.url'));
}
Bootstrap.app
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__)
))->bootstrap();
date_default_timezone_set(env('APP_TIMEZONE', 'Asia/Jakarta'));
$app->configure('app');
Config.app
'timezone' => env("APP_TIMEZONE", "Asia/Jakarta"),
.env
APP_TIMEZONE="Asia/Jakarta"
APP_LOCALE="id"
Also if I make a variable inside config.app such as:
'tes_var' => 'Test'
And using it like this:
\Log::info(config('app.tes_var'));
The result in Log is null, I can't get the value from tes_var.
I don't have any idea what's wrong here, if it's in Laravel maybe this is happened because cached config, but there's no cached config in Lumen. Maybe I miss some configuration here?
Thanks
First, you should create the config/ directory in your project root folder.
Then create a new file app.php under the config directory i.e. config/app.php
Now add whatever config values you want to access later in your application in the config/app.php file.
So, instead of creating a config.php file you should make a config directory and can create multiple config files under the config directory.
So final code will be like this:
config/app.php will have:
<?PHP
return [
'test_var' => 'Test'
];
Can access it anywhere like this:
config('app.tes_var');
Although Lumen bootstrap/app.php has already loaded the app.php config file (can check here: https://github.com/laravel/lumen/blob/9.x/bootstrap/app.php)
If not loaded in your case, you can add the below line in bootstrap/app.php file:
$app->configure('app');
Hope it will help you.
In order to use the env file while caching the configs, you need to create a env.php inside the config folder. Then, load all env variables and read as "env.VARIABLE_FROM_ENV". Example env.php:
<?php
use Dotenv\Dotenv;
$envVariables = [];
$loaded = Dotenv::createArrayBacked(base_path())->load();
foreach ($loaded as $key => $value) {
$envVariables[$key] = $value;
}
return $envVariables;
then read in your code:
$value = config('env.VARIABLE_FROM_ENV', 'DEFAULT_VALUE_IF_YOU_WANT');

How get cloudinary file url/other properties by public_id?

Saving images under cloudinary( with cloudinary-laravel 1.0) I keep public_id in my database
and I want to get url(http or https), size, dimaentainal of this file by public_id
At reading this
/**
* You can also retrieve a url if you have a public id
*/
$url = Storage::disk('cloudinary')->url($publicId);
at
https://github.com/cloudinary-labs/cloudinary-laravel
I got ERROR:
Disk [CLOUDINARY] does not have a configured driver.
But I save images to cloudinary with storeOnCloudinaryAs method and in my .env I have
CLOUDINARY_URL=cloudinary://NNNNNNNNNNNN:AErjB_-XXXXXXXXX
CLOUDINARY_UPLOAD_PRESET=ml_default
and default file config/cloudinary.php
My config/filesystems.php has no any cloudinary parameters and can it be reason of my error?
Also it seems very strange for me that Storage::was used in this case, but I did not
find how get file url/other properties by public_id ?
Edited 1:
I added line
...
CloudinaryLabs\CloudinaryLaravel\CloudinaryServiceProvider::class,
...
in 'providers' block of ny config/app.php and cleared cach.
But still got
"Disk [CLOUDINARY] does not have a configured driver."
error.
applying changes into .env and clearing cache I try to debug from which line error is triggered in file vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php as :
protected function resolve($name)
{
$config = $this->getConfig($name);
\Log::info( varDump($name, ' -1 $name resolve::') ); // IT HAS ‘CLOUDINARY’ value
if (empty($config['driver'])) {
throw new InvalidArgumentException("Disk [{$name}] does not have a configured driver.");
}
But what is source for $config in this file?
config/filesystems.php ? In this file I have no any CLOUDINARY block. maybe I need to add it? But in which format ?
Thanks in advance!
Setting driver to lowercase
$cloudinaryUrl = Storage::disk(strtolower($imagesUploadSource))
fixed this error.

How to enter localhost url manually ( using xampp php version 7.2)

I am trying to get into my root i have xampp in my D folder and i have create folder name (app) into my htdocs and created file Book.php now i am trying to access this file using url http://localhost/app/Book.php but no output. can anyone correct me?
class Book // class is where we define properties and methods
{
public $isbn;
public $title;
public $author;
public $available;
//instantiate
$harry_potter = new Book();
$harry_potter->isbn = 322401494;
$harry_potter->title = "Harry Potter and Magicians";
$harry_potter->author = "Shahzad";
$harry_potter->available = 10;
var_dump($harry_potter);
Actually, I can see 2 main reasons for this to happen,
You aren't using the right port, XAMPP might be using another port like 8080 check it out in the settings. If this is right then you should access to your file using localhost:port/book.php
Book.php return nothing, you should post book.php code here so we can figure out where is the problem.
Hope it could help.

Joomla 3 test site vs. production site: which files should change?

I am maintaining a Joomla 3 site, and I want to set up a test site in a different web host, so that we can test code changes in it first. The test web host is in a different server, uses a different DB, etc., but otherwise I want it to be as identical as possible to the production site.
Which files should I pay attention to, when downloading and uploading the site to the other host? I know about configuration.php. Is there anything else?
(All the docs I've found when searching were about older versions of Joomla: 1.5, 2.x...)
Here is another solution which does not involve any third party component. You need to take care of some points though. Steps are explained below.
Copy the entire files from 1st server to 2nd server.
From phpmyadmin copy the database from 1st to 2nd server.
Change the database details and other configuration details in the configuration.php file. Mainly you need to change the database details and the log and tmp path. Check the log and tmp folders are writable.
<?php
class JConfig {
public $db = 'joomla';
public $dbprefix = 's5oiy_';
public $log_path = 'C:/xampp/htdocs/joomla/administrator/logs';
public $memcache_server_host = 'localhost';
public $memcache_server_port = '11211';
public $password = 'dbpass';
public $sendmail = '/usr/sbin/sendmail';
public $smtpauth = '0';
public $smtphost = 'localhost';
public $smtppass = '';
public $smtpport = '25';
public $smtpsecure = 'none';
public $smtpuser = '';
public $tmp_path = 'C:/xampp/htdocs/joomla/tmp';
public $user = 'root';
public $memcached_server_host = 'localhost';
public $memcached_server_port = '11211';
public $redis_server_host = 'localhost';
public $redis_server_port = '6379';
public $redis_server_auth = '';
public $redis_server_db = '0';
public $proxy_enable = '0';
public $proxy_host = '';
public $proxy_port = '';
public $proxy_user = '';
public $proxy_pass = '';
public $session_memcache_server_host = 'localhost';
public $session_memcache_server_port = '11211';
public $session_memcached_server_host = 'localhost';
public $session_memcached_server_port = '11211';
}
?>
These are the variables in configuration.php file that need to be checked once you change the server.
If you dont know the Base directory path you may give wrong log and tmp path. So to know the directory path you can use this code
<?php
$dir = getcwd();
echo $dir;
?>
For things like this I suggest using Akeeba Backup and Kickstart
https://www.akeebabackup.com/products/akeeba-backup.html
https://www.akeebabackup.com/products/akeeba-kickstart.html
Just create a backup of your site and use Kickstart to install it on your test server. The install process will take care of the different settings. Make sure you disable sending mails from the test system. Otherwise your users might get mails the should not get.
Sven's suggestion is great, here are a couple of other options.
There might be some advantages to creating your test site on the same server as your production site, for one thing, you'll know that the server environment will be the same. Here are 2 ways you could do this.
You could create a new 'test' subdirectory on your production site and use Akeeba backup to install a copy of your site in that location. If you do this, take care to create a second test database and specify this new database when you use Akeeba backup. When you are finished your production site will be at www.domain.com and your test site will be at www.domain.com/test/
Alternatively StageIt is a very good commercial plugin which will setup a staging environment on your production server. You can test your ideas and sync them back from the test to the production site when you are finished.
Good luck!

Codeigniter dynamic configuration

How do I let users set the database configuration for a new CI install?
My intention is to have a form that allows them to enter the data then either generate a new config file or to set the options in the database.php file.
Is this possible?
Let's say you want to create a database config file. Here's how I do it:
Create a "dummy" config file by copying a real one, and use values that look something like this:
$db['default']['hostname'] = '__HOSTNAME__';
$db['default']['username'] = '__USERNAME__';
$db['default']['password'] = '__PASSWORD__';
$db['default']['database'] = '__DATABASE__';
Have the user complete the installation form, and verify all the data by testing a database connection. Next, use file_get_contents() to grab the content of the "dummy" config file, use a simple str_replace() to rewrite the values with the ones the user provided, then write the new content to your real config file overwriting the entire thing.
Here's part of the actual code I'm using for creating the file, just to get an idea. Bear in mind that I'm running this on a totally separate CI installation (the "installer"), and this is not a copy/paste example:
// Write the database configuration file
$config = array(
'hostname',
'username',
'password',
'database',
);
$data = file_get_contents(APPPATH.'config/dummy_database.php');
$file = '../private/config/database.php';
// Oops! Just caught this after posting: str_replace() accepts arrays.
// TODO: Use the array method instead of a loop!
foreach ($config as $item)
{
$data = str_replace('____'.strtoupper($item).'____', mysql_escape_string($this->data[$item]), $data);
}
if (write_file($file, $data))
{
$this->message('Database configuration file was written!', 'success');
#chmod($file, 0644);
{
if (is_really_writable($file))
{
$this->message('The database configuration is still writable, make sure to set permissions to <code>0644</code>!', 'notice');
}
}
}
else
{
$this->message('Could not write the database configuration file!');
redirect('step_4');
}
This retains the original copy of the "dummy" config file. You could use the same logic for editing, just read the current config values for anything the user has not changed and do the same string replacement technique.

Resources