FreeBSD+Nginx+FastCGI PHP+MySQL伺服器

來源:互聯網
上載者:User

聽說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


可以把phpmyadmin和phpinfo.php放到網站根目錄,/wwwroot,瀏覽效果。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.