Difference between revisions of "install php with php-fpm"

From WebHostingNeeds.com
Jump to: navigation, search
m
m
Line 2: Line 2:
 
yum install libxml2-devel curl-devel libjpeg-devel libpng-devel zlib-devel freetype-devel gd-devel mhash-devel libmcrypt-devel gcc -y
 
yum install libxml2-devel curl-devel libjpeg-devel libpng-devel zlib-devel freetype-devel gd-devel mhash-devel libmcrypt-devel gcc -y
 
</pre>
 
</pre>
 
  
 
<pre>
 
<pre>
 
cd /usr/local/src/
 
cd /usr/local/src/
 
 
wget http://us3.php.net/get/php-5.2.17.tar.gz/from/us.php.net/mirror
 
wget http://us3.php.net/get/php-5.2.17.tar.gz/from/us.php.net/mirror
 
tar zxvf php-5.2.17.tar.gz
 
tar zxvf php-5.2.17.tar.gz
 
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
 
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
 
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
 
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
 
 
cd /usr/local/src/php-5.2.17
 
cd /usr/local/src/php-5.2.17
+
./configure --prefix=/usr/local/php-fpm --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --disable-pdo --with-mysql --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 -with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-freetype-dir --with-jpeg-dir --enable-zend-multibyte --with-gd --with-libdir=lib64
./configure --prefix=/usr/local/nginx-php --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --disable-pdo --with-mysql --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 -with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-freetype-dir --with-jpeg-dir --enable-zend-multibyte --with-gd --with-libdir=lib64
 
 
 
 
 
 
make
 
make
 
make install
 
make install
 
</pre>
 
</pre>
 
  
 
Copy php.ini
 
Copy php.ini
  
 
<pre>
 
<pre>
cp php.ini-recommended /usr/local/nginx-php/lib/php/php.ini
+
cp php.ini-recommended /usr/local/php-fpm/lib/php/php.ini
 
</pre>
 
</pre>
  
 
+
I have faced problem with curl, so i install url from source as per [[install php from source]]
I have faced problem with curl, so i install url from source as per [[Install php from source]]
 
  
 
<pre>
 
<pre>
vi /usr/local/nginx-php/etc/php-fpm.conf
+
vi /usr/local/php-fpm/etc/php-fpm.conf
 
</pre>
 
</pre>
  
Line 56: Line 48:
  
 
<pre>
 
<pre>
/usr/local/nginx-php/sbin/php-fpm start
+
/usr/local/php-fpm/sbin/php-fpm start
 
</pre>
 
</pre>
  
 
<pre>
 
<pre>
 
[[email protected] ~]# ps aux| grep fpm
 
[[email protected] ~]# ps aux| grep fpm
root      9248  0.0  0.0 134884  3192 ?        Ss  11:58  0:00 /usr/local/nginx-php/bin/php-cgi --fpm --fpm-config /usr/local/nginx-php/etc/php-fpm.conf
+
root      9248  0.0  0.0 134884  3192 ?        Ss  11:58  0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
nginx    9249  0.0  0.0 134884  3108 ?        S    11:58  0:00 /usr/local/nginx-php/bin/php-cgi --fpm --fpm-config /usr/local/nginx-php/etc/php-fpm.conf
+
nginx    9249  0.0  0.0 134884  3108 ?        S    11:58  0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
nginx    9250  0.0  0.0 134884  3108 ?        S    11:58  0:00 /usr/local/nginx-php/bin/php-cgi --fpm --fpm-config /usr/local/nginx-php/etc/php-fpm.conf
+
nginx    9250  0.0  0.0 134884  3108 ?        S    11:58  0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
nginx    9251  0.0  0.0 134884  3108 ?        S    11:58  0:00 /usr/local/nginx-php/bin/php-cgi --fpm --fpm-config /usr/local/nginx-php/etc/php-fpm.conf
+
nginx    9251  0.0  0.0 134884  3108 ?        S    11:58  0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
nginx    9252  0.0  0.0 134884  3108 ?        S    11:58  0:00 /usr/local/nginx-php/bin/php-cgi --fpm --fpm-config /usr/local/nginx-php/etc/php-fpm.conf
+
nginx    9252  0.0  0.0 134884  3108 ?        S    11:58  0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
nginx    9253  0.0  0.0 134884  3108 ?        S    11:58  0:00 /usr/local/nginx-php/bin/php-cgi --fpm --fpm-config /usr/local/nginx-php/etc/php-fpm.conf
+
nginx    9253  0.0  0.0 134884  3108 ?        S    11:58  0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
 
root      9720  0.0  0.0  61220  780 pts/0    S+  11:59  0:00 grep fpm
 
root      9720  0.0  0.0  61220  780 pts/0    S+  11:59  0:00 grep fpm
 
[[email protected] ~]# netstat -an|grep :9000
 
[[email protected] ~]# netstat -an|grep :9000
Line 99: Line 91:
 
         }
 
         }
  
location ~ \.php$ {
+
    location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
+
        fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
+
        fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/test/html$fastcgi_script_name;
+
        fastcgi_param SCRIPT_FILENAME /home/test/html$fastcgi_script_name;
include fastcgi_params;
+
        include fastcgi_params;
}
+
    }
 
</pre>
 
</pre>
  
Line 113: Line 105:
 
echo "Testing" > /home/test/html/index.html
 
echo "Testing" > /home/test/html/index.html
 
</pre>
 
</pre>
 
 
 
 
  
  
 
----
 
----
  
[[Nginx]]
+
[[nginx]]

Revision as of 10:26, 29 January 2014

yum install libxml2-devel curl-devel libjpeg-devel libpng-devel zlib-devel freetype-devel gd-devel mhash-devel libmcrypt-devel gcc -y
cd /usr/local/src/
wget http://us3.php.net/get/php-5.2.17.tar.gz/from/us.php.net/mirror
tar zxvf php-5.2.17.tar.gz
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd /usr/local/src/php-5.2.17
./configure --prefix=/usr/local/php-fpm --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --disable-pdo --with-mysql --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 -with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-freetype-dir --with-jpeg-dir --enable-zend-multibyte --with-gd --with-libdir=lib64
make
make install

Copy php.ini

cp php.ini-recommended /usr/local/php-fpm/lib/php/php.ini

I have faced problem with curl, so i install url from source as per install php from source

vi /usr/local/php-fpm/etc/php-fpm.conf


Find

                        Unix user of processes
                <!--    <value name="user">nobody</value>                               -->

                        Unix group of processes
                <!--    <value name="group">nobody</value>              -->

Add below

                        <value name="user">nginx</value>
                        <value name="group">nginx</value>

Starting php-fpm

/usr/local/php-fpm/sbin/php-fpm start
[[email protected] ~]# ps aux| grep fpm
root      9248  0.0  0.0 134884  3192 ?        Ss   11:58   0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
nginx     9249  0.0  0.0 134884  3108 ?        S    11:58   0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
nginx     9250  0.0  0.0 134884  3108 ?        S    11:58   0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
nginx     9251  0.0  0.0 134884  3108 ?        S    11:58   0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
nginx     9252  0.0  0.0 134884  3108 ?        S    11:58   0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
nginx     9253  0.0  0.0 134884  3108 ?        S    11:58   0:00 /usr/local/php-fpm/bin/php-cgi --fpm --fpm-config /usr/local/php-fpm/etc/php-fpm.conf
root      9720  0.0  0.0  61220   780 pts/0    S+   11:59   0:00 grep fpm
[[email protected] ~]# netstat -an|grep :9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN
[[email protected] ~]#


Configuring Nginx to use php-fpm

Edit nginx.conf

vi /etc/nginx/nginx.conf

Find

        location / {
            root   html;
            index  index.html index.htm;
        }

Replace with

        location / {
            root   /home/test/html;
            index  index.html index.htm index.php;
        }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /home/test/html$fastcgi_script_name;
        include fastcgi_params;
    }

Create document root and a test file

mkdir -p /home/test/html
echo "Testing" > /home/test/html/index.html



nginx