msgbartop
Blog di Dino Ciuffetti (Bernardino in realtà)
msgbarbottom

03 Set 12 apache2 + mod_fastcgi + php 5.3 + PHP-FPM

This is a very quick guide to get your feet wet with PHP 5.3 + PHP-FPM fastcgi support and apache webserver.
The PHP-FPM is basically a fastcgi compliant pool of PHP processes spawned on the system, ready to quickly accept connections, for example via TCP. It’s generally used to greatly improove PHP scalability, security and performance.

Start by installing apache, no matter if it’s a binary installation or if it’s compiled from source code (I assume this step is already done).

Once you have a valid apache installation, you need to compile the mod_fastcgi module.
NOTE: don’t use mod_fcgid or any other fastcgi provider but mod_fastcgi: it’s proved to be stable and to work well with PHP-FPM.

To install mod_fastcgi you have to:

  1. download mod_fastcgi: http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
  2. untar the package, then compile the apache module with: /your_apache_path/bin/apxs -o mod_fastcgi.so -c *.c
  3. install the module with: /your_apache_path/bin/apxs -i -a -n fastcgi .libs/mod_fastcgi.so

Now, compile PHP with the fpm support, or install a already compiled PHP binary package.

Here I’ll cover how to compile it from source.

Start by downloading the latest php 5.3 version from http://www.php.net/downloads.php

When you have done, untar the PHP source package and enter into the extracted php-5.3.x directory.
Now create a file called conf.sh and put this stuff inside it:

./configure  \
–prefix=/usr/local/php53 \
–with-libdir=lib64 \
–enable-pcntl \
–enable-mbstring=shared \
–enable-mbregex \
–with-gd=shared \
–enable-bcmath=shared \
–with-xmlrpc=shared \
–with-mysql=shared,/usr \
–with-mysqli=shared,/usr/bin/mysql_config \
–enable-dom=shared \
–enable-soap=shared \
–with-xsl=shared,/usr \
–enable-xmlreader=shared –enable-xmlwriter=shared \
–with-pdo-mysql=shared,/usr \
–enable-json=shared \
–enable-zip=shared \
–with-readline \
–with-jpeg-dir=/usr \
–with-png-dir=/usr \
–with-pear \
–with-ldap=shared \
–enable-fpm \
–with-fpm-user=apache \
–with-fpm-group=apache

Your mileage may vary here, so please double check row by row if you need to modify something. The FPM part are the last 3 lines.

NOTE: you cannot compile PHP as FPM and SAPI at the same time.

Now, make the file executable with: chmod 755 conf.sh
and run the executable with: ./conf.sh

Wait that the configure script is done. If no errors are encountered you can proceed with make and make install as usual.
Remember to create the php.ini configuration file if you need it.
You should now end up with a fresh PHP installation into /usr/local/php53 (or any other path you given to the prefix configure attribute).

Ok, now it’s time to configure the php-fpm (change /usr/local/php53 with your path if it’s different):

cd /usr/local/php53/etc
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf

You generally don’t need to modify anything here, but if you want you can touch something.
Now start the php-fpm process pool by running this command by the root user: /usr/local/php53/sbin/php-fpm

If anything gone ok you should have some process up and running, something like this:

25976 ?        Ss     0:00 php-fpm: master process (/usr/local/php53/etc/php-fpm.conf)
4945 ?        S      0:00  \_ php-fpm: pool www
4946 ?        S      0:00  \_ php-fpm: pool www
4947 ?        S      0:00  \_ php-fpm: pool www

If you didn’t modify the php-fpm.conf, the process pool listen for fastcgi requests to TCP 127.0.0.1:9000.

It’s time to configure a apache virtualhost with PHP support using this brand new fpm.

Edit the httpd.conf apache configuration file (or another included file where you store the virtualhost) and append this stuff (I assume that apache is installed into /opt/apache2):

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot “/opt/apache2/htdocs”
ServerName “your_servername.com”
ErrorLog “logs/your_servername-error_log”
CustomLog “logs/your_servername-access_log” common

FastCgiExternalServer /opt/apache2/htdocs/php5.sock -host 127.0.0.1:9000
AddHandler php5-fcgi .php
Action php5-fcgi /tmp/php5.sock
Alias /tmp /opt/apache2/htdocs

<Directory “/opt/apache2/htdocs”>
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>

Any file whose name ends for “.php” into your document root should now be associated to the PHP fastcgi handler and the requests should be routed to the php-fpm process pool. Each php-fpm process is reused according to the php-fpm.conf configuration file.

Restart apache and enjoy (any comment are welcome).

18 Mag 12 The OrientDB 1.0 stable is finally there!

Congratulation to Luca Garulli and his dev team to the public release of OrientDB 1.0 Stable!
After a year of release candidates and bug fixing it’s finally time to the stable version.
Many may bugs fixed, new indexing algorithms, improved clustering with multi master replication, new Object Database interface with lazy object loading, new studio (web interface) and much more.

The community is growing fast and people get rapidly moving to new technologies.
Words like nosql, object and graph databases, cloud and mobile are big buzzwords of nowadays.

If you didn’t already, subscribe to the orientdb mailinglist to get in touch: http://groups.google.com/group/orient-database?pli=1.

20 Apr 12 Avaaz urgent petitions to sign NOW and quickly!

Urgent Online Petitions to sign now and quicky!! Please wide spread!!

https://secure.avaaz.org/it/monti_save_our_internet/

In qualità di cittadini preoccupati, le chiediamo di fermare immediatamente tutte le iniziative del governo volte a dare all’Autorità per le Garanzie nelle Comunicazioni (AGCOM) il potere di censurare siti internet senza mandato del giudice. Le chiediamo inoltre di riaffermare pubblicamente che solo il Parlamento può approvare leggi che incidono sui nostri diritti fondamentali, inclusa la libertà di espressione, come affermato dalla Costituzione. Ci affidiamo a lei per proteggere la libertà di Internet in quanto pilastro fondamentale della nostra democrazia.

https://secure.avaaz.org/en/stop_cispa/

As concerned global citizens, we urge you to immediately drop the Cyber Intelligence Sharing and Protection Act (CISPA). Our democracy and civil liberties are under threat from the excessive and unnecessary Internet surveillance powers it grants. The Internet is a crucial tool for people around the world to exchange ideas and work collectively to build the world we all want. We urge you to show true global leadership and do all you can to protect our Internet freedom.

08 Mar 12 How to execute a HTTP/Rest Query to NuvolaBase distributed database with PHP

As previously said, nuvolabase.com is a great service that permits you to have a distributed nosql document database in the cloud. This is very cool: think each time you would had the need of a database always available in the cloud that you would access via simple HTTP/Rest queries. The possibilities are endless.

Here is a very simple but powerful PHP curl agent to submit commands (queries) to nuvolabase via HTTP.

<?php
/*
* Author: Dino Ciuffetti <dino@tuxweb.it>
* Object: Execute a remote query to a distributed database on nuvolabase.com (free account) using HTTP (OrientDB REST API)
*/

/* user configurable parameters */
$nuvolabasedb = ‘db$free$youruser$yourdb’;
$command = ‘select from yourclass’;
$user = ‘admin’;
$password = ‘qwerty’;
$useragent = “NuvolaBase PHP REST agent/v0.8 (compatible; Mozilla 4.0; MSIE 5.5; http://www.nuvolabase.com/)”;
/* END of user configurable parameters */

$nuvolabasehost = ‘studio.nuvolabase.com’;
$url = ‘http://’.$user.’:’.$password.’@’.’studio.nuvolabase.com/command/’.$nuvolabasedb.’/sql/’;

$ch = curl_init();

// set user agent
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

// return the result or false in case of errors
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// set the target url
curl_setopt($ch, CURLOPT_URL, $url);

// do basic login authentication
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

// howmany parameter to post
curl_setopt($ch, CURLOPT_POST, 1);

// the post data to send
curl_setopt($ch, CURLOPT_POSTFIELDS, $command);

// execute curl,fetch the result and close curl connection
$res = curl_exec ($ch);
curl_close ($ch);

// display result
if ($res !== FALSE);
print_r (json_decode($res));

?>

Please use the attached file.

test.php

02 Feb 12 NuvolaBase: the new no-sql company behind OrientDB launches the Graph Database in the Cloud

London, UK – NuvolaBase Ltd is a London-based startup that is about to revolutionize the database market. Only two years ago this market was dominated by few big players such as Oracle, IBM and Microsoft. Something, in the last 24 months, has changed thanks to the “NoSQL” movement which focused on alternative solutions to the ordinary Relational DBMS’s due to the pressing and increasing demands for better performance and higher scalability.

Today the largest IT companies avail themselves of NoSQL solutions to manage Mission Critical projects. Google, Amazon, Microsoft, Facebook, Twitter, Disney, MTV, Craiglist and FourSquare are amongst the most famous ones.

After just a year of testing, NuvolaBase comes out of Alpha version, offering a NoSQL database of high performance as a cloud-based service. This way the database is no longer a software component that needs installing, configuring and maintaining, but it becomes a distributed service that is always available on the internet.

Web Site: http://www.nuvolabase.com
Follow us on Twitter: https://twitter.com/#!/nuvolabase
LinkedIn: http://www.linkedin.com/company/nuvolabase-ltd

26 Gen 12 liborient, OrientDB C library migrated to github

I never said before on those pages that some months ago I migrated liborient to github: liborient project page.

For those who do not know liborient, it’s a LGPLv3 library that can be used by C programs to interact with the OrientDB DBMS Server using the orientdb binary protocol. At the time of this writing it’s in development stage, but almost all low level binary protocol methods are implemented and should be quite working.

After fixing some (well known) memory leaks on the new odocument interface, I’m now working on a high level API that can be used by C programs to manipulate objects going to and coming from OrientDB Server.
You can, for example, put or get records to/from the server containing different data type fields. Those fields are organized into an object that OrientDB calls Document. This Document can include structured types like: integers, shorts, dates, strings, binary, char, float, collections, maps, documents embedded into documents, and more.
The liborient’s new odocument higher level API should make you comfortable to access and manipulate this documents.
This can be, for example, a good starting point to create native bindings for other languages like PHP, python, perl, ruby, etc.

At the moment I am the author and the only developer on this project, but if you are brave you can join and submit patches, test the code, open bugs, put your considerations, and so on. Feel free to send me a mail, add a comment to this page, write to the orientdb mailing list, send me a tweet at @tuxweb, or anything else.

06 Ott 11 Legge anti bavaglio – Firma la petizione online

Avaaz: “Vi invitiamo a votare contro l’approvazione del DDL Alfano e, quindi, salvaguardare i principi fondamentali stabiliti dalla nostra Costituzione, inclusa la libertà di informazione e il nostro diritto ad essere informati.”

Io credo che tutti debbano firmare. Se volete, potete farlo cliccando qui sotto:
http://www.avaaz.org/en/no_bavaglio_2/?wIJMBbb

15 Set 11 How to compile apache httpd 64 bits on Solaris 10 sparc

As usual we try to consider the “do it right (r)” way of doing configurations.
Today we will compile Apache HTTPD on Sun Solaris 10 OS (SPARC).

The first thing to do is to install the gcc c compiler if it is not already installed.
To do so, download and install the package from www.sunfreeware.com. Double read the package release notes.
You have to download the latest gcc package and its dependencies. You probably will need also libiconv and libintl.
Now download openssl-0-9.X package.

For each downloaded package install it with the command: dpkg -d <full_path>/your_package

When finished, go into your apache source directory and:

export LD_LIBRARY_PATH=/usr/sfw/lib/sparcv9:/usr/local/lib/sparcv9
export PATH=/usr/sfw/bin:/usr/ccs/bin:/usr/local/ccs/bin:/usr/local/bin:$PATH

# if you want it 64 bits:
export CFLAGS=”-m64″
# if you want it 32 bits:
# export CFLAGS=”-m32″
export LDFLAGS=”-L/usr/sfw/lib/sparcv9″

./configure –with-included-apr –with-expat=builtin –prefix=<your_installation_path> –enable-mods-shared=most –enable-ssl –with-ssl=/usr/sfw –enable-proxy –enable-proxy-connect –enable-proxy-http –enable-proxy-balancer

If the configure process terminated successfully, you can now call:

make

When finished, as usual, call:

make install

I recommend you to use gnu make. You can download it from sunfreeware.
Now, if everything gone ok, you can try to start your brand new 64 bits apache full of powerfull modules.
You may want to set your LD_LIBRARY_PATH variable into <apache>/bin/envvars file so that apachectl can find all the library it needs to start or stop the server.

Ciao, Dino.

04 Lug 11 How to use Huge Pages with Java and Linux

Hi.
Today we get how to use Huge Pages with Java from a Linux powered system.
While a Linux system generally splits memory segments into pages of 4 kb, Huge Pages are memory pages large 2Mb or more.
This is proved to increment speed when the application make use of large quantity of ram, like Java with a large heap (2 GB or more).
It’s correct to say that this is not always the correct configuration choice because the memory setted to be dedicated to Huge Pages cannot be accessed by the kernel (buffer cache) or by the applications, so that memory is subtracted from the virtual memory pool of the system. Since it’s very fast to make it a try and decide if use it or not, let me play with it.

Here in this example we will set 2,5 GB of RAM to be used as Huge Pages. Your mileage may vary.
HPM (huge page memory) is expressed in GB.

First: set the quantity of memory (bytes) to be defined as a shared memory segment
This is quickly found calculating this simple formula: ((HPM * 1024 * 1024 * 1024) – 1).
In our example: ((2,5 * 1024 * 1024 *1024) – 1) = 2684354559
Set it up online with this command:
echo 2684354559 > /proc/sys/kernel/shmmax
If you want to set it permanent at the next system reboot, append those two lines to your /etc/sysctl.conf file:
# Shared memory – max segment size: 2,5 Gb (-1 b)
kernel.shmmax = 2684354559

Second: set the number of reserved large memory pages
This is the number of reserved pages. Each page is large 2 Mb, so finding the number of pages to reserve is simple:
((HPM * 1024) / 2). In our example: ((2,5 * 1024) / 2) = 1280
Set it up online with this command:
echo 1280 > /proc/sys/vm/nr_hugepages
If you want to set it permanent at the next system reboot, append those two lines to your /etc/sysctl.conf file:
# Enable kernel to reserve 2,5GB / 2Mb large pages
vm.nr_hugepages = 1280

Third: set the system group id enabled to use huge pages
Java programs usually should not be fired by the root user. In my case, the group id of my program is “1001”.
Set it up online with this command:
echo 1001 > /proc/sys/vm/hugetlb_shm_group
If you want to set it permanent at the next system reboot, append those two lines to your /etc/sysctl.conf file:
# System group id that can use huge pages (hugepages gid: 1001)
vm.hugetlb_shm_group = 1001

Fourth: run the java program with the Huge Page support
In our example we are using the JVM distributed by Oracle. Other Java vendors may use different parameters to enable Huge Pages. They can even call Huge Pages differently.
The program can now be fired with “-XX:+UseLargePages -XX:LargePageSizeInBytes=2m”
My complete java parameters for my java program are:
java -d64 -server -Xms1900m -Xmx1900m -Xss192k -XX:+UseLargePages -XX:LargePageSizeInBytes=2m -XX:+UseParNewGC

Ciao ciao.
Dino Ciuffetti.