bsd / 未分类 · 2012年7月15日

FNMP(非ports)

#lnmp
http://www.discuz.net/thread-1833489-1-1.html
先用ports安装pcre nginx 要用到的
cd /usr/ports/devel/pcre
make install clean
###安装nginx###安装nginx###安装nginx###安装nginx###安装nginx###安装nginx###安装nginx###安装nginx###安装nginx
1、下载与解压nginx
wget http://sysoev.ru/nginx/nginx-0.7.61.tar.gz
tar xvf nginx-1.3.2.tar.gz
cd nginx-1.3.2
2、修改nginx原文件。如果不进行修改,nginx编译会以debug方式编译,编译后的文件有3兆之巨。经以下修改后,文件减小到500KB左右。
vi auto/cc/gcc
  将文件最后的
# debug
CFLAGS=”$CFLAGS -g”
  修改为
# debug
#CFLAGS=”$CFLAGS -g”
3、编译安装nginx。因为在安装FreeBSD的时候,已经内建了www用户和www用户组,因此不需要在自己建立了。这是与在Linux上安装的一个小小区别。
./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module
make -j 2 && make install
如果要开机后自动启动nginx,那么需要在/etc/rc.local中加入一行命令:
/usr/local/nginx/sbin/nginx
##安装mysql ##安装mysql ##安装mysql ##安装mysql ##安装mysql ##安装mysql ##安装mysql ##安装mysql
##安装mysql 因为安装PHP需要用到MySQL支持,所以要先于PHP安装
fetch http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.25a-freebsd8.0-x86_64.tar.gz
tar xvf mysql-5.5.25a-freebsd8.0-x86_64.tar.gz
cp -a mysql-5.5.25a-freebsd8.0-x86_64 /usr/local/mysql
1、创建mysql 的用户及用户组(这点与Linux稍有不同)
pw groupadd mysql
pw useradd mysql -g mysql -d /data/mysql -s /usr/sbin/nologin
  2、创建MySQL数据存放目录
mkdir -p /data/mysql/data/
chown -R mysql:mysql /data/mysql/
  3、以mysql用户的身份建立数据表
/usr/local/mysql/scripts/mysql_install_db –basedir=/usr/local/mysql –datadir=/data/mysql/data –user=mysql
*************
*********************************
  4、创建配置文件 ###good
*******************************
cp /usr/src/mysql-5.5.25a-freebsd8.0-x86_64/support-files/my-medium.cnf /etc/my.cnf
##如果没有加入这 几行
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /data/mysql/data/
tmpdir = /tmp
cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
echo ‘mysql_enable=”YES”‘ >> /etc/rc.conf
cd /usr/local/mysql/support-files ###mysql-5.5.25a-freebsd8.0-x86_64 用 这个也
cp mysql.server /usr/local/mysql/mysqld
chmod 755 /usr/local/mysql/mysqld
/usr/local/mysql/bin/mysqld_safe &
  5、打开/etc/rc.local,如果不存在的话,就新建一个,输入以下内容:
/usr/local/mysql/mysqld start
  6、创建一个可以远程登录的root账户,密码是123456,这样我们就可以使用mysql连接工具进行远程管理了。
/usr/local/mysql/mysqld start
/usr/local/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘123456’;
quit
/usr/local/mysql/bin/mysqladmin -u root password ‘2240881’
/usr/local/mysql/bin/mysql -uroot -p
echo ” >> /etc/profile
echo ‘PATH=/usr/local/mysql/bin:$PATH’ >> /etc/profile
echo ‘export PATH’ >> /etc/profile
三、编译安装PHP(FastCGI)
1、编译安装PHP 5.2.10所需的支持库
##这个好像安装了 ports wget时 好像有呀
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz
fetch http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar xvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure –prefix=/usr
make &&make install ;
cd ..
fetch http://cdnetworks-kr-1.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2
tar xxvf libmcrypt-2.5.8.tar.bz2
cd libmcrypt-2.5.8
./configure –prefix=/usr
make
make install
cd ..
fetch http://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure –prefix=/usr
make -j 2 && make install
cd ..
fetch http://cdnetworks-kr-1.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
vi src/rfc2440.c
##不改是不行的啦
  FreeBSD与Linux的不同点,造成需要对 mcrypt 的源码进行一下小小的修改,才能在FreeBSD下编译通过。将其中的
#include
  修改为
#include
  然后继续编译
./configure –prefix=/usr
make -j2 && make install
cd ..
fetch ftp://xmlsoft.org/libxml2/libxml2-2.7.8.tar.gz
tar xvf ibxml2-2.7.8.tar.gz
cd libxml2-2.7.8
./configure –prefix=/usr
make -j2 && make install clean
cd ..
##或者下面这个
cd /usr/ports/textproc/libxml2
make install clean
fetch http://curl.haxx.se/download/curl-7.26.0.tar.bz2
tar xvf curl-7.26.0.tar.bz2
cd curl-7.26.0
./configure –prefix=/usr
make -j2 && make install clean
cd ..
fetch http://www.ijg.org/files/jpegsrc.v8d.tar.gz
tar xvf jpegsrc.v8d.tar.gz
cd jpeg-8d/
./configure –prefix=/usr
make -j2 && make install clean
cd ..
fetch http://nchc.dl.sourceforge.net/project/libpng/libpng15/1.5.11/libpng-1.5.11.tar.gz
tar xvf libpng-1.5.11.tar.gz
cd libpng-1.5.11
./configure –prefix=/usr
make -j2 && make install clean
cd ..
##ports 下载的url
http://heanet.dl.sourceforge.net/project/freetype/freetype2/2.4.9/freetype-2.4.9.tar.bz2
#fetch http://download.savannah.gnu.org/releases/freetype/freetype-2.4.10.tar.bz2
#tar xvf freetype-2.4.10.tar.bz2
#cd freetype-2.4.10/
fetch http://heanet.dl.sourceforge.net/project/freetype/freetype2/2.4.9/freetype-2.4.9.tar.bz2
tar xvf freetype-2.4.9.tar.bz2
cd freetype-2.4.9
./configure –prefix=/usr
make -j2 && make install clean
cd ..
evan# ./configure –prefix=/usr
GNU make (>= 3.80) or makepp (>= 1.19) is required to build FreeType2.
Please try
`GNUMAKE= ./configure’.
or >&2
`GNUMAKE=”makepp –norc-substitution” ./configure’.
evan#
evan# make -j2 && make install clean
“./builds/toplevel.mk”, line 41: Need an operator
“./builds/toplevel.mk”, line 42: Missing dependency operator
Error expanding embedded variable.
**************
## src2
cd /usr/ports/print/freetype
make install clean
##这个是必要的,上面那个可以不要
cd /usr/ports/print/freetype2
make install clean
  2、编译安装PHP 5.2.10
wget http://cn.php.net/distributions/php-5.4.4.tar.bz2
#wget http://www.php.net/get/php-5.2.10.tar.gz/from/this/mirror
#wget http://php-fpm.org/downloads/php-5.2.10-fpm-0.5.11.diff.gz
wget http://cn2.php.net/distributions/php-5.2.17.tar.gz
fetch http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
#tar zxvf php-5.2.10.tar.gz
#gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1
#cd php-5.2.10/
tar xvf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-iconv-dir=/usr –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr/local –enable-xml –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-xmlrpc –enable-zip –disable-ipv6 –without-pear
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp php.ini-dist /usr/local/php/etc/php.ini
###
 3、安装PHP扩展
  安装扩展前,有些扩展需要一些包支持,所以先要安装以下包。
##其实是2.69
cd /usr/ports/devel/autoconf
make install clean
  接下来就可以顺利安装PHP扩展了。
#wget http://pecl.php.net/get/memcache-2.2.5.tgz
fetch http://pecl.php.net/get/memcache-2.2.6.tgz
tar zxvf memcache-2.2.6.tgz
cd memcache-2.2.6
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make -j 2 && make install
cd ..
#wget http://bart.eaccelerator.net/sou … tor-0.9.5.3.tar.bz2
http://sourceforge.net/projects/eaccelerator/files/eaccelerator
fetch http://nchc.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2
#tar jxvf eaccelerator-0.9.5.3.tar.bz2
#cd eaccelerator-0.9.5.3
tar xvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
/usr/local/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php/bin/php-config
make -j 2 && make install
cd ..
fetch http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config –with-pdo-mysql=/usr/local/mysql
make -j 2 && make install
cd ..
#wget ftp://mirror.aarnet.edu.au/pub/I … gick-6.5.4-2.tar.gz
#tar zxvf ImageMagick-6.5.4-2.tar.gz
#cd ImageMagick-6.5.4-2
#fetch ftp://ftp.kddlabs.co.jp/graphics/ImageMagick/ImageMagick-6.7.8-1.tar.bz2
##这个编译起来有点久的
fetch http://imagemagick.mirrorcatalogs.com/ImageMagick-6.7.8-2.tar.bz2
tar xvf ImageMagick-6.7.8-2.tar.bz2
cd ImageMagick-6.7.8-2
./configure
make -j2 && make install
cd ..
#wget http://pecl.php.net/get/imagick-2.2.2.tgz
#tar zxvf imagick-2.2.2.tgz
#cd imagick-2.2.2
fetch http://pecl.php.net/get/imagick-3.0.1.tgz
tar xvf imagick-3.0.1.tgz
cd imagick-3.0.1
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make -j2 &&make install
cd ..
  4、修改php.ini
vi /usr/local/php/etc/php.ini
##把原来的注释 加下面
查找output_buffering = Off
修改为output_buffering = On
再查找extension_dir = “./”
修改为 extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”
并在此行后增加以下几行,然后保存:
extension = “memcache.so”
extension = “pdo_mysql.so”
extension = “imagick.so”
  5、配置eAccelerator,加速PHP
mkdir -p /data/php/eaccelerator_cache
vi /usr/local/php/etc/php.ini
  在文件末尾增加下面的内容。
[eaccelerator]
zend_extension=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/data/php/eaccelerator_cache”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=””
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”3600″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
  6、开机启动php-fpm
vi /etc/rc.local
增加下面语句
/usr/local/php/sbin/php-fpm start
##错误 /libexec/ld-elf.so.1: Shared object “libmysqlclient.so.18”
cd /usr/src/PDO_MYSQL-1.0.2
evan# ldconfig /usr/local/mysql/lib
evan# /usr/local/php/sbin/php-fpm start
Starting php_fpm /libexec/ld-elf.so.1: Shared object “libmysqlclient.so.18” not found, required by “php-cgi”
failed
Starting php_fpm Nov 05 05:44:48.271363 [ERROR] fpm_unix_conf_wp(), line 124: please specify user and group other than root, pool ‘default’
vi /usr/local/php/etc/php-fpm.conf ##可以参考一下frg 或者把 nobody 改成www
Unix user of processes
nobody
Unix group of processes
nobody
#自启动
vi /etc/rc.local
/usr/local/mysql/mysqld start
/usr/local/nginx/sbin/nginx
/usr/local/php/sbin/php-fpm start
问题
evan# /usr/local/php/sbin/php-fpm start
Starting php_fpm /libexec/ld-elf.so.1: Shared object “libmysqlclient.so.18” not found, required by “php-cgi”
failed
解决
evan# ldconfig /usr/local/mysql/lib
ln -s /usr/local//mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
#####
evan# /usr/local/nginx/sbin/nginx
/libexec/ld-elf.so.1: Shared object “libpcre.so.1” not found, required by “nginx”
  四、配置nginx使其支持PHP
  1、创建网站根目录
mkdir -p /data/www
chmod +w /data/www
chown -R www:www /data/www
  2、创建PHP测试页
vi /data/www/index.php
在文件中输入以下内容

  3、修改 /usr/local/nginx/conf/nginx.conf 如下:
user www www;
worker_processes 8;
events {
use kqueue;
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
tcp_nodelay on;
server {
listen 80;
server_name a.com 192.168.1.99;
root /data/www;
index index.html index.php;
location ~ .*.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Starting php_fpm /libexec/ld-elf.so.1: Shared object “libmysqlclient.so.18” 库文件等 参考
http://linuxjcq.blog.51cto.com/3042600/751032
  至此,环境已经搭建完毕。重启机器后打开浏览器,在地址栏输入:http://192.168.1.99/ or a.com,应该可以正确显示PHP信息页。
Starting php_fpm eAccelerator: shmmax should be at least 2MBPHP Warning: [eAccelerator] Can not create shared memory area in Unknown on line 0
PHP Fatal error: Unable to start eAccelerator module in Unknown on line 0
vi /etc/sysctl.conf
#在文件末尾加入以下代码
kern.ipc.shmmax=67108864
kern.ipc.shmall=32768
http://blog.jiqila.com/post/221/
FreeBSD环境下PHP 5.3.3无法加载eAccelerator的解决方法 http://www.sungyism.com/blog/post/26/
chown -R www:www /data/www/
############################################################################################################################################################