Running C++ as FastCGI in Lighttpd - c++

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

Related

AWS PHP 7 Session got reset in every reset in

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

Adding single quotes into a sed command and also in a ssh command

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

Uncaught exception 'Predis\Response\ServerException' with message 'MOVED 7369

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']
);

Doctrine migrations not using specified configuration

I have been using Doctrine and Migrations in my ZF2 project for a few weeks without issue. I have been executing migrations by specifying my own configuration file:
vendor/bin/doctrine-module migrations:diff --configuration=/path/to/migrations-config.xml
I recently brought in Codeception into my project via composer and when I recently went to execute a new migration (with the same above command), I received the following error:
[InvalidArgumentException]
Migrations directory data/DoctrineORMModule/Migrations does not exist
This is not the directory I have specified in my configuration file. At first I thought Doctrine Migrations was completely ignoring my --configuration argument. When I traced it through, I saw that Doctrine Migrations wasn't using my --configuration argument because it had already loaded a config file.
Would anyone know where this config file may be pulling in from? I can work around the issue for the time being by commenting out the conditional in AbstractCommand getMigrationConfiguration(), but long term I'd rather not have to rely on this. I'll also try and remove codeception and see if that has any impact. Any help is appreciated.
As it turns out, I was able to move Doctrine migrations configuration into my ZF2 module config. In my module.config.php, I have the following specified (Api is the module name):
'doctrine' => array(
'driver' => array(
'application_entities' => array(
'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/Api/Entity')
),
'orm_default' => array(
'drivers' => array(
'Api\Entity' => 'application_entities'
)
)
),
'migrations_configuration' => array(
'orm_default' => array(
'directory' => 'data/migrations',
'namespace' => 'My\Namespace\Migrations',
'table' => 'migrations',
),
),
),
This allows me to run Doctrine migrations commands without having to specify a configuration file, for example:
vendor/bin/doctrine-module migrations:diff
I see an alternative in using a stand-alone doctrine-migration.phar command:
php doctrine-migrations.phar migrations:migrate --configuration=config.xml --db-configuration=db-config.xml
To make this work, you need to download doctrine-migrations.phar from here: https://github.com/doctrine/migrations

lighttpd + mod_fastcgi + django

I am having trouble deploying my django app to a server that uses lighttpd (on which I'm root.)
Here's my lighttpd.conf:
server.modules = (
# "mod_access",
# "mod_alias",
# "mod_compress",
# "mod_redirect",
"mod_status",
#"mod_rewrite",
# "mod_fastcgi",
# "mod_accesslog",
)
status.status-url = "/server-status"
status.config-url = "/server-config"
$HTTP["host"] == "myurl.com" {
server.document-root = "/var/www/myurl"
server.errorlog = "/var/log/lighttpd/myurl/error.log"
accesslog.filename = "var/log/lighttpd/nixcraft/access.log"
server.error-handler-404 = "/e404.html"
fastcgi.server = (
"/myurl/nonorientable.fcgi" => (
"main" => (
# Use host / port instead of socket for TCP fastcgi
# "host" => "127.0.0.1",
# "port" => 3033,
"socket" => "/tmp/myurl.sock",
"check-local" => "disable",
)
),
)
}
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm")
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl"
dir-listing.encoding = "utf-8"
server.dir-listing = "enable"
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/x-javascript", "text/css", "text/html", "text/plain" )
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
server.modules += ( "mod_auth" )
auth.debug = 2
auth.backend = "plain"
auth.backend.plain.userfile = "/etc/lighttpd/.lighttpdpassword"
auth.require = ( "/" =>
("method" => "basic",
"realm" => "",
"require" => "user=john"))
And then I ran this on my server (from the folder /var/www/myurl):
sudo python manage.py runfcgi daemonize=false socket=/tmp/myurl.sock maxrequests=1
At this point, when I try to load myurl.com, all I get is the directory listing: my django app is not executed. I thought that the problem was that mod_fastcgi is commented in my conf, it actually appears on myurl.com/server-config. If I uncomment it, lighttpd complains that I'm trying to load the same module twice and exits, so my guess is that it is imported by default.
I'm using django1.4 (latest stable) and lighttpd 1.4.28 on ubuntu 12.04, and I'm pretty stuck. I followed the official doc (https://docs.djangoproject.com/en/1.4/howto/deployment/fastcgi/)
It looks like your missing the rewrite directive given in the docs:
url.rewrite-once = (
"^(/media.*)$" => "$1",
"^/favicon\.ico$" => "/media/favicon.ico",
"^(/.*)$" => "/mysite.fcgi$1",
)
Update: You need to change the fastcgi.server section from /myurl/nonorientable.fcgi to /mysite.fcgi so that it matches the rewrite above.