⬆️ ⬇️

Installing nginx + php-fpm + memcache + eaccelerator on FreeBSD

Why all this? - you ask. Yes, I just wanted to share with the public some of the experience gained in the process of optimizing vds for the needs of a well-known blog-social engine , which on a regular hosting feels uncomfortable, to say the least.



It all started with the fact that I left from firstvds, where nothing can save from the brakes. Gone to Gandy. No, took one ball (1 share), which was given for a month for free. By the way, this action ( This summer, your server is free! ) Is not over yet. ;) And on this ball I began to conduct brutal experiments with installing different software. Tested results with siege.



As a result, the configuration of the subject was the fastest. I would like to share the experience of its installation and configuration with you.

')

First of all, we are updating the ports tree, if we haven’t done it for a long time. And if they have never done it, then without this, they will go nowhere:

# portsnap fetch update


Nginx



Install the latest stable version of nginx from the ports:

# cd /usr/ports/www/nginx

# make install clean


Add the line 'nginx_enable = "YES"' to the file '/etc/rc.conf'.



Basic nginx default settings to know where to look:



PHP-FPM



First we install php itself:

# cd /usr/ports/lang/php5

# make install clean


PHP support in FreeBSD is built on a modular basis, so the basic installation has limited functionality. Additional extensions can be easily added using the php5-extensions port. Install the extensions we need (for example, mbstring, gd, mysql ...):

# cd /usr/ports/lang/php5-extensions

# make install clean


Next put the patch php-fpm. In the ports of freebsd this patch is missing, but it does not matter. I propose, after all, to put it through the port, and not to collect it from the sources. Download the FreeBSD port from php-fpm.org and unpack it to the default ports directory, from where we install:

# fetch php-fpm.anight.org/downloads/freebsd-port/php-5.2.10-fpm-0.5.13.tar.gz

# tar -xvf php-5.2.10-fpm-0.5.13.tar.gz -C /usr/ports/lang/

# cd /usr/ports/lang/php5-fpm

# make install clean


Add the line 'php_fpm_enable = ”YES"' to the file '/etc/rc.conf'.



We are friends with NGINX and PHP



We go in kofig our http-server. By default, it is here '/usr/local/etc/nginx/nginx.conf'. We erase everything. To begin with, the config will be like this with a minimum of settings:

user www;

worker_processes 1;



events {

worker_connections 1024;

}



http {

include mime.types;

default_type application/octet-stream;



server {

listen 80;

server_name localhost;



charset utf-8;



location / {

root /usr/local/www/nginx;

index index.php index.html index.htm;

}



error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/local/www/nginx-dist;

}



location ~ \.php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /usr/local/www/nginx$fastcgi_script_name;

include fastcgi_params;

}

}

}


A detailed description of the configuration file settings can be found here and here , so I will not dwell in detail. Recently, an article appeared on Habré about setting up nginx - I recommend for viewing.



Next, edit the configuration of php-fpm. By default, it is here '/usr/local/etc/php-fpm.conf'. Find in the file line:

<!–- <value name=”user”>nobody</value> -–>

<!–- <value name=”group”>nobody</value> -–>


And change them to:

<value name=”user”>www</value>

<value name=”group”>www</value>


Thus, specifying the user and group under which php will spin. A detailed description of these and other php-fpm settings is available on the official site in Russian .



MEMCACHE



We put the memcache extension:

# cd /usr/ports/databases/pecl-memcache

# make install clean


Then go to the file '/usr/local/etc/php/extensions.ini', where we add the line:

extension=memcache.so


EACCELERATOR



Install:

# cd /usr/ports/www/eaccelerator

# make install clean


Similarly, memcache go to the file '/usr/local/etc/php/extensions.ini' and add the line:

extension=eaccelerator.so


Create a folder where eAccelerator will store its cache, set the owner of the www and set permissions:

# mkdir /tmp/eaccelerator

# chown www /tmp/eaccelerator

# chmod 0700 /tmp/eaccelerator


RESULT



Run php and nginx:

# /usr/local/etc/rc.d/php-fpm start

# /usr/local/etc/rc.d/nginx start


It's time to check if we have something. :) Create the file '/usr/local/www/nginx/info.php' with the contents of "<? Php phpinfo ();?>". And we look at the result in the browser: https: //your-domain/info.h - it should be something like this:



image



Beyond the scope of this note are: installing mysql (put as easy as everything else from the ports) and a bunch of different settings, read tuning, all this magnificence. But this is a huge material, which is regularly covered on Habré in one way or another in parts. Does it make sense to collect the tuning of the entire bundle in one article - I do not know yet. Thanks for attention. My first topic is here in two years of presence. :)

Source: https://habr.com/ru/post/67152/



All Articles