I have implemented app on adionisjs framework and I want to deploy it on godaddy shared server, is there is any way to do that?
You cannot deploy nodejs app on a shared server directly, because the shared server is configured with server name not with the port, so instead, you can use PHP to run nodejs app.
<?php
//Choose JS file to run
$file = 'node_modules/jt-js-sample/index.js';
//Spawn node server in the background and return its pid
$pid = exec('PORT=49999 node/bin/node ' . $file . ' >/dev/null 2>&1 & echo $!');
//Wait for node to start up
usleep(500000);
//Connect to node server using cURL
$curl = curl_init('http://127.0.0.1:49999/');
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//Get the full response
$resp = curl_exec($curl);
if($resp === false) {
//If couldn't connect, try increasing usleep
echo 'Error: ' . curl_error($curl);
} else {
//Split response headers and body
list($head, $body) = explode("\r\n\r\n", $resp, 2);
$headarr = explode("\n", $head);
//Print headers
foreach($headarr as $headval) {
header($headval);
}
//Print body
echo $body;
}
//Close connection
curl_close($curl);
//Close node server
exec('kill ' . $pid);
Related
I have moved my xampp server to raspbian for image uploading. I can access the server, folder via browser and can see that image was registered in DB but unfortunately there is no image at that folder.
If you need more specific information let me know.
My phone app: https://gist.github.com/DoIReallyNeedIt/a068c69958f269ad1d1a373d9ec8bcdb
Connection to server:
<?php
$user_name = "root";
$user_pass = "root";
$host_name = "localhost";
$db_name = "mydb";
$con = mysqli_connect ($host_name, $user_name, $user_pass, $db_name);
if ($con)
{
$image = $_POST["image"];
$name =date('Y').date('m').date('d'). "_" . date('H'). date('i'). "_". $_POST["name2"]."_".$_POST["name1"];
$sql = "insert into imageinfo(name) values ('$name')";
$upload_path = "uploads/$name.jpg";
if(mysqli_query($con,$sql)){
file_put_contents ($upload_path, base64_decode($image));
echo json_encode (array ('response'=>'Nuotrauka buvo sėkmingai įkelta'));
}
else {
echo json_encode (array ('response'=>'Nuotraukos įkelti nepayvko'));
}
}
mysqli_close($con);
?>
Found the problem. For some reason chmod didn't saved for folders
I have Couchdb installed locally on Windows, localhost:5984 and on Google Cloud, 104.197.185.97:5984. I reviewed the local.ini and also settings via Fauxton. I run code to create a user with one database per user, the setting is [couch_peruser] enable = true.
I create the Couchdb user (and the database is automatically created, for example userdb-70706333) in Laravel/php (see below) and using my Windows curl here as a test, I can connect to the specific user's database as an admin:
curl -X GET http://adminUserName:adminPassword#localhost:5984/userdb-70706333
curl -X GET http://adminUserName:adminPassword#104.197.185.97:5984/userdb-70706333
Yet I get an error "unathorized" reason: "Name or password is incorrect" for Google cloud server - why? (First line works, second line gives this error)
curl -X GET http://userName:userPassword#localhost:5984/userdb-70706333
curl -X GET http://userName:userPassword#104.197.185.97:5984/userdb-70706333
The local.ini files are almost identical:
Both have:
[couch_peruser]
delete_dbs = true
enable = true
[chttpd]
port=5984
bind_address=0.0.0.0
require_valid_user=true
authentication_handlers =
WWW-Authenticate=Basic realm="Administrator"
enable_cors = true
authentication_handlers = {couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, proxy_authentication_handler}, {couch_httpd_auth, default_authentication_handler}
[couch_httpd_auth]
require_valid_user=true
allow_persistent_cookies = true
proxy_use_secret =
timeout = 6000
[ssl]
port=6984
[cors]
origins = *
credentials = true
methods = GET, PUT, POST, HEAD, DELETE
headers = accept, authorization, content-type, origin, referer
Differences:
Google cloud server:
[couchdb]
database_dir=/opt/bitnami/couchdb/var/lib/couchdb
view_index_dir=/opt/bitnami/couchdb/var/lib/couchdb
plugin_dir=/opt/bitnami/couchdb/lib/couchdb/plugins
Local:
[couchdb]
database_dir=./data
view_index_dir=./data
My Laravel/php code to create the couchdb/user:
curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
$data_array = array(
"name" => (string)($user_name),
"password" => (string)($user_password),
"roles" => ["users"],
"type" => (string)("user")
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$url = 'http://' . $admin_user_name . ':' . $admin_user_password . '#'.$remoteDbIP.'/_users/org.couchdb.user:' . $user_name;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json',
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_exec($curl);
So I call this from javascript:
var completeRemoteDbUrl = 'http://' + userName + ':' + userPassword + '#' + remoteDbUrl;
console.log("completeRemoteDbUrl:" + completeRemoteDbUrl);
var theRemoteDb = new PouchDB(completeRemoteDbUrl, {revs_limit: 1});
completeRemoteDbUrl value is
For local:
http://ppc1:jqW1iR370706331#localhost:5984/userdb-70706331
For remote:
http://ppc1:jqW1iR370706331#104.197.185.97:5984/userdb-70706331
So I tried both from curl and tried uploading the code to my cloudways server and both give me the same result "Name or password is incorrect". Got a feeling it is something simple. Thanks.
The answer is to open up a tunnel on the source server, which is the server you are calling the couchDB from. On my server that hosts couchDB, the key file is already created and you download that one (note *.pem is the linux one, *.ppk is the Windows one). Upload the key file to the source server, not the keyfile location and to open the tunnel run:
ssh -N -L SOURCE-PORT:127.0.0.1:DESTINATION-PORT -i KEYFILE-LOCATION DESTINATION-USERNAME#DESTINATION-SERVER-IP
Ctl-z out and run:
Then check it works with wget http://127.0.0.1:SOURCE-PORT/
Now I am figuring out how to keep the process running after I sign off my SSH connection to my source server. fuser looks good.
I have created a simple project to test sending photo to telegram bot in php 7, but nothing sends after starting the bot, however this project runs in php 5.3!
Is there anything different in php 7 that I should use it?
$message = file_get_contents("php://input");
$result = json_decode($message,true);
$token = "My_Robot_token";
if($result['message']['text']=='/start')
{
$target_url = "https://api.telegram.org/bot".$token."/sendPhoto";
$file_path = "./img/img1.jpg";
$file_name_with_full_path = realpath($file_path);
$chat_id = $result['message']['chat']['id'];
$photo_send = array(
'chat_id' => $chat_id,
'photo' => '#'.$file_name_with_full_path,
'caption' => 'photo sent!'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $photo_send);
$result=curl_exec ($ch);
file_put_contents('res.txt', $ch);
}
define('API_KEY','API Token');
function bot($method,$datas=[]){
$url = "https://api.telegram.org/bot" . API_KEY . "/" . $method;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$datas);
$res = curl_exec($ch);
if(curl_error($ch)){
var_dump(curl_error($ch));
}else{
return json_decode($res);
}
}
function sendphoto($ChatId, $photo, $caption){
bot('sendphoto',[
'chat_id'=>$ChatId,
'photo'=>$photo,
'caption'=>$caption
]);
}
$update = json_decode(file_get_contents('php://input'));
var_dump($update);
$message=$update->message;
$chat_id=$message->chat->id;
$text =$message->text;
if ($text=='/start'){
sendphoto($chat_id,"Your file_id","photo sent!"); // send photo by file_id
sendphoto($chat_id,new CURLFILE("file path"),"photo sent!"); // send photo by url
}
I am trying to create eJabberd users using PHP script.
The following script is working perfectly on my local system(Ubuntu 14.04) :
<?php
error_reporting(E_ALL);
ini_set('display_errors', '-1');
$username = 'userx1';
$password = '123456';
$node = 'localhost';
exec('ssh -t -t <hostname> ejabberdctl register '.$username.' '.$node.' '.$password.' 2>&1', $output, $status);
if($output == 0)
{
echo "User created successfully.";
}
else
{
// Failure, $output has the details
echo '<pre>';
foreach($output as $o)
{
echo $o."\n";
}
echo '</pre>';
}
But when I am trying to run on the server(CentOS).
Its giving me following error :
Host key verification failed.
I tried some solutions like :
https://askubuntu.com/questions/45679/ssh-connection-problem-with-host-key-verification-failed-error
https://www.youtube.com/watch?v=IJj0uD7EgGk
but no success.
Any reference will be very helpful. Thanks in advance.
Found A better way to crate user to eJabberd server.
mod_rest :
https://github.com/processone/ejabberd-contrib/tree/master/mod_rest
Provides you to make REST calls to the server.
I have 2 servers, one of them has the application for upload images and the folder that save the images is in the other server
So, how can i do that?? (connect the application with the folder in the other server)
If you upload your images with php, a solution is to upload via ftp the image to your second server (with folders to save images) from the first server.
You need :
private function ftpConnnect($ftp_server, $ftp_user_name, $ftp_user_pass)
{
// set up basic connection
$conn_id = ftp_connect($ftp_server);
if(ftp_login($conn_id, $ftp_user_name, $ftp_user_pass))
{
echo "Logged In\n";
}
else
{
echo "Not Logged In\n";
}
ftp_pasv($conn_id, true);
return $conn_id;
}
private function uploadOnServer($path, $saved_to, $ftp, $ftp_server_path)
{
// upload a file
if (ftp_put($ftp, $ftp_server_path.$saved_to, $path, FTP_BINARY)) {
echo "successfully uploaded $ftp_server_path$saved_to\n";
} else {
echo "There was a problem while uploading $ftp_server_path$saved_to\n";
}
}
Then call once :
$ftp = $this->ftpConnnect($serv, $user, $pass);
for each images
if($this->uploadOnServer($path, $saved_to, $ftp, $ftp_server_path))
unlink($path);
And at the end :
ftp_close($ftp);