最近一直在研究freeBSD下nginx+php+mysql的安装,看了很多网上的资料收获不小,不过大部分都是编译安装,相对初学者来说比较复杂,不容易理解,所以我整合了一些ports安装的资料,都是经过自己验证后的,安装成功也比较容易理解,下面是两种成功的案例,其中有一个是Apache代替nginx的安装,希望对大家有所帮助。
安装前更新好ports:
进入系统后,准备
cvs
更新:
1.
cd /usr/ports/net/cvsup-without-gui
2.
cp /usr/share/examples/cvsup/ports-supfile /etc/ports-supfile
3.
# vi /etc/ports-supfile
将其中的
#*default host=CHANGE_THIS.FreeBSD.org
一行改为
*default host=cvsup4.FreeBSDchina.org
4.
更新
ports
/usr/local/bin/cvsup -g -L 2 /etc/ports-supfile
1,freeBSD下Apache+php+mysql安装
安装时必须用root用户或su方式登录后生效
安装配置apache
#cd /usr/ports/www/apache22/
#make config
将mysql勾上
#make install clean
#rehash
#ee /usr/local/etc/apache22/httpd.conf
修改以下配置
ServerAdmin
[email protected]
ServerName 192.168.1.1:80
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#ee /boot/defaults/loader.conf
修改以下配置
accf_data_load="YES"
accf_http_load="YES"
#echo 'apache22_enable="YES"' >> /etc/rc.conf
启动时自动运行apache服务
如果不成功可以:ee /etc/rc.conf 里添加
apache22_enable="YES"
#apachectl start
输入地址看到
It works!表示安装成功.
安装配置php5及php5-extensions
#cd /usr/ports/lang/php5
#make config
apache一定要勾上,不然apache认不出php
#make install clean
#cd /usr/ports/lang/php5-extensions
#make config
选上需要支持的扩展
#make install clean
#cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini
#apachectl restart
重启apache后php就生效了
安装配置mysql
#cd /usr/ports/databases/mysql50-server
#make WITH_CHARSET=gbk WITH_XCHARSET=all WITH_PROC_SCOPE_PTH=yes BUILD_OPTIMIZED=yes BUILD_STATIC=yes SKIP_DNS_CHECK=yes WITHOUT_INNODB=yes install clean
由于这个版本不支持make config,我们只能用参数编译
#rehash
#cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
#echo "default-character-set=utf8" >> /etc/my.cnf
修改数据库默认字符集为UTF-8
#chown -R mysql /var/db/mysql
#/usr/local/bin/mysql_install_db -u mysql
#/usr/local/bin/mysqld_safe &
如果没有报错就说明配置没有问题,接下来可以直接启动数据库
#/usr/local/etc/rc.d/mysql-server start
#mysql -u root -p
测试连接数据库
#echo 'mysql_enable="YES"' >> /etc/rc.conf
启动时自动运行mysql服务
可能遇到的问题
Mysql Server has gone away
意思就是mysql服务器倒掉了。
在freebsd最好采用ports安装mysql,一般没有问题的,我原来也运行过的。
不过现在换成了centos,我觉得更爽些。
以下在我原来在编译mysql时的笔记,有点乱,你看看可能对你有帮助。我想你的问题很可能出在这个地方。WITH_CHARSET=latin1 WITH_COLLATION=latin1_general_ci WITH_XCHARSET=all 建议你用我推荐的编译选项。latin1更适用的。
2,freeBSD下nginx+php+mysql的安装
安装axel提高ports的安装速度
cd /usr/ports/ftp/axel
make install
#修改 /et/make.conf
ee /etc/make.conf
#加入以下内容
FETCH_CMD=axel
FETCH_BEFORE_ARGS= -n 10 -a
FETCH_AFTER_ARGS=
DISABLE_SIZE=yes
MASTER_SITE_OVERRIDE?=\
http://ports.hshh.org/${DIST_SUBDIR}/\
http://ports.cn.freebsd.org/${DIST_SUBDIR}/\
ftp://ftp.freeBSDchina.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}/
MASTER_SITE_OVERRIDE?=${MASTER_SITE_BACKUP}
安装 Mysql5.1.40
cd /usr/ports/databases/mysql51-server
make WITH_CHARSET=gbk WITH_XCHARSET=all WITH_PROC_SCOPE_PTH=yes BUILD_OPTIMIZED=yes BUILD_STATIC=yes SKIP_DNS_CHECK=yes WITHOUT_INNODB=yes install clean
#安装系统数据库
/usr/local/bin/mysql_install_db --user=mysql
cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
#设置 mysql 开机启动
vi /etc/rc.conf
#添加以下内容
mysql_enable="YES"
#启动mysql
/usr/local/etc/rc.d/mysql-server start
安装 Nginx
安装 pcre8.00
pcre 是Nginx 所需的 Perl兼容正则表达式库
cd /usr/ports/devel/pcre
make install
安装 Nginx0.8.24
cd /usr/ports/www/nginx
make install
#配置编译参数
[ ] DEBUG Enable nginx debugging
[ ] IPV6 Enable IPv6
[ ] GOOGLE_PERFTOOLS Enable google perftools module
[X] HTTP_MODULE Enable HTTP module
[ ] HTTP_ADDITION_MODULE Enable http_addition module
[X] HTTP_CACHE_MODULE Enable http_cache module
[ ] HTTP_DAV_MODULE Enable http_webdav module
[ ] HTTP_FLV_MODULE Enable http_flv module
[X] HTTP_GZIP_STATIC_MODULE Enable http_gzip_static module
[ ] HTTP_IMAGE_FILTER_MODULE Enable http_image_filter module
[ ] HTTP_PERL_MODULE Enable http_perl module
[ ] HTTP_RANDOM_INDEX_MODULE Enable http_random_index module
[ ] HTTP_REALIP_MODULE Enable http_realip module
[X] HTTP_REWRITE_MODULE Enable http_rewrite module
[ ] HTTP_SECURE_LINK_MODULE Enable http_secure_link module
[ ] HTTP_SSL_MODULE Enable http_ssl module
[X] HTTP_STATUS_MODULE Enable http_stub_status module
[ ] HTTP_SUB_MODULE Enable http_sub module
[ ] HTTP_XSLT_MODULE Enable http_xslt module
[ ] MAIL_MODULE Enable IMAP4/POP3/SMTP proxy module
[ ] MAIL_IMAP_MODULE Enable IMAP4 proxy module
[ ] MAIL_POP3_MODULE Enable POP3 proxy module
[ ] MAIL_SMTP_MODULE Enable SMTP proxy module
[ ] MAIL_SSL_MODULE Enable mail_ssl module
[ ] WWW Enable html sample files
[ ] HTTP_ACCESSKEY_MODULE 3rd party http_accesskey module
[ ] HTTP_EVAL_MODULE 3rd party eval module
[ ] HTTP_FANCYINDEX_MODULE 3rd party http_fancyindex module
[ ] HTTP_MOGILEFS_MODULE 3rd party mogilefs module
[ ] HTTP_MP4_H264_MODULE 3rd party mp4/h264 module
[ ] HTTP_NOTICE_MODULE 3rd party notice module
[ ] HTTP_REDIS_MODULE 3rd party http_redis module
[ ] HTTP_RESPONSE_MODULE 3rd party http_response module
[ ] HTTP_UPLOAD_MODULE 3rd party upload module
[ ] HTTP_UPLOAD_PROGRESS 3rd party upload_progress module
[ ] HTTP_UPSTREAM_FAIR 3rd party upstream fair module
[ ] HTTP_UPSTREAM_KEEPALIVE 3rd party upstream keepalive module
[ ] HTTP_ZIP_MODULE 3rd party http_zip module
[ ] PASSENGER_MODULE 3rd party passenger module
#修改 nginx 配置文件
vi /usr/local/etc/nginx/nginx.conf
修改配置文件请参考http://wiki.nginx.org/NginxChsFullExample2(来自官方网站)
#设置 mysql 开机启动 vi /etc/rc.conf #添加以下内容 mysql_enable="YES"
#启动nginx /usr/local/etc/rc.d/nginx start
安装 libxml2-2.7.6
cd /usr/ports/textproc/libxml2
make install
安装 GD
安装 libpng1.2.40
cd /usr/ports/graphics/png
make install
安装 jpeg v7
cd /usr/ports/graphics/jpeg
make install
安装 freetype2.3.11
cd /usr/ports/print/freetype2
make install
安装 gd2.0.35
cd /usr/ports/graphics/gd
make install
#配置编译参数
[ ] X11 X11 support
[ ] XPM XPM color bitmap loading support (requires X11)
[ ] FONTCONFIG fontconfig library support (requires X11)
[X] ICONV iconv support
安装 PHP
安装 php5.2.11(FastCGI模式)
cd /usr/ports/lang/php5 make install clean #配置编译参数 [X] CLI Build CLI version [X] CGI Build CGI version [ ] APACHE Build Apache module [ ] DEBUG Enable debug [X] SUHOSIN Enable Suhosin protection system (not for jails) [ ] MULTIBYTE Enable zend multibyte support [ ] IPV6 Enable ipv6 support [ ] MAILHEAD Enable mail header patch [ ] REDIRECT Enable force-cgi-redirect support (CGI only) [ ] DISCARD Enable discard-path support (CGI only) [X] FASTCGI Enable fastcgi support (CGI only) [X] PATHINFO Enable path-info-check support (CGI only) #安装 php5-extensions cd /usr/ports/lang/php5-extensions make install clean #配置编译参数 [ ] BCMATH bc style precision math functions [ ] BZ2 bzip2 library support [ ] CALENDAR calendar conversion support [X] CTYPE ctype functions [X] CURL CURL support [ ] DBA dba support [ ] DBASE dBase library support [X] DOM DOM support [ ] EXIF EXIF support [ ] FILEINFO fileinfo support [X] FILTER input filter support [ ] FRIBIDI FriBidi support [ ] FTP FTP support [X] GD GD library support [ ] GETTEXT gettext library support [ ] GMP GNU MP support [X] HASH HASH Message Digest Framework [X] ICONV iconv support [ ] IMAP IMAP support [ ] INTERBASE Interbase 6 database support (Firebird) [X] JSON JavaScript Object Serialization support [ ] LDAP OpenLDAP support [X] MBSTRING multibyte string support [ ] MCRYPT Encryption support [ ] MHASH Crypto-hashing support [ ] MING ming shockwave flash support [ ] MSSQL MS-SQL database support [X] MYSQL MySQL database support [ ] MYSQLI MySQLi database support [ ] NCURSES ncurses support (CLI only) [ ] ODBC unixODBC support [ ] OPENSSL OpenSSL support [ ] PCNTL pcntl support (CLI only) [X] PCRE Perl Compatible Regular Expression support [ ] PDF PDFlib support (implies GD) [X] PDO PHP Data Objects Interface (PDO) [X] PDO_SQLITE PDO sqlite driver [ ] PGSQL PostgreSQL database support [X] POSIX POSIX-like functions [ ] PSPELL pspell support [ ] READLINE readline support (CLI only) [ ] RECODE recode support [X] SESSION session support [ ] SHMOP shmop support [X] SIMPLEXML simplexml support [ ] SNMP SNMP support [ ] SOAP SOAP support [ ] SOCKETS sockets support [X] SPL Standard PHP Library [ ] SQLITE sqlite support [ ] SYBASE_CT Sybase database support [ ] SYSVMSG System V message support [ ] SYSVSEM System V semaphore support [ ] SYSVSHM System V shared memory support [ ] TIDY TIDY support [X] TOKENIZER tokenizer support [ ] WDDX WDDX support (implies XML) [X] XML XML support [X] XMLREADER XMLReader support [ ] XMLRPC XMLRPC-EPI support [X] XMLWRITER XMLWriter support [ ] XSL XSL support (Implies DOM) [ ] YAZ YAZ support (ANSI/NISO Z39.50) [ ] ZIP ZIP support [X] ZLIB ZLIB support #安装过程中遇到的软件配置编译参数默认选择即可
安装 ZendOptimizer3.3.9
whereis ZendOptimizer
cd /usr/ports/devel/ZendOptimizer
make install clean
本人是新手,中间有错误的地方还请大家见谅,欢迎留言互相学习。