




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
FreeBSD环境下以编译源码方式搭建nginx+php+mysql的手册.txt心若无尘,一花一世界,一鸟一天堂。我曾经喜欢过你,现在我依然爱你希望月亮照得到的地方都可以留下你的笑容那些飘满雪的冬天,那个不带伞的少年,那句被门挡住的誓言,那串被雪覆盖的再见更多分享资料请浏览/gdfz(孤独疯子的涂鸦之地)前言:在网上Linux环境下搭建nginx+php的文章已经比较多也比较完善了,而在FreeBSD环境下搭建的文章并不多,且都使用的是 ports方式安装。本文的目的就是形成一个比较完整的、可操作强的FreeBSD环境下以编译源码方式搭建nginx+php+mysql的手册。本文将尽量详细地描述每一个操作步骤,使初学者也能迅速搭建一个FEMP环境。Nginx简介:Nginx (engine x) 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器 。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的Rambler.ru 站点开发的,它已经在该站点运行超过四年多了。Igor 将源代码以类BSD许可证的形式发布。自Nginx 发布四年来,Nginx 已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。目前国内各大门户网站已经部署了Nginx,如新浪、网易、腾讯等;国内几个重要的视频分享网站也部署了Nginx,如六房间、酷6等。新近发现Nginx 技术在国内日趋火热,越来越多的网站开始部署Nginx。FreeBSD系统分区的时候,根据自己的需要来做。以下的安装,我都是以我的分区为例。引用硬盘总大小:160GB/ 512MBswap 4GB/var 3GB/tmp 512MB/usr 50GB/data 40GB/home 55GBFreeBSD不同于Linux,我们最小化安装FreeBSD后,系统中并没有wget(可能完全安装也没有,呵呵),因为我已经习惯了使用wget进行下载,所以为了可以在FreeBSD中使用wget,我们需要安装wget,方法如下:引用cd /usr/ports/ftp/wgetmake install clean#在出现的对话框中去掉IPV6前面的选择刚刚安装完后,wget并未能使用,需要执行下面的命令后方可生效。引用rehash一、首先,我们来安装nginx。安装Nginx前,需要先安装pcre,因为nginx需要pcre支持。FreeBSD 7.2-Release已经包含了pcre 7.9,所以选择安装Package的时候,选择上pcre即可。或者使用ports方式安装pcre。ports方式安装如下:引用cd /usr/ports/devel/pcremake install clean1、下载与解压nginx引用wget http:/sysoev.ru/nginx/nginx-0.7.64.tar.gz tar zxvf nginx-0.7.64.tar.gz cd nginx-0.7.642、修改nginx原文件。如果不进行修改,nginx编译会以debug方式编译,编译后的文件有3兆之巨。经以下修改后,文件减小到500KB左右。引用cd auto/ccvi gcc将文件最后的引用# debugCFLAGS=$CFLAGS -g修改为引用# debug#CFLAGS=$CFLAGS -g3、编译安装nginx。因为在安装FreeBSD的时候,已经内建了www用户和www用户组,因此不需要在自己建立了。这是与在Linux上安装的一个小小区别。引用cd ./././configure -user=www -group=www -prefix=/usr/local/nginx -with-http_stub_status_module -with-http_ssl_module make make install如果要开机后自动启动nginx,那么需要在/etc/rc.local中加入一行命令:引用/usr/local/nginx/sbin/nginx二、接下来,我们来安装MySQL,因为安装PHP需要用到MySQL支持,所以要先于PHP安装。引用wget /get/Downloads/MySQL-5.1/mysql-5.1.42.tar.gz/from//tar zxvf mysql-5.1.42.tar.gz cd mysql-5.1.42./configure -prefix=/usr/local/mysql/ -enable-assembler -with-extra-charsets=complex -enable-thread-safe-client -with-big-tables -with-readline -with-ssl -with-embedded-server -enable-local-infile -with-plugins=innobase -with-mysqld-user=mysql -without-ndb-debug -without-debug -with-charset=utf8 -localstatedir=/data/mysql/datamakemake install#以 MySQL 5.1.42 为例#tar xvf mysql-5.1.42.tar.gz #cd mysql-5.1.42/#./configure prefix=/usr/local/mysql51 # 指定安装目录with-embedded-server enable-assembler with-mysqld-ldflags=-all-static with-client-ldflags=-all-static # 静态编译without-debug without-docs without-man without-readline # 舍去不必要的东东with-charset=utf8 with-collation=utf8_general_ci # 指定编码,建议使用utf8, 默认latin1with-extra-charsets=complex # 添加支持的编码, 根据自己的需求指定enable-thread-safe-client # 线程安全enable-local-infile with-ssl with-libwrap # 附加网络安全支持with-plugins=innobase,heap # 支持 Innodb 及内存表#可以不只定系统平台, 编译程序会自检; 如果指定, Like: with-system-type=i686-redhat-linux-gnu with-machine-type=i686-redhat-linux-gnu 如果你希望在这台服务器上运行MySQL数据库服务端,那么执行以下步骤。1、创建mysql 的用户及用户组(这点与Linux稍有不同)引用pw groupadd mysqlpw useradd mysql -g mysql -d /data/mysql -s /usr/sbin/nologin2、创建MySQL数据存放目录引用mkdir -p /data/mysql/data/ chown -R mysql:mysql /data/mysql/3、以mysql用户的身份建立数据表引用/usr/local/mysql/bin/mysql_install_db -basedir=/usr/local/mysql -datadir=/data/mysql/data -user=mysql4、创建配置文件引用cd /usr/local/mysql/share/mysql cp f /etc/f cp mysql.server /usr/local/mysql/mysqld chmod 755 /usr/local/mysql/mysqld5、打开/etc/rc.local,如果不存在的话,就新建一个,输入以下内容:引用/usr/local/mysql/mysqld start6、创建一个可以远程登录的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三、编译安装PHP(FastCGI)1、编译安装PHP 5.2.12所需的支持库引用wget /pub/gnu/libiconv/libiconv-1.13.tar.gz tar zxvf libiconv-1.13.tar.gz cd libiconv-1.13/ ./configure -prefix=/usrmake make installcd .引用wget /mcrypt/libmcrypt-2.5.8.tar.gz modtime=1171868460&big_mirror=0 tar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8 ./configure -prefix=/usrmake make installcd .引用wget /mhash/mhash-.tar.gz modtime=1175740843&big_mirror=0 tar zxvf mhash-.tar.gz cd mhash- ./configure -prefix=/usrmake make installcd .引用wget /mcrypt/mcrypt-2.6.8.tar.gz modtime=1194463373&big_mirror=0 tar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8cd srcvi rfc2440.cFreeBSD与Linux的不同点,造成需要对 mcrypt 的源码进行一下小小的修改,才能在FreeBSD下编译通过。将其中的引用#include 修改为引用#include 然后继续编译引用./configure -prefix=/usrmakemake installcd .2、编译安装PHP 5.2.12引用wget /get/php-5.2.12.tar.gz/from/this/mirror wget /downloads/php-5.2.12-fpm-0.5.13.diff.gztar zxvf php-5.2.12.tar.gzgzip -cd php-5.2.12-fpm-0.5.13.diff.gz | patch -d php-5.2.12 -p1cd php-5.2.12./buildconf -force./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-pearmake ZEND_EXTRA_LIBS=-liconvmake installcp php.ini-dist /usr/local/php/etc/php.ini3、安装PHP扩展安装扩展前,有些扩展需要一些包支持,所以先要安装以下包。引用cd /usr/ports/devel/autoconf262make install clean接下来就可以顺利安装PHP扩展了。引用wget /get/memcache-2.2.5.tgztar zxvf memcache-2.2.5.tgzcd memcache-2.2.5/usr/local/php/bin/phpize./configure -with-php-config=/usr/local/php/bin/php-configmakemake installcd .引用wget /source//eaccelerator-.tar.bz2tar jxvf eaccelerator-.tar.bz2cd eaccelerator-/usr/local/php/bin/phpize./configure -enable-eaccelerator=shared -with-php-config=/usr/local/php/bin/php-configmakemake installcd .引用wget /get/PDO_MYSQL-1.0.2.tgztar zxvf PDO_MYSQL-1.0.2.tgzcd 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/mysqlmakemake installcd .引用wget .au/pub/imagemagick/ImageMagick-6.5.5-6.tar.gz tar zxvf ImageMagick-6.5.5-6.tar.gzcd ImageMagick-6.5.5-6./configuremakemake installcd .引用有网友提示,按照以上方法安装ImageMagick后,有可能会遇到PHP加载imagick.so后运行错误,解决方法是在编译ImageMagick时关掉openmp: disable-openmp。在此感谢网友Sonic热心提示,谢谢。如果还不行的话,请更换ImageMagick至低版本,比如:6.5.4-2。引用wget /get/imagick-2.2.2.tgztar zxvf imagick-2.2.2.tgzcd imagick-2.2.2/usr/local/php/bin/phpize./configure -with-php-config=/usr/local/php/bin/php-configmakemake installcd .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.soextension = pdo_mysql.soextension = imagick.soextension = eaccelerator.so5、配置eAccelerator,加速PHP引用mkdir -p /data/php/eaccelerator_cachevi /usr/local/php/etc/php.ini在文件末尾增加下面的内容。引用eacceleratoreaccelerator.shm_size=64eaccelerator.cache_dir=/data/php/eaccelerator_cacheeaccelerator.enable=1eaccelerator.optimizer=1eaccelerator.check_mtime=1eaccelerator.debug=0eaccelerator.filter=eaccelerator.shm_max=0eaccelerator.shm_ttl=3600eaccelerator.shm_prune_period=3600eaccelerator.shm_only=0press=1press_level=96、开机启动php-fpm引用vi /etc/rc.local增加下面语句/usr/local/php/sbin/php-fpm start四、配置nginx使其支持PHP1、创建网站根目录引用mkdir -p /data/wwwchmod +w /data/wwwchown -R www:www /data/www2、创建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 ; root /data/www; index index.html index.php; location .*.(php|php5) $ fastcgi_pass :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; 4、修改/usr/local/php/etc/php-fpm.conf文件如下:引用 All relative paths in this config are relative to phps install prefix Pid file /usr/local/php/logs/php-fpm.pid Error log file /usr/local/php/logs/php-fpm.log Log level notice When this amount of php processes exited with SIGSEGV or SIGBUS . 10 . in a less than this interval of time, a graceful restart will be initiated. Useful to work around accidental curruptions in accelerators shared memory. 1m Time limit on waiting childs reaction on signals from master 5s Set to no to debug fpm yes Name of pool. Used in logs and stats. default Address to accept fastcgi requests on. Valid syntax is ip.ad.re.ss:port or just port or /path/to/unix/socket :9000 Set listen(2) backlog -1 Set permissions for unix socket, if one used. In Linux read/write permissions must be set in order to allow connections from web server. Many BSD-derrived systems allow connections regardless of permissions. 0666 Additional php.ini defines, specific to this pool of workers. !- /usr/sbin/sendmail -t -i - 0 Unix user of processes www Unix group of processes www Process manager settings Sets style of controling worker process count. Valid values are static and apache-like static Sets the limit on the number of simultaneous requests that will be served. Equivalent to Apache MaxClients directive. Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi Used with any pm_style. 8 Settings group for apache-like pm style Sets the number of server processes created on startup. Used only when apache-like pm_style is selected 20 Sets the desired minimum number of idle server processes. Used only when apache-like pm_style is selected 5 Sets the desired maximum number of idle server processes. Used only when apache-like pm_style is selected 35 The timeout (in seconds) for serving a single request after which the worker process will be terminated Should be used when max_execution_time ini option does not stop script execution for some
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 安徽省芜湖市繁昌区2024-2025学年高二上学期期中考试英语试题及答案
- 心理分析问答题目及答案
- 小学学科数学题目及答案
- 忘不了作文500字(9篇)
- 合作经营养殖项目合同
- 项目管理计划及预算制定指导性文档模板
- 农民特色农产品购销合同书
- 旬阳县消防知识培训课件
- 纪检基础知识培训课件
- 五角飞碟200字(8篇)
- 中西结合治疗皮肤病
- 人教版小学一年级上体育全册教案
- 街道综合执法培训课件
- 山东省潍坊市2024-2025学年高一上学期期中考试数学试题
- 《山东省建筑工程消耗量定额》解释全集
- 宠物脂肪肝的诊断与治疗
- 木工分包协议书电子版
- 历年制油工题库汇编
- 小学科学教科版三年级下册全册思维导图(共24课)
- (三级)智能云服务交付工程师理论考试题库大全-中(多选题)
- 浙江省中小学心理健康教育课程标准
评论
0/150
提交评论