• 06Jan

    In Linux, installing Apache2 and PHP5 is easy. Always there is a related package to your distribution. But in many case, you’re not gonna prefer that environment. Because there may be some compile-time limits in your environment. For example, in Ubuntu, Apache2 comes with 256 ServerLimit configuration.

    # apt-get install apache2 php5

    Yesterday, I compiled Apache2 and PHP5 from source code to solve some performance problems for a media company and I’m gonna share compiling Apache2 and PHP5 parts with you.

    If you don’t optimize your web server your web site will never work stable whatever your server specification is. Yesterday, when I hear the website working slowly, first I checked error logs. There are so many errors on the pages. Remember, you need to fix these errors before you apply a specific performance tuning.

    When all errors gone away web site were still slow. So, I had to do something about that! This article is not for performance tuning. Because of that I won’t touch on tuning details.

    There is a powerful server with Dual CPU and 8GB RAM. In that case, that server is web server and runs static pages 90 percent.

    As I said before, there is a compile-time limit in Apache2 which is installed by apt-get in Ubuntu. To solve that problem I compiled Apache2 from source code with PHP5. Here are the instructions:

    ServerLimit is a compile-time option and it’s located in MPM (Multi-Processing Module) scripts. If you want to set that option you need to open prefork.c file which is located in /server/mpm/prefork directory in your Apache2 source directory and find DEFAULT_SERVER_LIMIT definition and change it to value you want to.

    # ./configure –enable-so –enable-cgi –enable-info –enable-rewrite –enable-speling –enable-usertrack –enable-deflate –enable-ssl –enable-mime-magic

    You have to install some extra packages to complete configure command with these options such as SSL, Deflate. You can use apt-get to install extra packages.

    When you complete configure successfully it’s time to run make command. make will take times and then, you have to run make install to install Apache2. If you don’t use –prefix option in configure Apache2 will be installed into default directory. It’s probably /usr/local/apache2.

    So, we’re completed to install Apache2. It’s PHP’s turn now.

    ./configure –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql –prefix=/usr/local/apache2/php –with-config-file-path=/usr/local/apache2/php –disable-cgi –with-zlib –with-gettext –with-gd –enable-ftp

    You have to install some extra packages to complete configure command with these options such as MySQL, GD, ZLib.

    When you complete configure successfully it’s time to run make command. make will take times and then, you have to run make install to install PHP5.

    cp php.ini-recommended /usr/local/apache2/php/php.ini

    In my case, these modules were required. You may want to change configure options.

    If you completed to install successfully Apache2 and PHP5, you need to make some modifications in Apache2 configuration.

    AddHandler php5-script php
    DirectoryIndex index.php index.html
    AddType text/html php

    Now you have your own compiled Apache2 and PHP5.

  • 28Nov

    People compare PHP with other software development languages. According to many articles, there is one major difference: PHP does not support asynchronous processing, threading, etc. Working as an Apache module, that’s correct. But if you’re running your script on CLI or CGI module you have an option: Fork.

    Fork is a child processing method. As different from your regular PHP scripts, pcntl_fork() is not linear. Because of this, for some developers, it’s a little bit hard to learn how fork works.

    All processes you run have a unique process id. We call that id PID. All processes also have another ID which is reference to the parent process. We call that id PPID. pcntl_fork() is just copying current process and pretend as it’s a child process. New child process gets a unique PID and our process’s PID becomes PPID for new child process.

    When you call pcntl_fork() it always returns INT value. For child processes, it returns 0. For parent, it returns PID if everything’s fine. Otherwise, it returns -1. When you get -1 that means something is just wrong.

  • 20Sep

    I believe that Internet Explorer is a joke by Microsoft. Alright, I don’t really believe that but it could be anyway :)

    Why can’t their programmers or software architects realize that they are still The Most Popular Internet Browser on our planet. In my opinion, the most important question is how can’t IE make possible things that making possible by others.

    The problem that I had faced to at last is just happend while I’m trying to use same session with subdomains. It’s not working on IE. The most strange thing in this case is that there is nothing to do with the browser to make it possible normally. It’s a server-side problem and here is solution:

    session_set_cookie_params(1200, null, ‘.domain.com’);

    Now, you can use same session on your subdomains except you’re working on IE. So, we need to detect Internet Browser to apply that wonderful feature.

    if (substr_count($_SERVER['HTTP_USER_AGENT'], ‘Firefox’) > 0)
    session_set_cookie_params(1200, null, ‘.domain.com’);

  • 19Sep

    <VirtualHost localhost:80>
    ServerAdmin baraka@localhost
    ServerName test.baraka
    DocumentRoot /var/www/baraka/run
    DirectoryIndex index.php

    <Directory /var/www/baraka/run>
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>
    </VirtualHost>

    Update: Please check your Baraka path before load that configuration.