I am very new with AWS while deploying my project i found that session is not getting stored .
so with help of google and stack-overflow i was trying to resolve is and trying following code
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
ini_set('display_errors', 'on');
//ini_set('session.gc_maxlifetime', 1500);
ini_set("session.save_handler", "files");
$dir=getcwd() . '/ses'; //folder with 777 permission
ini_set('session.save_path', $dir);
//ini_set('session.name', "name-session");
ini_set('session.gc_probability', 1);
ini_set('session.use_only_cookies', 0);
//ini_set('session.serialize_handler', '');
$sId = session_id();if ($sId == '') { session_start(); }
print_r($_SESSION);
$_SESSION['loggedIn']="swarna";
$_SESSION['name']=session_name();
$_SESSION['cookie_params']=session_get_cookie_params();
$_SESSION['cache_expire']=session_cache_expire();
$_SESSION['session_id']=session_id();
$_SESSION['maxlifetime']=ini_get("session.gc_maxlifetime");
echo "<br> \n <pre>";
print_r($_SESSION);
print_r(scandir($dir));
echo "<br> \n </pre>";
but it didn't worked each time i refresh it is printing the first print_r($_SESSION); as empty and second one with different session id while expedition first one with same data which i have stored last execution .
Array ( )
Array
(
[loggedIn] => swarna
[name] => name-session
[cookie_params] => Array
(
[lifetime] => 0
[path] => /
[domain] =>
[secure] =>
[httponly] =>
)
[cache_expire] => 180
[session_id] => qip9hisbsh901gbpbjef4qe70c
[maxlifetime] => 1440
)
Array
(
[0] => .
[1] => ..
[2] => sess_2rkl7v7h593ih942i1k14o9s4d
[3] => sess_4ccmmm0efq7quj26pm6r0ue9sn
[4] => sess_8rvh2nd9n0ng4vtekevh6p26ef
[5] => sess_lj4r99u9gf22ur935jr4gbcd97
[6] => sess_qip9hisbsh901gbpbjef4qe70c
)
now i am using php7 in AWS Amazon Linux 2 server . can any one guide me what to be done ? what is wrong their .
i have also tried
this has nothing to do with AWS or ec2, I recommend you comment out all PHP into variables at the beginning of the script and always have session_start() at the beginning script
Related
I'm in trouble doing a sed command inside an ssh call. I need to use single quotes in my sed command. Here is my command line :
ssh root#192.168.0.32 "sed -i '/0 => '192.168.0.32' /a 1 => '$old',' /tmp/test"
Here is the file :
<?php
$CONFIG = array (
'trusted_domains' =>
array (
0 => '192.168.0.32',
),
'dbtype' => 'mysql',
'dbport' => '',
'dbtableprefix' => 'oc_',
'logtimezone' => 'UTC',
'installed' => true,
'redis' =>
array (
'host' => '192.168.0.13',
'port' => 9095,
),
'mail_smtpmode' => 'sendmail',
'mail_from_address' => 'noreply',
'knowledgebaseenabled' => false,
0 => 18,
'loglevel' => 1,
'maintenance' => false,
);
In this context, I want to add in the trusted_domains for example 1 => '192.168.0.1', after the first element.
The problem of the command is that he doesn't recognize the single quotes inside the sed command.
Don't forget, the sed command is inside a ssh command
Let's minimize this problem (and in the process of it realize, that most of your context could be stripped from your question.) First we define a helper function args to understand how the commands are split into words
$ args() { for x in "$#"; do echo "[$x]"; done; }
$ old=0.0.0.0
$ args ssh root#192.168.0.32 "sed -i '/0 => '192.168.0.32' /a 1 => '$old',' /tmp/test"
[ssh]
[root#192.168.0.32]
[sed -i '/0 => '192.168.0.32' /a 1 => '0.0.0.0',' /tmp/test]
Therefore a single argument ("sed -i ...") is passed to ssh. The double
quotes are necessary for the variable expansion to take place but we can
simplify the problem by inlining the old variable:
$ args sed -i '/0 => '192.168.0.32' /a 1 => '0.0.0.0',' /tmp/test
[sed]
[-i]
[/0 => 192.168.0.32 /a 1 => 0.0.0.0,]
[/tmp/test]
We can simplify this further
$ args '/0 => '192.168.0.32' /a 1 => '0.0.0.0','
[/0 => 192.168.0.32 /a 1 => 0.0.0.0,]
and replacing the complicated argument with a much simpler one
$ args 'foo'1'bar'
[foo1bar]
Notice that the three strings 'foo', 1 and bar are concatenated to the
single world foo1bar. And now you can ask a simpler question:
How can I add a single quote to the string 'foo'1'bar'? And the answer is:
$ args 'foo'\'1\''bar'
[foo'1'bar]
Note though that "foo'1'bar" does not work in your case since you already used the double quotes for the outer ssh command.
Could you try the following command (replace the username, hostname accordingly to your needs):
ssh toto#localhost "sed '/0 => \x27192.168.0.32\x27/a 1 => \x27$old\x27,' /tmp/test"
output:
<?php
$CONFIG = array (
'trusted_domains' =>
array (
0 => '192.168.0.32',
1 => '1.1.1.1',
),
'dbtype' => 'mysql',
'dbport' => '',
'dbtableprefix' => 'oc_',
'logtimezone' => 'UTC',
'installed' => true,
'redis' =>
array (
'host' => '192.168.0.13',
'port' => 9095,
),
'mail_smtpmode' => 'sendmail',
'mail_from_address' => 'noreply',
'knowledgebaseenabled' => false,
0 => 18,
'loglevel' => 1,
'maintenance' => false,
);
If this works, just add -i options if you are really sure about what you are doing. you can also do the -i.bak to force sed to take a back up of your files
Getting this error :
[error] 1118#1118: *366 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught exception 'Predis\Response\ServerException' with message 'MOVED 7369 10.0.213.16:6379'
My Redis connection code is:
$parameters = array(
"scheme" => "tcp",
"host" => "testingredis.akf46e.clustercfg.use1.cache.amazonaws.com",
"port" => 6379,
"database" => 0,
);
$db = new Predis\Client($parameters, $options);
Note: The above code is working fine in local but not working in my AWS server. Any help would be appreciated.
After lots of research successfully completed the redis cluster with the AWS elasticache.
$options = array('cluster' => 'redis');
$parameters = array(
'clusters' => array(
'default' => array(
'scheme' => 'tcp',
'host' => HOST_URL,
'port' => 6379,
'database' => 0
),
),
);
$db = new Predis\Client($parameters,$options);
Were struggling with same. this is short version of what works:
$redis = new Predis\Client(
['tcp://127.0.0.1:6379'],
['cluster' => 'redis']
);
Following code works well in PHP 5.6.
require_once '../aws/aws-autoloader.php';
$config = [
'region' => 'ap-south-1',
'version' => 'latest',
'credentials' => [
'key' => '...',
'secret' => '...'
]
];
$sdk = new Aws\Sdk($config);
$client = $sdk->createS3();
But on PHP 7, it through error:
Fatal error: Uncaught TypeError: Argument 1 passed to Aws\Common\Client\AbstractClient::__construct() must be an instance of Aws\Common\Credentials\CredentialsInterface, array given, called in /var/www/html/webservice/vendor/aws3/Aws/Sdk.php on line 316 and defined in /var/www/html/aws-sdk/vendor/aws/aws-sdk-php/src/Aws/Common/Client/AbstractClient.php:75 Stack trace: #0 /var/www/html/webservice/vendor/aws3/Aws/Sdk.php(316): Aws\Common\Client\AbstractClient->__construct(Array) #1 /var/www/html/webservice/vendor/aws3/Aws/Sdk.php(291): Aws\Sdk->createClient('S3', Array) #2 index.php(14): Aws\Sdk->__call('createS3', Array) thrown in /var/www/html/aws-sdk/vendor/aws/aws-sdk-php/src/Aws/Common/Client/AbstractClient.php on line 75
Please suggest me how can I make it work on PHP 7.
Thanks.
UPDATE: I have both AWS SDK version 2 & 3 in my project. this might be a issue of conflict. Then how to solve the conflict?
This problem doesn't have any issue with PHP 7.0.
It's the case of conflict SDK ver 2 & 3.
This two sdk can't be used together. so I had to upgrade to sdk 3.
I'm using logstash 2.3.4 and Amazon Elasticsearch Service (2.3) .
My config
input {
jdbc {
# Postgres jdbc connection string to our database, mydb
jdbc_connection_string => "jdbc:mysql://awsmigration.XXXXXXXX.ap-southeast-1.rds.amazonaws.com:3306/table_receipt?zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false"
# The user we wish to execute our statement as
jdbc_user => "XXXXXXXX"
jdbc_password => "XXXXXXXX"
# The path to our downloaded jdbc driver
jdbc_driver_library => "/opt/logstash/drivers/mysql-connector-java-5.1.39/mysql-connector-java-5.1.39-bin.jar"
# The name of the driver class for Postgresql
jdbc_driver_class => "com.mysql.jdbc.Driver"
# our query
statement => "SELECT * from Receipt"
jdbc_paging_enabled => true
jdbc_page_size => 200
}
}
output {
#stdout { codec => json_lines }
amazon_es {
hosts => ["search-XXXXXXXX.ap-southeast-1.es.amazonaws.com"]
region => "ap-southeast-1"
index => "slurp_receipt"
document_type => "Receipt"
document_id => "%{uid}"
}
}
After running a command
bin/logstash agent -f db.conf
I got this error :
Attempted to send a bulk request to Elasticsearch configured at '["https://search-XXXXXXXX.ap-southeast-1.es.amazonaws.com:443"]', but an error occurred and it failed! Are you sure you can reach elasticsearch from this machine using the configuration provided? {:client_config=>{:hosts=>["https://search-slurp-wjgudsrlz66esh6hyrijaagamu.ap-southeast-1.es.amazonaws.com:443"], :region=>"ap-southeast-1", :aws_access_key_id=>nil, :aws_secret_access_key=>nil, :transport_options=>{:request=>{:open_timeout=>0, :timeout=>60}, :proxy=>nil}, :transport_class=>Elasticsearch::Transport::Transport::HTTP::AWS, :logger=>nil, :tracer=>nil, :reload_connections=>false, :retry_on_failure=>false, :reload_on_failure=>false, :randomize_hosts=>false, :http=>{:scheme=>"https", :user=>nil, :password=>nil, :port=>443}}, :error_message=>"undefined method `credentials' for nil:NilClass", :error_class=>"NoMethodError", :backtrace=>["/opt/logstash/vendor/bundle/jruby/1.9/gems/aws-sdk-core-2.1.36/lib/aws-sdk-core/signers/v4.rb:24:in `initialize'", "/opt/logstash/vendor/local_gems/b0f0ff24/logstash-output-amazon_es-1.0-java/lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb:36:in `signer'", "/opt/logstash/vendor/local_gems/b0f0ff24/logstash-output-amazon_es-1.0-java/lib/logstash/outputs/amazon_es/aws_v4_signer_impl.rb:48:in `call'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/faraday-0.9.2/lib/faraday/rack_builder.rb:139:in `build_response'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/faraday-0.9.2/lib/faraday/connection.rb:377:in `run_request'", "/opt/logstash/vendor/local_gems/b0f0ff24/logstash-output-amazon_es-1.0-java/lib/logstash/outputs/amazon_es/aws_transport.rb:49:in `perform_request'", "org/jruby/RubyProc.java:281:in `call'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/elasticsearch-transport-1.0.18/lib/elasticsearch/transport/transport/base.rb:257:in `perform_request'", "/opt/logstash/vendor/local_gems/b0f0ff24/logstash-output-amazon_es-1.0-java/lib/logstash/outputs/amazon_es/aws_transport.rb:45:in `perform_request'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/elasticsearch-transport-1.0.18/lib/elasticsearch/transport/client.rb:128:in `perform_request'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/elasticsearch-api-1.0.18/lib/elasticsearch/api/actions/bulk.rb:90:in `bulk'", "/opt/logstash/vendor/local_gems/b0f0ff24/logstash-output-amazon_es-1.0-java/lib/logstash/outputs/amazon_es/http_client.rb:53:in `bulk'", "/opt/logstash/vendor/local_gems/b0f0ff24/logstash-output-amazon_es-1.0-java/lib/logstash/outputs/amazon_es.rb:321:in `submit'", "org/jruby/ext/thread/Mutex.java:149:in `synchronize'", "/opt/logstash/vendor/local_gems/b0f0ff24/logstash-output-amazon_es-1.0-java/lib/logstash/outputs/amazon_es.rb:318:in `submit'", "/opt/logstash/vendor/local_gems/b0f0ff24/logstash-output-amazon_es-1.0-java/lib/logstash/outputs/amazon_es.rb:351:in `flush'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/stud-0.0.22/lib/stud/buffer.rb:219:in `buffer_flush'", "org/jruby/RubyHash.java:1342:in `each'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/stud-0.0.22/lib/stud/buffer.rb:216:in `buffer_flush'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/stud-0.0.22/lib/stud/buffer.rb:159:in `buffer_receive'", "/opt/logstash/vendor/local_gems/b0f0ff24/logstash-output-amazon_es-1.0-java/lib/logstash/outputs/amazon_es.rb:311:in `receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/outputs/base.rb:83:in `multi_receive'", "org/jruby/RubyArray.java:1613:in `each'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/outputs/base.rb:83:in `multi_receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/output_delegator.rb:130:in `worker_multi_receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/output_delegator.rb:114:in `multi_receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:301:in `output_batch'", "org/jruby/RubyHash.java:1342:in `each'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:301:in `output_batch'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:232:in `worker_loop'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:201:in `start_workers'"], :level=>:error}
May i know how to solve this problems?
thank you
I'm trying to run C++ binaries as FastCGI in Lighttpd, but it won't start. I tried something like this:
fastcgi.server += (".cpp" =>
( "localhost" =>
(
"socket" => "/tmp/mysocket",
"bin-path" => "/var/www/index.cpp",
"max-procs" => 1
))
)
But I can't get it working. I want to keep the C++ in memory for starting really fast.
You should adapt your configuration to something like this:
fastcgi.server = (
"/api" => (
"api.fastcgi.handler" => (
"socket" => "/var/run/lighttpd/lighttpd-fastcgi-test-" + PID + ".socket",,
"check-local" => "disable",
"bin-path" => "/var/www/localhost/cgi-bin/test.fcgi",
"max-procs" => 30,
)
)
)
For all requests: localhost/api/some_test lighttp will call your fcgi executable /var/www/localhost/cgi-bin/test.fcgi