A new uWSGI PHP plugin is available

Hi everyone,

uWSGI has got a new php plugin, allowing you to run php apps at full
speed
(read: not in CGI mode) and getting all of the uWSGI features (like
adaptive process spawning and jailing technics).

In addition to this a bunch of uwsgi api functions has been added,
allowing your php apps to interact with other apps hosted in uWSGI.

http://projects.unbit.it/uwsgi/wiki/PHP

The build system on redhat-based distros (fedora, centos…) is very
easy,
but for debian/ubuntu you need to rebuild php or use some ppa as debian
(still) does not include the libphp.

In my company, we are using this plugin proxied behind nginx from about
2
weeks without problems. Every report will be wellcomed.

Please, do not ask me to compare it with php-fpm as i have never used it
at a level allowing me to make a fair analysis :frowning:


Roberto De Ioris
http://unbit.it

On 2012-02-24 16:23, Roberto De Ioris wrote:

In my company, we are using this plugin proxied behind nginx from about 2
weeks without problems. Every report will be wellcomed.

Segfaulted on my server.

!!! uWSGI process 31078 got Segmentation Fault !!!
*** backtrace of 31078 ***
./uwsgi(uwsgi_backtrace+0x2a) [0x80779ea]
./uwsgi(uwsgi_segfault+0x2c) [0x8077adc]
[0x865420]
./uwsgi(wsgi_req_recv+0x7b) [0x805640b]
./uwsgi(simple_loop+0x136) [0x8070dc6]
./uwsgi(uwsgi_ignition+0x196) [0x8074c16]
./uwsgi(uwsgi_start+0x2526) [0x80771a6]
./uwsgi(main+0x1584) [0x807a654]
/lib/libc.so.6(__libc_start_main+0xdc) [0xabceac]
./uwsgi [0x8054a91]
*** end of backtrace ***
DAMN ! worker 3 (pid: 31078) died :frowning: trying respawn …
Respawned uWSGI worker 3 (new pid: 31083)

Running:

  • CentOS 5.7
  • PHP 5.3 from IUSCommunity repository (http://iuscommunity.org)
  • nginx 1.1.15 (self-compiled)
  • Python 2.4

On 2012-02-24 17:46, Roberto De Ioris wrote:

Be sure to fully rebuild (do a make clean) uWSGI if you have added
devel packages during php_plugin compilation as they can modify CFLAGS
setup

Thank you, it’s working fine now. The DOCUMENT_ROOT (or something else)
doesn’t seem to be passed properly though? I get “Not Found” (uwsgi’s?)
unless I start uwsgi with --php-docroot parameter. I’m following “Run
php apps with nginx as frontend” chapter of the wiki.

./uwsgi(uwsgi_backtrace+0x2a) [0x80779ea]
DAMN ! worker 3 (pid: 31078) died :frowning: trying respawn …
Respawned uWSGI worker 3 (new pid: 31083)

Running:

  • CentOS 5.7
  • PHP 5.3 from IUSCommunity repository (http://iuscommunity.org)
  • nginx 1.1.15 (self-compiled)
  • Python 2.4

Be sure to fully rebuild (do a make clean) uWSGI if you have added devel
packages during php_plugin compilation as they can modify CFLAGS setup


Roberto De Ioris
http://unbit.it

I tried building this on my Ubuntu 11.10 server with nginx-1.0.12

./configure
–prefix=/opt/nginx
–conf-path=/etc/nginx/nginx.conf
–pid-path=/var/run/nginx.pid
–lock-path=/var/lock/nginx.lock
–http-log-path=/var/log/nginx/access.log
–error-log-path=/var/log/nginx/error.log
–http-client-body-temp-path=/var/lib/nginx/body
–http-proxy-temp-path=/var/lib/nginx/proxy
–http-fastcgi-temp-path=/var/lib/nginx/fastcgi
–http-uwsgi-temp-path=/var/lib/nginx/uwsgi
–http-scgi-temp-path=/var/lib/nginx/scgi
–with-http_stub_status_module
–with-http_ssl_module
–with-http_gzip_static_module
–add-module=/root/sources/uwsgi-1.1-snapshot5/nginx/
–user=www-data
–group=www-data
–without-mail_pop3_module
–without-mail_imap_module
–without-mail_smtp_module

but I keep getting this error:

objs/addon/nginx/ngx_http_uwsgi_module.o:(.data+0x0): multiple
definition of ngx_http_uwsgi_module' objs/src/http/modules/ngx_http_uwsgi_module.o:(.data+0x0): first defined here collect2: ld returned 1 exit status make[1]: *** [objs/nginx] Error 1 make[1]: Leaving directory/root/sources/nginx-1.0.12’
make: *** [build] Error 2

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,222924,222930#msg-222930

you are right, there is a missing variable assignment for docroot, i
have
released a new snapshot (snapshot5) or you can use the latest tip.

Obviously i suggest you to always list allowed docroots in uWSGI for
increasing security.


Roberto De Ioris
http://unbit.it

Thanks for the promp reply, I wasn’t aware it’s already been included.

Look forward to testing it out.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,222924,222932#msg-222932

I’m a bit stuck with ‘running the php script in the uWSGI server’

My PHP is built from source, as far as I understand I need to build it
with --enable-embed

./configure --prefix=/opt/php5 --with-config-file-path=/opt/php5/etc
–with-config-file-scan-dir=/opt/php5/etc/conf.d --with-curl
–with-mhash --enable-cgi --with-pear --with-gd --with-jpeg-dir
–with-png-dir --with-zlib --with-xpm-dir --with-freetype-dir
–with-t1lib --with-mcrypt --with-mhash --with-mysql=mysqlnd
–with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl
–with-xmlrpc --with-xsl --with-bz2 --with-gettext
–with-fpm-user=www-data --with-fpm-group=www-data --disable-debug
–enable-fpm --enable-exif --enable-wddx --enable-zip --enable-bcmath
–enable-calendar --enable-ftp --enable-embed --enable-mbstring
–enable-soap --enable-sockets --enable-shmop --enable-dba
–enable-inline-optimization --enable-sysvsem --enable-sysvshm
–enable-sysvmsg

How would I then proceed to build the uWSGI php plugin?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,222924,222936#msg-222936

–http-proxy-temp-path=/var/lib/nginx/proxy
–without-mail_imap_module
make[1]: Leaving directory `/root/sources/nginx-1.0.12’
make: *** [build] Error 2

It looks like you have added the uwsgi patch to nginx, while nginx does
not require it starting from 0.8.40 (it is included in the official
distribution)


Roberto De Ioris
http://unbit.it

–with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl
–with-xmlrpc --with-xsl --with-bz2 --with-gettext
–with-fpm-user=www-data --with-fpm-group=www-data --disable-debug
–enable-fpm --enable-exif --enable-wddx --enable-zip --enable-bcmath
–enable-calendar --enable-ftp --enable-embed --enable-mbstring
–enable-soap --enable-sockets --enable-shmop --enable-dba
–enable-inline-optimization --enable-sysvsem --enable-sysvshm
–enable-sysvmsg

How would I then proceed to build the uWSGI php plugin?

download 1.1 uWSGI sources:

http://projects.unbit.it/downloads/uwsgi-1.1-snapshot5.tar.gz

uncompress and move to the resulting directory and run

make

if all goes well you will end with a binary named ‘uwsgi’

then build the php plugin with

python uwsgiconfig.py --plugin plugins/php

finally run (always from the same dir)

./uwsgi -s :3031 --plugins php

now point nginx to that port as described here:

http://projects.unbit.it/uwsgi/wiki/PHP


Roberto De Ioris
http://unbit.it

Please, do not ask me to compare it with php-fpm as i have never used it at a
level allowing me to make a fair analysis :frowning:

Would love to see some (even simple) benchmarks from someone who has
played around both (fpm and the uwsgi).

rr

Thanks for all the help so far Roberto.

When I run

python uwsgiconfig.py --plugin plugins/php
using profile: buildconf/default.ini
detected include path: [’/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include’,
‘/usr/local/include’,
‘/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include-fixed’,
‘/usr/include/x86_64-linux-gnu’, ‘/usr/include’]
*** uWSGI building and linking plugin plugins/php ***
[gcc -pthread] ./php_plugin.so
/usr/bin/ld: cannot find -lphp5
collect2: ld returned 1 exit status
*** unable to build php plugin ***

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,222924,222939#msg-222939

I’ve tried that, but same result:

LDFLAGS="-Lpath" LD_RUN_PATH="/opt/php5/lib/libphp5.so" python
uwsgiconfig.py --plugin plugins/php
using profile: buildconf/default.ini
detected include path: [’/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include’,
‘/usr/local/include’,
‘/usr/lib/gcc/x86_64-linux-gnu/4.6.1/include-fixed’,
‘/usr/include/x86_64-linux-gnu’, ‘/usr/include’]
*** uWSGI building and linking plugin plugins/php ***
[gcc -pthread] ./php_plugin.so
/usr/bin/ld: cannot find -lphp5
collect2: ld returned 1 exit status
*** unable to build php plugin ***

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,222924,222943#msg-222943

*** uWSGI building and linking plugin plugins/php ***
[gcc -pthread] ./php_plugin.so
/usr/bin/ld: cannot find -lphp5
collect2: ld returned 1 exit status
*** unable to build php plugin ***

Your php-config script is not exporting library dir. Use this trick:

LDFLAGS="-Lpath" LD_RUN_PATH=“path” python uwsgiconfig.py --plugin
plugins/php

where path is the directory containing libphp5.so


Roberto De Ioris
http://unbit.it

Thanks Robert - finally have it up and running.

Just did some quick testing and seeing 15% improvement in page load
times, we’ve previously been using php-fpm.

Looks very promising so far!

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,222924,222946#msg-222946

I’ve tried that, but same result:

LDFLAGS="-Lpath" LD_RUN_PATH="/opt/php5/lib/libphp5.so" python
uwsgiconfig.py --plugin plugins/php

it must be

LDFLAGS="-L/opt/php5/lib/" LD_RUN_PATH="/opt/php5/lib/"

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,222924,222943#msg-222943


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx


Roberto De Ioris
http://unbit.it

Roberto De Ioris wrote in post #1048644:

–with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl
–with-xmlrpc --with-xsl --with-bz2 --with-gettext
–with-fpm-user=www-data --with-fpm-group=www-data --disable-debug
–enable-fpm --enable-exif --enable-wddx --enable-zip --enable-bcmath
–enable-calendar --enable-ftp --enable-embed --enable-mbstring
–enable-soap --enable-sockets --enable-shmop --enable-dba
–enable-inline-optimization --enable-sysvsem --enable-sysvshm
–enable-sysvmsg

How would I then proceed to build the uWSGI php plugin?

download 1.1 uWSGI sources:

http://projects.unbit.it/downloads/uwsgi-1.1-snapshot5.tar.gz

uncompress and move to the resulting directory and run

make

if all goes well you will end with a binary named ‘uwsgi’

then build the php plugin with

python uwsgiconfig.py --plugin plugins/php

finally run (always from the same dir)

./uwsgi -s :3031 --plugins php

now point nginx to that port as described here:

http://projects.unbit.it/uwsgi/wiki/PHP


Roberto De Ioris
http://unbit.it

Hi, I follow the tutorial of http://projects.unbit.it/uwsgi/wiki/PHP

the server config in nginx is:

server {
listen 8080;
server_name www.myphp.com myphp.com;
location ~ .php {
root /var/www/php_test;
uwsgi_pass 127.0.0.1:3030;
include uwsgi_params;
}
}

Put a file name index.php in /var/www/php_test.

Than i run uwsgi -s :3030 --plugin php -M -p 4
the output is:

*** Starting uWSGI 1.1 (64bit) on [Sun Mar 18 17:57:32 2012] ***
compiled with version: 4.6.1 on 17 March 2012 17:44:26
current working directory: /home/delai/uwsgi
detected binary path: /usr/local/bin/uwsgi
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread mutexes
uwsgi socket 0 bound to TCP address :3030 fd 3
Python version: 2.7.2+ (default, Oct 4 2011, 20:41:12) [GCC 4.6.1]
Python main interpreter initialized at 0x6945a0
PHP 5.3.10 initialized
your server socket listen backlog is limited to 100 connections
*** Operational MODE: preforking ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 9385)
spawned uWSGI worker 1 (pid: 9386, cores: 1)
spawned uWSGI worker 2 (pid: 9387, cores: 1)
spawned uWSGI worker 3 (pid: 9388, cores: 1)
spawned uWSGI worker 4 (pid: 9389, cores: 1)
<<<

it looks fine.

when i visit http://myphp.com:8080/, nginx return 404 not found
visit http://myphp.com:8080/index.php, nginx return
“uWSGI Error
Python application not found”

php was recompiled and php plugin was configured.

Any one know Why?

How would I then proceed to build the uWSGI php plugin?
if all goes well you will end with a binary named ‘uwsgi’

server {
listen 8080;
server_name www.myphp.com myphp.com;
location ~ .php {
root /var/www/php_test;
uwsgi_pass 127.0.0.1:3030;
include uwsgi_params;
}
}

here you have missed

uwsgi_modifier1 14;

that instruct uWSGI to route the request to the php plugin.

About index.php you can add an index directive in nginx or

php-index = index.php

in uwsgi config


Roberto De Ioris
http://unbit.it

…and obviously disable request logging as uWSGI by default is really
verbose.
This is the command line of my test suite:

./uwsgi -s :3031 --plugins php --disable-logging -p 4 -M

this spawn 4 processes (as php-fpm default on debian/ubuntu).


Roberto De Ioris
http://unbit.it

Thank you very much.

Robert

There should be not much difference in both (or php-fastcgi), the only
thing that came to my mind is in different configuration.

Best way to test is in using both with a single process, or with the
same
number of processes (adaptive process spawning is completely different
from the php-fpm one so i would not expect a fair comparison). But
again,
do not expect too much differences, the internal php stuff is the same.


Roberto De Ioris
http://unbit.it

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs