Freebsd 9.1 + nginx 1.4.2 + php 5.4.18 + php 5.5.2 编译安装

2013-08-18 02:02:08 0  category: Freebsd

PHP 在Freebsd 9.1 下的安装


1.下载 nginx


root@bsd91:/root # fetch http://nginx.org/download/nginx-1.4.2.tar.gz


2.下载 php 5.5.2


root@bsd91:/root # fetch http://www.php.net/get/php-5.5.2.tar.bz2/from/hk1.php.net/mirror

root@bsd91:/root # mv mirror php-5.5.2.tar.bz2


3.下载 php 5.4.18



root@bsd91:/root # fetch http://www.php.net/get/php-5.4.18.tar.bz2/from/tw2.php.net/mirror

root@bsd91:/root # mv mirror php-5.4.18.tar.bz2


4. 安装nginx

 

root@bsd91:/root/ # tar -xvf nginx-1.4.2.tar.gz

root@bsd91:/root/ # cd nginx-1.4.2

root@bsd91:/root/nginx-1.4.2 # pkg_add -r pcre

root@bsd91:/root/nginx-1.4.2 # ./configure --prefix=/usr/local/nginx142 --with-http_ssl_module

root@bsd91:/root/nginx-1.4.2 # make && make install

root@bsd91:/root # echo "/usr/local/nginx142/sbin/nginx" >> /etc/rc.local //开机自动启动



5.安装 php-5.4.18


root@bsd91:/root/nginx-1.4.2 # cd ..

root@bsd91:/root/ # tar -xvf php-5.4.18.tar.bz2

root@bsd91:/root/ # cd php-5.4.18

root@bsd91:/root/ # pkg_add -r libxml2 curl libmcrypt

root@bsd91:/root/php-5.4.18 # ./configure --prefix=/usr/local/php5418 --with-config-file-path=/usr/local/php5418/etc --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-mhash --enable-mbstring --with-mcrypt --enable-xml --enable-sockets --enable-zip --enable-bcmath

root@bsd91:/root/php-5.4.18 # make && make install

root@bsd91:/root/php-5.4.18 # cp php.ini-development /usr/local/php5418/etc/php.ini

root@bsd91:/root/php-5.4.18 # cp sapi/fpm/init.d.php-fpm /usr/local/php5418/etc/php-fpm.rc

root@bsd91:/root/php-5.4.18 # cd /usr/local/php5418/etc/

root@bsd91:/usr/local/php5418/etc # mv php-fpm.conf.default php-fpm.conf

root@bsd91:/usr/local/php5418/etc # vim php-fpm.conf
// pid = run/php-fpm.pid //25行去掉注释
// listen = 127.0.0.1:9004 // 159 行修改
// request_terminate_timeout = 120 // 444 行 修改

root@bsd91:/usr/local/php5418/etc # chmod a+x php-fpm.rc

root@bsd91:/usr/local/php5418/etc # echo "/usr/local/php5418/etc/php-fpm.rc start" >> /etc/rc.local //开机自动启动



5.安装 php-5.5.2



root@bsd91:/usr/local/php5418/etc # cd /root/

root@bsd91:/root # tar xvf php-5.5.2.tar.bz2

root@bsd91:/root # cd php-5.5.2

root@bsd91:/root/php-5.5.2 # ./configure --prefix=/usr/local/php552 --with-config-file-path=/usr/local/php552/etc --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-mhash --enable-mbstring --with-mcrypt --enable-xml --enable-sockets --enable-zip --enable-bcmath --enable-opcache

root@bsd91:/root/php-5.5.2 # make && make install

root@bsd91:/root/php-5.5.2 # cp php.ini-development /usr/local/php552/etc/php.ini

root@bsd91:/root/php-5.5.2 # cp sapi/fpm/init.d.php-fpm /usr/local/php552/etc/php-fpm.rc

root@bsd91:/root/php-5.5.2 # cd /usr/local/php552/etc/

root@bsd91:/usr/local/php552/etc # mv php-fpm.conf.default php-fpm.conf

root@bsd91:/usr/local/php552/etc # vim php-fpm.conf
// pid = run/php-fpm.pid 修改第25行
// listen = 127.0.0.1:9005 修改第159行
// request_terminate_timeout = 120 // 修改第444 行

root@bsd91:/usr/local/php552/etc # chmod +x php-fpm.rc

root@bsd91:/usr/local/php552/etc # echo "/usr/local/php552/etc/php-fpm.rc start" >> /etc/rc.local


6.添加GD库

root@bsd91:/usr/local/php552/etc # cd /root/php-5.5.2/ext/gd

root@bsd91:/root/php-5.5.2/ext/gd # pkg_add -r autoconf freetype2 jpeg png

root@bsd91:/root/php-5.5.2/ext/gd # /usr/local/php552/bin/phpize

./configure --with-php-config=/usr/local/php552/bin/php-config --with-jpeg-dir --with-png-dir --with-freetype-dir

root@bsd91:/root/php-5.5.2/ext/gd # make && make install

root@bsd91:/root/php-5.5.2/ext/gd # vim /usr/local/php552/etc/php.ini
// extension=gd.so //在910行添加



7.修改nginx 配置文件


root@bsd91:/usr/local/php552 # cd /usr/local/nginx142/conf/

root@bsd91:/usr/local/nginx142/conf # vim nginx.conf
// include vhost/*.vhost 在80行添加

root@bsd91:/usr/local/nginx142/conf # mkdir vhost

root@bsd91:/usr/local/nginx142/conf # cd vhost

root@bsd91:/usr/local/nginx142/conf/vhost # vim p5.bsd.vhost

server {
listen 80;
server_name p55.bsd;
#access_log logs/host.access.log main;
location / {
root /home/test;
index index.html index.htm index.php;
autoindex on;
try_files $uri $uri/ /index.php;
}
error_page 404 /404.html;
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:9005;
# fastcgi_index index.php;
include fastcgi_params;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ( $fastcgi_script_name ~ "^(.+?\.php)(/.*)$" ) {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /home/test$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}


root@bsd91:/usr/local/nginx142/conf/vhost # cp p5.bsd.vhost p4.bsd.vhost

root@bsd91:/usr/local/nginx142/conf/vhost # vim vhost/p4.bsd.vhost


server {
listen 80;
server_name p54.bsd;
#access_log logs/host.access.log main;
location / {
root /home/test;
index index.html index.htm index.php;
autoindex on;
try_files $uri $uri/ /index.php;
}
error_page 404 /404.html;
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:9004;
# fastcgi_index index.php;
include fastcgi_params;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ( $fastcgi_script_name ~ "^(.+?\.php)(/.*)$" ) {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /home/test$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}


root@bsd91:/usr/local/nginx142/conf/vhost # vim /home/test/i.php
<?php
phpinfo();


root@bsd91:/usr/local/nginx142/conf/vhost # sh /etc/rc.local

//修改本机 hosts 文件
// 192.168.56.22 p55.bsd // Freebsd 的IP
// 192.168.56.22 p54.bsd // Freebsd 的IP