Not signed in (Sign In)
    •  
      CommentAuthorsoroush
    • CommentTimeJun 28th 2008
     permalink

    Hi everyone!

    I have a problem which I hope you can help with.

    In a nutshell

    I've been having problems with Apache using up memory and also using up swap.

    More:

    I have a 256MB slice, with Ubuntu 6.06 installed and use Apache 2 with php and mysql to run my Drupal website. I've read other discussions on this forum (found 2), and also did some reading on the Internet. I've tried to tune my Apache configuration and change maxClients, etc., which has helped to some degree but not much. In the end I've resorted to (for now anyway) restarting apache every few hours. Recently, I had around 90 visitors to my site at around the same time, which caused Apache to use swap, which in turn I was emailed about through Slicehost. (second time this has happened)

    I'm worried that I'll have problems later on, if I have even a modest burst of traffic. I also previously thought I could run at least 2-3 websites on my slice, but it doesn't look possible right now.

    So I had a couple of questions:

    • Are there any suggestions for making Apache behave better and make the most of my 256MB or RAM?
    • If anyone else uses Drupal, is there anything I can do in Drupal to help the problem?
    • and finally, I've heard good things about nginx, is that the way to go? Again to Drupal using folks, do they work well together?

    Thank you for you time in reading and replying to my questions.

    • CommentAuthoralphagears
    • CommentTimeJun 28th 2008
     permalink
    I have a number of drupal sites on a 256 slice. I'm using nginx with php5-fastcgi. I use to have a 512 slice with apache and was just getting by with memory. I did tune my apache server with maxClient and maxRequests and that seemed to work for me. But I can attest to the majesty of nginx with php5-fastcgi. I can easily sustain heavy traffic on my drupal sites. I did a siege test a few weeks ago and it held up better than I expected. The user load you mentioned would easily be handled. I am using Ubuntu 8.04 (I was using 6.06 with apache before), so I'm not sure if the newer version works any faster with this stuff.

    Let me know if you need any help setting up nginx. I can post my vhost configs and php5-fastcgi init scripts. I was able to do it all through ubuntu's packages and not compile anything.
    •  
      CommentAuthorsoroush
    • CommentTimeJun 28th 2008
     permalink
    Thanks alphagears!

    "... a number of drupal sites on a 256 slice." I never thought that was possible! Looks like I should look into nginx. I have two concerns:

    1. How does Drupal's .htaccess file get "translated" for nginx to understand? Do I have to rewrite it?
    2. Do I have to remove my current Apache, php (and mysql maybe) if I install nginx with php5-fastcgi?

    Thanks again.
    • CommentAuthoralphagears
    • CommentTimeJun 29th 2008
     permalink

    The .htaccess rewrite is easily translated in to the nginx config. The config for nginx is just…

    if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$1 last; }

    You don’t have to remove apache and php, but I would recommend it. You’ll want to install nginx and php-cgi. I’m totally sure if Ubuntu 6.06 has a package for nginx. I know it’s available in 8.04. But you could build from source, if you’re feeling adventurous.

    •  
      CommentAuthorsoroush
    • CommentTimeJun 29th 2008
     permalink
    Great! I'll read more into nginx and get myself comfortable with it and then switch to it from Apache! : )
    • CommentAuthoralphagears
    • CommentTimeJun 29th 2008
     permalink

    Cool. Let me know if you need any of my configs. There are some php=fcgi init scripts out there but most use lighttp’s spawn program, which you don’t need to use.

    •  
      CommentAuthorsoroush
    • CommentTimeJun 30th 2008
     permalink
    Hello again alphagears!

    I installed nginx from source on a test server, along with php5-cgi. I was following the article written by Pickled Onion (thanks!) in the Articles section. I haven't created any init scripts or modify any conf files.

    searching thorough the forums, I found this post by you:
    < http://forum.slicehost.com/comments.php?DiscussionID=1987&page=1#Item_2 >

    Do I need all of those scripts? I will be using virtual hosts, url rewrite and of course php5.

    Thanks for pointing me in the right direction. : )
    •  
      CommentAuthorsoroush
    • CommentTimeJul 1st 2008
     permalink
    To update:

    I used Pickled Onion's nginx init script along with alphagears' php-fastcgi scripts (link in previous post), had then start when system boots and php is working now.

    Thanks guys!

    Now I'll have to figure why I get a 403 error with phpmyadmin.
  1.  permalink

    Soroush. Sorry I was not at my computer yesterday. I’m very glad you got nginx and php working. The 403 message is probably going to be the permissions on the phpmyadmin directory. Make sure the nginx user (e.g. www-data) has read access to the files.

    • CommentAuthorfactor
    • CommentTimeJul 1st 2008
     permalink

    FWIW, another option is lighttpd + php-fastcgi, which I’ve used for Drupal with success.

    Basic config:

    $HTTP["host"] == "www.yoursite.com" { server.document-root = "/var/www/yoursite" index-file.names = ("index.php") fastcgi.server = (".php" => (( "socket" => "/tmp/php-fastcgi.sock", "bin-path" => "/usr/bin/php-cgi", ))) }

    Clean URLs can be implemented too. More info here.

    •  
      CommentAuthorsoroush
    • CommentTimeJul 1st 2008
     permalink
    @alphagears: Thanks for the tip on phpmyadmin. I'll check the permissions tomorrow. (my machine doesn't have remote access, otherwise itching to do it now!)

    @factor: I've heard good things about lighttpd, with 'big people' using it. I'll keep this solution in mind as well.
    •  
      CommentAuthorsoroush
    • CommentTimeJul 2nd 2008
     permalink
    Ok, the 403 error was due to not adding 'index.php' to my location{}. I mentioned this at the below link, which might be of use to someone else:

    < http://forum.slicehost.com/comments.php?DiscussionID=2023&page=1#Item_7 >

    @alphagears, I think I'm ready to make 'the big move' now! I can get nginx and php working. I think I have the virtual hosts under control, using the English nginx wiki as a starting point. That leaves Drupal. You mentioned a rewrite snippet above, which I also saw on the Drupal forum. Is that all I need to get everything working? What about the hidden .htaccess file that is inside the Drupal folder? Most of it is commented out, but there are still some things available there.

    Thanks for your help and guidance so far!
    Soroush
    • CommentAuthoralphagears
    • CommentTimeJul 2nd 2008 edited
     permalink
    Soroush. The .htaccess file is useless to nginx so you could delete it or just rename it. Here is a full example of one of my vhost that uses drupal. It should be all you need to get it running. Obviously your fast-cgi port may be different than mine. The first server entry just redirects site.com to www.site.com.

    server {
    listen 80;
    server_name site.com;
    rewrite ^/(.*) http://www.site.com/$1 permanent;
    }

    server {
    listen 80;
    server_name www.site.com;
    client_max_body_size 16m;

    access_log /path/to/logs/access.log;

    location / {
    root /path/to/site;
    index index.php;

    if (!-e $request_filename) {
    rewrite ^/(.*)$ /index.php?q=$1 last;
    }
    }

    # .php, .php3, .php4 and .php5 sent to php5
    location ~ .*\.php[345]?$ {
    include /etc/nginx/fcgi.conf;
    fastcgi_pass 127.0.0.1:10005;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /path/to/site$fastcgi_script_name;
    }
    }


    That should be it.
    Thankful People: soroush
    •  
      CommentAuthorsoroush
    • CommentTimeJul 2nd 2008
     permalink
    Thanks! I'll report back once I get everything running.
    •  
      CommentAuthorsoroush
    • CommentTimeJul 3rd 2008
     permalink
    Right... following the Slicehost articles and alphagears' help, I've managed to setup Drupal with nginx! : ) In the past 24 hours, my RAM usage went up by 3MB, something I hadn't gotten with Apache!

    One thing to note is that in alphagears' php-fastcgi script, there is a line


    # Load the VERBOSE setting and other rcS variables
    . /lib/init/vars.sh


    which was causing errors on a Ubuntu 6.06 machine, as that file didn't exist. This wasn't the case in Ubuntu 8.04. I commented the line out, and the rest was fine.

    Thanks for the help guys!
    • CommentAuthoralphagears
    • CommentTimeJul 3rd 2008 edited
     permalink
    Woohoo! Glad it's working for you! It would be interesting to know what 'free -m' currently says to how much memory you saved by switching.
    •  
      CommentAuthorsoroush
    • CommentTimeJul 3rd 2008
     permalink
    This is what I get:

    $ free -m
    total used free shared buffers cached
    Mem: 256 252 3 0 19 49
    -/+ buffers/cache: 183 72
    Swap: 511 0 511


    As I understand, I'm using 183MB and have 72MB free. About 24 hours ago, I was using 180MB of RAM. I'm not sure if 183MB is considered "high" or "low" amount of memory usage and whether I could fit in another website! What I know is, with Apache I would have such a figure, but with every page view the value would increase (jump!) and it was always using an amount of swap, which would increase with higher traffic. I was restarting Apache every few hours, but it would still swap in that time as well... and I would get an email from Slicehost reminding me about it!

    So in a nutshell, it's the memory 'stability' that is different so far.

    Soroush
    • CommentAuthorlewis
    • CommentTimeJul 24th 2008 edited
     permalink
    I'm glad that it finally worked out for you. well, I tried to follow in your footsteps...I started off by having nginx and php working following PickledOnion's Guide and alphagears's script. Althought I am not sure about the latter step; it's not really detailed so I did a lot of guessing since I'm still fresh off the boat with linux. can you give more details please. thanks

    Basically, I created a new vhost file in /usr/local/nginx/sites-available with the following command:

    sudo nano /usr/local/nginx/sites-available/my_vhost

    Then I edited the file with the following: (I wasn't really sure about my site path under drupal)

    server {
    listen 80;
    server_name site.com;
    rewrite ^/(.*) http://www.my_site.com/$1 permanent;
    }

    server {
    listen 80;
    server_name www.my_site.com;
    client_max_body_size 16m;

    access_log /usr/local/nginx/logs/access.log;

    location / {
    root /var/www;
    index index.php;

    if (!-e $request_filename) {
    rewrite ^/(.*)$ /index.php?q=$1 last;
    }
    }

    # .php, .php3, .php4 and .php5 sent to php5
    location ~ .*\.php[345]?$ {
    include /etc/nginx/fcgi.conf;
    fastcgi_pass 127.0.0.1:10005;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
    }
    }

    Finally, I created a symlink with ln -s /usr/local/nginx/sites-available/my_vhost /usr/local/nginx/sites-enabled/my_vhost.

    I deleted .htaccess in the drupal folder. I'm not sure what it is for but I heard I had to get rid of it.

    now I still have apache installed, and my website is apparently still online and working. i am not sure nginx is running though. I am a little bit confused. I don't know if I should uninstall apache? If yes, how? Also, what did I do wrong or what should I do? Thanks for your help. I wish I could understand how nginx works a little bit better
    • CommentAuthoralphagears
    • CommentTimeJul 24th 2008
     permalink
    Hey Lewis.

    In essence, you are going to replace apache with nginx. Both are web servers. Since both apache and nginx are trying to bind to port 80, one will loose out. So you need to get rid of apache. You should be able to do a 'sudo apt-get remove apache2'. That should remove apache and let nginx take over. Once apache is uninstalled, you should restart nginx. From the looks of your paths, you compiled nginx from source, right? I'm assuming you created the init script from PickledOnion's article. So to restart nginx you should run 'sudo /etc/init.d/nginx restart'

    That should get nginx running for you.
    • CommentAuthorlewis
    • CommentTimeJul 24th 2008 edited
     permalink
    Thank you for answering so fast alphagears; well, I just did what you suggested. however, for some reasons I think that apache2 is not completly removed. The website is still online. I typed the command; top and I could see some apache2 processes running.

    Mem: 262316k total, 250336k used, 11980k free, 400k buffers
    Swap: 524280k total, 129560k used, 394720k free, 56880k cached

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    8372 www-data 15 0 192m 30m 3504 S 0 11.9 0:00.62 apache2
    5641 www-data 15 0 192m 30m 3280 S 0 11.8 0:02.38 apache2
    5614 www-data 15 0 192m 29m 3280 S 0 11.7 0:02.82 apache2
    5693 www-data 15 0 192m 29m 3348 S 0 11.6 0:00.29 apache2
    7981 www-data 15 0 191m 29m 3452 S 0 11.4 0:00.25 apache2
    5057 www-data 15 0 188m 26m 3148 S 0 10.2 0:03.75 apache2
    5664 www-data 15 0 188m 6752 3248 S 0 2.6 0:01.30 apache2
    2206 mysql 15 0 287m 5376 1828 S 0 2.0 0:07.28 mysqld
    8486 root 18 0 67960 2892 2292 S 0 1.1 0:00.01 sshd
    8386 www-data 15 0 168m 2760 1256 S 0 1.1 0:00.00 apache2