I have installed moodle in AWS EC2 instance. But config.php file is missing. And I created a file using **
touch config.php
** command. But I couldnt place my content inside that file.
My content is
<?php // Moodle configuration file
unset($CFG); global $CFG; $CFG = new stdClass();
$CFG->dbtype = 'mariadb'; $CFG->dblibrary = 'native'; $CFG->dbhost
= 'localhost'; $CFG->dbname = 'moodledb'; $CFG->dbuser = 'root'; $CFG->dbpass = 'pass'; $CFG->prefix = 'mdl_'; $CFG->dboptions = array ( 'dbpersist' => 0, 'dbport' => '', 'dbsocket' => '', 'dbcollation' => 'utf8mb4_general_ci', );
$CFG->wwwroot = 'http://localhost/moodle'; $CFG->dataroot = 'L:\\xampp\\moodledata'; $CFG->admin = 'admin';
$CFG->directorypermissions = 0777;
require_once(__DIR__ . '/lib/setup.php');
I have connected to AWS using Putty from windows.
Use cat and heredoc:
cat > config.php <<'EOF'
your content
goes here
EOF
And you can skip touch this way.
Related
hi my goal is to create zip file and download it, working okay on local server but giving problem on Cpanel when i hit download button
$fileEntry = FileEntry::with('childEntriesRecursive')->where('shared_id', $shared_id)->notExpired()->firstOrFail();
abort_if(!static::accessCheck($fileEntry), 404);
$zip_file = str_replace(' ', '_', $fileEntry->name).'.zip';
$zip = new ZipArchive();
$zip->open(public_path($zip_file), ZipArchive::CREATE | ZipArchive::OVERWRITE);
foreach ($fileEntry->childEntriesRecursive as $key => $file) {
$getFile = storage_path('app/public/'.$file->path);
if (file_exists($getFile) && is_file($getFile)){
echo $file->name;
$zip->addFile(storage_path('app/public/'.$file->path), $file->name);
}
}
$zip->close();
return response()->download($zip_file, basename($zip_file))->deleteFileAfterSend(true);
output is
Following the answer suggested in the question -
Is it possible to permanently set environment variables?
I was able to set new environment variables permanently with the command -
spawnSync('setx', ['-m', 'MyDownloads', 'H:\\temp\\downloads'])
But now my goal is to append new values to the PATH environment variable.
Is it possible?
Why don't you just get the environment variable and then append to it?
I.e.
const {spawnSync} = require("child_process");
const current_value = process.env.PATH;
const new_path_value = current_value.concat(";", "/some/new/path");
var result = spawnSync('setx', ['-m', 'PATH', new_path_value])
// STDOUT
var stdOut = result.stdout.toString();
console.log(stdOut)
// STDERR
var stdErr = result.stderr.toString();
if(stdErr === '') {
console.log('Successfully set environment variable')
} else {
console.log(`ERROR: ${stderr}`)
}
Update "/some/new/path" and run this as admin as the link you provided suggests and it should work.
Run your script with the admin permission:
Open cmd or PowerShell with admin
Run node your_script.js
To append PATH variable, you can set value is : %PATH%;your_new_value here (%PATH% get old value)
If you run with electron app, you should require admin permission.
Don't forget setx run on window
I don't have rights to modify my registry, and I also would rather not call an OS command such as setx.
The following adds an additional component to the Windows PATH. I then ran Selenium, which uses the new setting.
// Display current value of PATH
const current_value = process.env.PATH;
console.log("PREV VALUE:")
console.log(current_value)
// Add the additional entry
const addl_entry = String.raw`\my\new\path\component`
process.env["PATH"] = addl_entry + ";" + current_value
// Display the new value
console.log("NEW VALUE:")
console.log(process.env.PATH)
const fs = require("fs")
//const HOW = "/home/test/everything"
// const HOW = "/home/test/"
// This one fails. My home is encrypted and it cannot read directories, it gets the .Private file. I want to read files and directories in my home folder. But can't.
const HOW = "/home/test/folder/"
// This one works for some reason. It lists all the directories in the folder.
// const HOW = "folder"
// This one works as well
var list = walk(HOW)
console.log(list)
// How do I get contents of /home/test (which happens to be my home folder).
// I'm both root and "test" user of the computer.
I'd like to have walk() work on /home/test/.
The code that fails:
var walk = function(dir) {
var results = []
var list = fs.readdirSync(dir)
list.forEach(function(file) {
file = dir + '/' + file
var stat = fs.statSync(file)
if (stat && stat.isDirectory()) results = results.concat(walk(file))
else results.push(file)
})
return results
}
The exact line causing it (stack trace): var stat = fs.statSync(file)
The error is:
Error: ENOENT: no such file or directory, stat '/home/test/.Private/###############################################################'
Where # is an amount of letters whose importance to safety is unknown to me.
Node.js doesn't have a problem addressing any folder contained within my home folder, but cannot address the home folder itself. Neither my own account nor root account can get access to it.
I think you are adding an unnecessary /. Try changing
const HOW = "/home/test/folder/"
to
const HOW = "/home/test/folder"
I have one .env file , that looks like :
NODE_ENV = local
PORT = 4220
BASE_URL = "http://198.**.**.**:4220/"
PROFILE_UPLOAD = http://198.**.**.**:4220/uploads/profile/
POST_UPLOAD = http://198.**.**.**:4220/uploads/discussion/
COMPANY_UPLOAD = http://198.**.**.**:4220/uploads/company/
ITEM_UPLOAD = http://198.**.**.**/uploads/item/
GROUP_UPLOAD = http://198.**.**.**/uploads/group/
I want to do something like this :
NODE_ENV = local
IP = 198.**.**.**
PORT = 5000
BASE_URL = http://$IP:$PORT/
PROFILE_UPLOAD = $BASE_URL/uploads/profile/
POST_UPLOAD = $BASE_URL/uploads/discussion/
COMPANY_UPLOAD = $BASE_URL/uploads/company/
ITEM_UPLOAD = $BASE_URL/uploads/item/
GROUP_UPLOAD = $BASE_URL/uploads/group/
Expected result of BASE_URL is http://198.**.**.**:4220/
I have tried many few syntax but not getting computed values
Tried Syntax : "${IP}" , ${IP} , $IP
I have used dotenv package , for accessing env variables.
dotenv-expand is the solutions as #maxbeatty answered , Here are the steps to follow
Steps :
First Install :
npm install dotenv --save
npm install dotenv-expand --save
Then Change .env file like :
NODE_ENV = local
PORT = 4220
IP = 192.***.**.**
BASE_URL = http://${IP}:${PORT}/
PROFILE_UPLOAD = ${BASE_URL}/uploads/profile/
POST_UPLOAD = ${BASE_URL}/uploads/discussion/
COMPANY_UPLOAD = ${BASE_URL}/uploads/company/
ITEM_UPLOAD = ${BASE_URL}/uploads/item/
GROUP_UPLOAD = ${BASE_URL}/uploads/group/
Last Step :
var dotenv = require('dotenv');
var dotenvExpand = require('dotenv-expand');
var myEnv = dotenv.config();
dotenvExpand(myEnv);
process.env.PROFILE_UPLOAD; // to access the .env variable
OR (Shorter way)
require('dotenv-expand')(require('dotenv').config()); // in just single line
process.env.PROFILE_UPLOAD; // to access the .env variable
dotenv-expand was built on top of dotenv to solve this specific problem
As already stated you can't assign variables in .env files. You could move your *_UPLOAD files to a config.js file and check that into .gitignore , then you could do
//config.js
const BASE_URL = `http://${process.env.IP}:${process.env.PORT}/`
module.exports = {
PROFILE_UPLOAD: BASE_URL+"uploads/profile/",
POST_UPLOAD: BASE_URL+"uploads/discussion/",
....
}
Unfortunately dotenv can't combine variables. Check this issue to see more and find a solution for your project.
I have below code running on apache on linux mint 64 bit OS. Find that files cannot save on server. Do you know how to solve? add more config or privileges??
$config['file_name'] = basename($imgPath);
$config['upload_path'] = $upload_dir;
$config['allowed_types'] = 'gif|jpg|png|bmp';
$this->upload->initialize($config);
if ( ! $this->upload->do_upload("image".$i))
or
$this->image_lib->clear();
$config2['image_library'] = 'gd2';
$config2['source_image'] = $this->upload->upload_path.$this->upload->file_name;
$config2['new_image'] = $upload_dir_resize.'/'.$thumb_fileName;
$config2['maintain_ratio'] = TRUE;
$config2['width'] = 320;
$config2['height'] = 320;
$this->image_lib->initialize($config2);
if ( !$this->image_lib->resize()){
You need to make sure you have 0777 rights on the folder you're saving.
if(!file_exists($folderPath))
mkdir($folderPath, 0777, TRUE);
$config['upload_path'] = $folderPath;
$config['file_name'] = randomStringName();
$config['allowed_types'] = 'jpg|png|bmp';
$config['max_size'] = '1024'; // 1MB~
$config['overwrite'] = FALSE;
if($this->upload->do_upload('image') == FALSE)
die('Ups...something went wrong');
$filePath = base_url() . $folderPath . $this->upload->data()['file_name'];