The Developer Day | Staying Curious

CAT | Apache

Feb/10

20

Subversion Self Signed Certificates

When connecting to Subversion repositories using SSL connections the SVN client checks the server certificate if it is not expired, if it’s host description matches the host of the repository and if the authority which signed the certificate is trusted.

If the certificate fails to comply with any of the above rules the SVN client will respond with a message such as this one:

Error validating server certificate for ‘https://hostname:443′:
- The certificate is not issued by a trusted authority. Use the
fingerprint to validate the certificate manually!
Certificate information:
- Hostname: hostname
- Valid: from Tue, 16 Feb 2010 16:58:39 GMT until Fri, 14 Feb 2020 16:58:39 GMT
- Issuer: company.com, London, Berkshire, GB
- Fingerprint: d5:4e:d8:12:33:12:a5:f1:18:91:77:40:c4:77:3b:0b:f8:51:71:cd
(R)eject, accept (t)emporarily or accept (p)ermanently?

The certificate can still be accepted permanently manually. It may not be a solution if SVN commands are issued by non interactive processes. For example a PHP script run by apache trying to export a branch from the repository.

Certificates signed by trusted authorities such as Verisign should not have any problems. But self signed certificates will not be recognized by the SVN client which in turn will respond with the response above. Self signed certificates can be be made trusted by the SVN client by using the ssl-authority-files configuration option:

ssl-authority-files = /home/void/.subversion/company.crt

The configuration file named servers which holds this configuration option can be stored in multiple locations on the filesystem. First the Subversion client will try to look for it in the home folder of the user that is executing the SVN command. Users such as apache will most likely not have a home folder. In such cases SVN tries to look for the servers file in the /etc/subversion directory. It may or may not exist depending on the OS distribution flavour. For example it exits on Ubuntu but does not exist on CentOS a flavour of RedHat.

, , , , Hide

Feb/10

18

Starting services in a clean environment

I was working on a small web application that creates Subversion branches and tags. In short it just executes SVN commands on the repository. Whenever a user executes an SVN command the SVN client tries to check user’s local home folder for the .subversion configuration directory. The issue that I was running into was that for some reason apache’s home folder was pointing to our system’s administrator home folder which in turn would result in a permission denied error when apache would try to access the .subversion folder.

It just didn’t make any sense. Turns out if you start a service through /etc/init.d/ it starts that service with environment variables belonging to the user that started the service. In this case our system’s administrator started the service using his own user.

To start services in a clean environment a special utility called service should be used. It usually resides in the /sbin directory. So for example instead of starting apache like this:

$ sudo /etc/init.d/httpd start

It should be started like this:

$ sudo /sbin/service httpd start

Which will result in $HOME environment variable being empty and the SVN client not getting a permission denied error.

, , , , , Hide

Apr/09

21

Adding a virtual host on apache windows xampp

Setting up virtual host on windows using apache and possibly XAMPP is easy but may cause some trouble to the inexperienced. To setup a virtual host follow these steps:

1. Locate your vhosts file. On my PC it’s: D:\apache\conf\extra\httpd-vhosts.conf
2. Uncomment the following line: NameVirtualHost *:80
3. Add your virtual host definition:


     DocumentRoot "D:\www\myproject\"
     ServerName myproject.com
     
          Allow from all
          Options +Includes +Indexes +FollowSymLinks
          AllowOverride all
     

4. Open a file name hosts located at: C:\WINDOWS\system32\drivers\etc
5. Add the following line: 127.0.0.1 myproject.com
Check that for project path correct slashes are being used. Apache seems to not understand \ slashes and instead wants /. If you try and start apache from a command line it may output something like this:

Syntax error on line 45 of D:/XamppLite/apache/conf/extra/httpd-vhosts.conf:
DocumentRoot must be a directory

, , , , Hide

Aug/07

21

PHP load testing tool

I needed to test load some of our applications. I’m currently using a windows machine as my workstation. For some weird reason I’ve decided to develop such a load testing tool myself. It was both interesting and fun.

I used php curl extension multi_ functions that are only available since PHP5. The script is very simple. It accepts an integer parameter with max clients and a string parameter where a URL list file resides. You can run the script either from the command line or a browser. The script outputs average client response time, average responses per minute, total amount of responses and time elapsed during test loading. After a client responds the tool requests another URL. You can only stop the tool by killing the process.

You can try my php test loading tool yourself. If you are looking for something more serious try apache ab under Linux or Cygwin.

, , , Hide

Aug/07

20

Profiling PHP applications

A while ago I was in need to profile one of our PHP applications. I needed to be able to see execution times, memory usage and some kind of a graphical interface to view it all. I remembered a PHP profiler debugger tool named Xdebug. Xdebug works as a PHP Zend extension. If you are a windows user installing it on your machine is very straightforward:

Download the appropriate windows module from xdebug.org. Edit your php.ini file by adding the following line to the extensions section:

zend_extension_ts=”path/xdebug.dll”

Restart your web server and look for a module named Xdebug in your phpinfo() output. If you’re lucky enough you’ll find it there.

After that you need to configure xdebug extension.

;enables the profiler
xdebug.profiler_enable=1;
;specifies profiler output files directory
xdebug.profiler_output_dir=”c:/php/xdebug/”
;specifies profiler output file name pattern.
xdebug.profiler_output_name=”cachegrind.%u.out”
;enables auto tracing on every script startup
xdebug.auto_trace=1
;specifies trace files output direcctory
xdebug.trace_output_dir=”c:/php/xdebug/”
;specifies trace output file name pattern.
xdebug.trace_output_name=”trace.%u”
;enable memory usage tracking
xdebug.show_mem_delta=1

Restart your web server again. Run any of your php applications and you should find files in your specified directories:

trace.1187359095_993350.xt
cachegrind.1187366421_815700.out

Now you can view cachegrind files with WinCacheGrind. The application I tested was spawning few processes of it’s own and the profile information was in one file by default. But apparently something didn’t want to work so I separated each process to a separate file by adding %u to the output file name pattern.

The most interesting part for me was memory usage which you can find in the .xt files. It shows the total memory used after every line of code executed and a delta’s between executions. A tool for viewing/analyzing these trace files would be nice. Did not look for one though. All in all Xdebug is useful to find those nasty bottlenecks. It also has other nice features that help you to daily develop your apps. Nice thing I didn’t try yet is the “Code coverage” test. It might help me find some unused code in our applications.

, , , Hide

Aug/07

17

PHP SoapClient certificate problems

I’ve been working with SoapClient and certificates for some time. I recently switched my old workstation to a new one and while working with a piece of code that seemed to work fine I got an error like this:

Unable to set local cert chain file `filename.pem’; Check that your cafile/capath settings include details of your certificate and its issuer in somescript.php on line ##

I tried to google what the problem might be and found a comment that you can get this error if you have curl extension disabled. But in my case it was enabled and working fine. I tried to remember what extensions I had enabled on my previous box and after a few thoughts I decided to enable mcrypt extension which seems related to crypted certificates and after restarting my webserver everything started working fine.

The php soapclient documentation does not mention anything that soapclient is dependency related to curl or mcrypt.

, , , , , Hide

Jun/07

18

PHP5 upgrade - DLL & version issues

Recently I tried to update my PHP 5.2.0 version to 5.2.3 on my Windows XP machine. After the upgrade I found that phpinfo() would still show the previous version of PHP 5.2.0. Though running the “php -version” at the command line would work fine saying that my php version is 5.2.3. Later that day I also noticed that I’m unable to connect to MySQL.

Fatal Error: undefined function mysql_connect()

Though, running php -m at the command line would say, that mysql extension is ready and loaded. And phpinfo() would show it as not loaded. After checking apache’s logs/error.txt i found that php is unable to load quite a few of the php.ini enabled extensions.

PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_curl.dll’ - The specified procedure could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_mcrypt.dll’ - The specified module could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_mhash.dll’ - The specified procedure could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_mysql.dll’ - The specified procedure could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_mysqli.dll’ - The specified procedure could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_soap.dll’ - The specified procedure could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘c:\\php\\ext\\php_xmlrpc.dll’ - The specified procedure could not be found.\r\n in Unknown on line 0

I started googling on the matter to find out what went wrong with the upgrade. After reading a PHP bug report I realized that it might have something to do with my windows/system32 dlls. Then I found php5ts.dll in the windows/system32 directory.

It became clear to me, that PHP CLI version was using the the DLL’s from the php directory and PHP as an Apache module was loading them from the windows\system32 directory. I deleted all of the DLLs that are in the PHP directory from the windows/system32 directory and added PHP directory path to PATH environment variable and everything seems to work fine now.

My personal advice is not to put any of PHP DLL’s in the windows/system32 directory. You may really forget you have them there and become confused why things have started acting strangely.

, Hide

Find it!

Theme Design by devolux.org