Category: php

rss

Remote logging with rsyslog, php and agavi

When I tried to get rsyslog running with php I didn't face much problems. Anyways I want to share some things I noticed while getting it to work.

First of all ubuntu uses rsyslog already. Just a simple

1
# apt-get install rsyslog-mysql

and all syslog messages went directly into the database "syslog". Configure /etc/rsyslog.d/mysql.conf to insert this information into a remote machine.

Now let's get to php. You have the option to set:

1
error_log=syslog

This however does log all messages with

1
php: whatever the issue or error is

If you want to replace "php" with a custom message, you have to call

1
openlog('myapp', LOG_PID | LOG_ODELAY, LOG_USER);

before any error happens. Because LOG_ODELAY is given, it won't connect to syslog unless any error happens, so one should be save to put this call at the top of your dispatcher file.

The final log message will look like that (254 is the process id):

1
Sep 26 13:39:44 root-server myapp[254]: the issue or error

Finally I wanted to log all messages created by agavi's logging system. Since I didn't found an existing AgaviSyslogLoggerAppender, I wrote one and put it up on a github-gist.

Have fun logging!

In MyQuests, php, Agavi & Ubuntu By DracoBlue @ 13:55 26.09.2011

Installing php 5.3.5/5.3.6 on Ubuntu Maverick/Lucid

Latest Version for PHP 5.3 on Ubuntu is just PHP 5.3.3. This is not so good, if you want to have some of the plenty bugfixes which will be shipped with a later version.

If you want to upgrade to 5.3.5 (5.3.6 support may come later), you can use this inofficial ppa by the nginx user at launchpad: https://launchpad.net/~nginx/+archive/php5.

For ubuntu maverick just create a file:

1
$ gedit /etc/apt/sources.list.d/php5-ppa.list

with the contents

1
2
3
deb http://ppa.launchpad.net/nginx/php5/ubuntu maverick main
deb-src http://ppa.launchpad.net/nginx/php5/ubuntu maverick main

and run:

1
2
$ sudo apt-get update
$ sudo apt-get dist-upgrade

Now you have php-5.3.5 installed on your ubuntu box! Have fun.

In Linux, php & Ubuntu By DracoBlue @ 22:02 13.04.2011

PhpDebugToolbar 1.3.0 (for agavi) released

Today I am pleased to announce the new version 1.3.0 of the Agavi PHP DebugToolbar for download.

New features include full propel support (thanks tim), rows+time+memory display for the database queries and some small bugfixes.

The source can be found on github now http://github.com/DracoBlue/PhpDebugToolbar, feel free to fork it and send pull request with new features!

Download for PhpDebugToolbar 1.3.0 (just 23KB) is also available here at dracoblue.net.

Short installation and configuration information can be found in the readme. Thanks to all contributors!

mcrypt and PHP 5.3 on Ubuntu Jaunty

My dedicated server still runs on ubuntu jaunty. I wanted to move on to php 5.3 (php 5.2.16 was the final release of the php 5.2 series). The issue is: php 5.3 is not available in jaunty repositories, because it will stay at 5.2.

Installing php 5.3 was simple, just add to:

1
$ vim /etc/apt/sources.list

the following:

1
2
deb http://php53.dotdeb.org stable all
deb-src http://php53.dotdeb.org stable all

Install the dotdeb pgp key:

1
# curl http://www.dotdeb.org/dotdeb.gpg | apt-key add -

Update the apt cache and upgrade php5:

1
# apt-get update
1
# apt-get install php5

But when you want to install phpmyadmin again now, it fails.

1
php5-mcrypt: Depends: libltdl3 (>= 1.5.2-2) but it is not installable

Luckily you can get that (mcrypt) by adding the lenny updates repository manually:

1
# vim /etc/apt/sources.list

add:

1
http://security.debian.org/debian-security lenny/updates main

Install the debian gpg:

1
# gpg --keyserver wwwkeys.eu.pgp.net --recv-keys 9AA38DCD55BE302B

Now update again:

1
# apt-get update

and install php5-mcrypt flawlessly:

1
# apt-get php5-mcrypt

I commented out the new sources.list entries after the install, because I don't need them to be checked on every update.

In Articles, Linux, php & Ubuntu By DracoBlue @ 12:37 19.12.2010

Configure an Agavi Site with NGINX (using PHP-FPM)

de en

I was used to configure my Agavi site with Lighttpd and recently switched to Nginx. The setup for Nginx was not so common to me, so I decided to write down what I had to do to configure it properly. Here is an example for dracoblue.net. Please change the parts of the script to suit your needs (the necessary parts are highlighted with "HINT:").

First of all install php5-fpm. On ubuntu I did it this way:

1
$ sudo apt-get install php5-fpm

Now create a new file:

1
$ vim /etc/nginx/sites-enabled/dracoblue.net

And add the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
server {
listen dracoblue.net:80;
# HINT: Add the servername, so Agavi is able to see that it's dracoblue.net
# Otherwise you'll get something like "localhost" here
server_name dracoblue.net;

location / {
# HINT: The directory where index.php is
root /home/dracobluenet/tags/1.0.0/pub;
index index.php;

# HINT: All files except those in "static" should be served by index.php
location ~* ^/(favicon.ico|robots.txt|static) {
break;
}

# HINT: All files except those in "static" should be served by index.php
if ($uri !~ "^/(favicon.ico|robots.txt|static|index.php)") {
rewrite ^/([^?]*)$ /index.php?/$1 last;
}
}

location ~ \.php($|/) {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
# HINT: The directory where index.php is + $fastcgi_script_name
fastcgi_param SCRIPT_FILENAME /home/dracobluenet/tags/1.0.0/pub$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
}

As you can see, for projects I usually have only a "static" folder which is not served by agavi. This keeps the amount of work low, which nginx needs to do for each request to decide whether it should be served by php or not. I also added robots.txt and favicon.ico since you usually have them in root, too.

Restart nginx.

1
$ /etc/init.d/nginx restart
In Articles, Linux, php, Agavi, NGINX & Lighttpd By DracoBlue @ 13:46 09.12.2010

PhpDebugToolbar 1.1.1 (for agavi) released

Today I am pleased to announce the availability of the Agavi PHP DebugToolbar for download. After the success of the Qos-Filter for agavi, I want to relaunch the useful agavi toolbar with a different name, a better look and feel and a way better code base.

Screenshot:
http://twitpic.com/show/thumb/2zgig8.png

What is PhpDebugToolbar?
Like you can see on the screenshot, it's a little Toolbar (written in JS+CSS), which keeps track of all stuff happening in your php agavi application.
So you can easily spot memory leaks, time exhausting tasks and extensive usage of database queries (with the doctrine extension).

Additionally it integrates easily into the logging system of agavi, just add the PhpDebugToolbarLoggerAppender class in your logging.xml!

Where to download Toolbar?
The source can be found on github now http://github.com/DracoBlue/PhpDebugToolbar, feel free to fork it and send pull request with new features!

Download for PhpDebugToolbar 1.1.1 (just 20KB) is also available here at dracoblue.net.

Short installation and configuration information can be found in the readme. Thanks to all contributors!

This is meant to be a lightweight alternative to the unofficial Agavi Debug Tools. It won't have FirePHP output or other neat features, which ship with Agavi Debug Tools. So if you need them: use adt, please!

In open source, php, JavaScript, Agavi & PhpDebugToolbar By DracoBlue @ 12:33 21.10.2010