FNMP (Fcgi, Nginx, Mysql and Php)
freebsd8.2 下ports 安装配置 nginx+mysql+php-fpm
因为php需要mysql支持,所以,我一般按照mysql+php+nginx的步奏来安装.
1 安装 mysql 5.1版本
(mysql55版本老编译不过去,还是采用稳妥的51来安装)
cd /usr/ports/databases/mysql51-server
make WITH_CHARSET=utf8 WITH_XCHARSET=all WITH_COLLATION=utf8_general_ci install clean
启动
添加以下内容到/etc/rc.conf中
配置
/usr/local/etc/rc.d/mysql-server start
给root帐号添加密码
mysqladmin -u root password 'MyPassword'
service mysql-server restart
*mysql重新启动
mysql -u root -p
show variables like 'char%';
*设定编码察看
配置文件
挑选下面的配置拷贝到/etc目录
比如# cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
/usr/local/share/mysql/my-huge.cnf
/usr/local/share/mysql/my-innodb-heavy-4g.cnf
/usr/local/share/mysql/my-large.cnf
/usr/local/share/mysql/my-medium.cnf
/usr/local/share/mysql/my-small.cnf
2 安装php53+php-fpm
安装
cd /usr/ports/lang/php5
make install clean
cd /usr/ports/lang/php5-extension
make install clean
我这里主要选择了以下几个
[X] BCMATH bc style precision math functions
[X] BZ2 bzip2 library support
[X] CURL CURL support[X] FTP FTP support
[X] GD GD library support
[X] ICONV iconv support[X] MCRYPT Encryption support
[X] MHASH Crypto-hashing support
[X] MYSQL MySQL database support
*重要mysql支持
[X] MYSQLI MySQLi database support
*重要mysql支持
[X] OPENSSL OpenSSL support[X] PCRE Perl Compatible Regular Expression support
[X] XML XML support[X] XMLREADER XMLReader support
[X] XMLWRITER XMLWriter support
[X] ZLIB ZLIB support
配置
1 php
在freebsd默认安装的是没有配置文件的,需要你自己拷贝一个
cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
php.ini-development 开发测试版本 php.ini-production 生产适用版本
2 php_fpm
配置文件 /usr/local/etc/php-fpm.conf
启动
在 /etc/rc.conf 中添加
php_fpm_enable="YES"
启动php-fpm
# /usr/local/etc/rc.d/php-fpm start
3 安装nginx
cd /usr/ports/www/nginx
make install clean
这里除了默认主要添加了ssl支持这个选项,其他就选择默认就可以了
[X] HTTP_SSL_MODULE Enable http_ssl module
[X] HTTP_STATUS_MODULE Enable http_stub_status module
[X] WWW Enable html sample files
编译完成后,启动 nginx
- # echo nginx_enable="YES" >> /etc/rc.conf
这里先不急着 start nginx,因为现在还没有对 PHP 的支持。
- # vi /usr/local/etc/nginx/nginx.conf
将如下段落前的 “#” 删除,并且将 html 更改为 /usr/local/www/nginx
location ~ \.php$ {
root /usr/local/www/nginx;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
结束后,编辑 /usr/local/etc/nginx/fastcgi_params,加入
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
启动 nginx,看看是否已经对 PHP 了
- # /usr/local/etc/rc.d/nginx start
- # echo "" > /usr/local/www/nginx/info.php
vi /usr/local/www/nginx/info.php
在文件中输入以下内容
phpinfo();
?>
访问 http://yourdomain/info.php,看到 phpinfo 的页面则证明无误。
参考 :
Nginx + PHP-FPM + MySQL On FreeBSD 8.2
nginx + PHP-FPM + MySQL + eAccelerator FreeBSD 8.0 安装笔记
FreeBSD上搭建nginx 0.8.x + PHP 5.3.x(FastCGI) + MySQL 5.1.x