FreeBSD+Nginx+FastCGI PHP+MySQL服务器

听说Nginx很强,公司的运维总提起Nginx,今天自己动手重装了自己的服务器。服务器系统还是用FreeBSD系统,这次采用了新的7.2版本。

所需软件:

nginx 0.6.38

spawn-fcgi-1.6.0

php5-5.2.9

MySQL 5.0.77

proftpd-1.3.2

memcached-1.2.6_1 

1、安装系统,系统安装用了不到15分钟,选择最小安装,选择了Ports、Perl、Python等几个必要的包。开启ssh。

2、使用Ports 安装了php5、vim、spawn-fcgi、memcached,这样做有一个好处,FreeBSD系统,会把一些基本的lib都自动安装上。比如libxml2、libzip、libgd2、libjpeg,还有一些常用的基本软件也都会安装上。

Ports安装mysql发现,mysql下载不了了。php5选择ports其实,并不是真的要用它,实际用的时候是自己下载编译安装的。

3、下载了一份MySQL,编译安装。

Sh代码
#./configure with_charset=utf8 with_charset=gbk with_charset=gb2312 \    
with_xcharset=all with_proc_scope_pth=yes build_optimized=yes \    
build_static=yes skip_dns_check=yes PREFIX=/usr/local/mysql #addgroup mysql    
#adduser mysql    
#cd /usr/local/mysql    
#./bin/mysql_install_db --basedir = /usr/local/mysql/ --datadir=/wwwroot/databases   
#./configure with_charset=utf8 with_charset=gbk with_charset=gb2312 \ with_xcharset=all with_proc_scope_pth=yes build_optimized=yes \ build_static=yes skip_dns_check=yes PREFIX=/usr/local/mysql #addgroup mysql #adduser mysql #cd /usr/local/mysql #./bin/mysql_install_db --basedir = /usr/local/mysql/ --datadir=/wwwroot/databases
 

需要把my.cnf复制到/etc/my.cnf,然后配置文件中加入

[mysqld] datadir=/wwwroot/databases

./bin/mysqld_safe --user=mysql &

4、安装了一个elinks,elinks到php.net,下载了一份php5.2.9,解压

Java代码
#tar xvf php5.2.9.tar.bz2    
  
#./configure --prefix=/usr/local/php --with-gd --enable-fastcgi --enable-ftp\   
 --with-zlib --enable-mbstring --with-mcrypt --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql \   
--enable-zip --with-pear   
#tar xvf php5.2.9.tar.bz2 #./configure --prefix=/usr/local/php --with-gd --enable-fastcgi --enable-ftp\ --with-zlib --enable-mbstring --with-mcrypt --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql \ --enable-zip --with-pear
 

php.ini-dist复制到/usr/local/php/lib/php.ini,然后修改一下配置文件,开启所需的扩展。

5、Nginx也是ports安装的

cd /usr/ports/www/nginx/

make install clean PREFIX=/usr/local/nginx

注意:安装nginx之前需要有pcre包。ports安装之前先安装pcre。如果安装nginx的时候,自动安装pcre,就会把pcre安装到/usr/local/nginx,nginx就会找不到/usr/local的pcre而报错。

6、配置nginx

Java代码
events {    
  
        worker_connections 1024;    
  
        use kqueue; #FreeSBD下要启用kqueue,Linux下是epoll    
  
}    
events { worker_connections 1024; use kqueue; #FreeSBD下要启用kqueue,Linux下是epoll }  
 

Java代码
location ~ \.php$ {   
  
        include fcgi.conf;    
  
        fastcgi_pass 127.0.0.1:9000;    
  
        fastcgi_index index.php;    
  
}   
location ~ \.php$ { include fcgi.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; }
 

配置fcgi.conf nginx自带那个配置文件fastcgi_param,缺少一条

Java代码
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;    
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
$document_root就是php程序的根目录。如果nginx的虚拟主机中有这一条,可以引用变量。如果没有,就填写绝对路径。/wwwroot$fastcgi_script_name;

7、现在就可以启动服务器了

Sh代码
#spawn-fcgi -a 127.0.0.1 -C 10 -p 9000 -u www -g www -f /usr/local/php/bin/php-cgi    
#nginx   
#spawn-fcgi -a 127.0.0.1 -C 10 -p 9000 -u www -g www -f /usr/local/php/bin/php-cgi #nginx
 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wydfzj.html