FreeBSD下配置Nginx+php+mysql高性能web服务器
概述:
FreeBSD版本8.4
Nginx版本1.6
php版本5.4
mysql版本5.6
在配置之前要先更新系统,在root模式下输入如下命令查看pkg安装工具版本,如果版本低于1.4,那么需要更新才可使用:
配置环境的服务器要能上网,因为需要直接从官方资源站点下载配置包。
将看到如下信息,系统提示需要安装pkg工具:
root@localhost:/usr/home/root001 # pkg info
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]:
选择yes
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg please wait
_http._tcp.pkg.FreeBSD.org
Installing pkg-1.4.7...
Extracting pkg-1.4.7: 100%
Message for pkg-1.4.7:
If you are upgrading from the old package format, first run:
pkg: PACKAGESITE in pkg.conf is no longer supported. Convert to the new repository style. See pkg.conf(5)
pkg: Cannot parse configuration file!
系统提示运行pkg2ng 此时配置文件和内部数据库还未更新
pkg: PACKAGESITE in pkg.conf is no longer supported. Convert to the new repository style. See pkg.conf(5)
pkg: Cannot parse configuration file!
Analysing shared libraries, this will take a while...
pkg: PACKAGESITE in pkg.conf is no longer supported. Convert to the new repository style. See pkg.conf(5)
pkg: Cannot parse configuration file!
更新系统安装包,在/usr/ports/下运行如下命令:
root@localhost:/usr/ports # portsnap fetch
Looking up portsnap.FreeBSD.org mirrors... 7 mirrors found.
Fetching public key from ec2-ap-southeast-2.portsnap.freebsd.org... done.
Fetching snapshot tag from ec2-ap-southeast-2.portsnap.freebsd.org... done.
Extracting snapshot... done.
Verifying snapshot integrity... done.
Fetching snapshot tag from ec2-ap-southeast-2.portsnap.freebsd.org... done.
Fetching snapshot metadata... done.
Updating from Mon Feb 9 08:16:34 CST 2015 to Mon Feb 9 23:26:07 CST 2015.
Fetching 4 metadata patches... done.
Applying metadata patches... done.
Fetching 0 metadata files... done.
Fetching 33 patches.....10....20....30. done.
Applying patches... done.
Fetching 3 new ports or files... done.
root@localhost:/usr/ports #
然后运行释放更新命令,这个时间稍微久一些:
root@localhost:/usr/ports # portsnap extract
然后更新目录和数据库:
root@localhost:/usr/ports # portsnap fetch update
Looking up portsnap.FreeBSD.org mirrors... 7 mirrors found.
Fetching snapshot tag from ec2-ap-southeast-2.portsnap.freebsd.org... done.
Fetching snapshot metadata... done.
Updating from Mon Feb 9 23:26:07 CST 2015 to Mon Feb 9 23:43:52 CST 2015.
Fetching 1 metadata patches. done.
Applying metadata patches... done.
Fetching 0 metadata files... done.
Fetching 1 patches. done.
Applying patches... done.
Fetching 0 new ports or files... done.
Removing old files and directories... done.
Extracting new files:
/usr/ports/cad/pcb/
Building new INDEX files... done.
//开始编译安装pkg工具
root@localhost:/usr/ports # make && make install clean
或者:
root@localhost:/usr/ports/ports-mgmt/pkg # pkg_add -r pkg
............................
checking for arc4random_uniform... (cached) yes
checking for chflags... yes
checking for chflagsat... no
checking whether we should only build the static version of pkg... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating external/Makefile
config.status: creating scripts/Makefile
config.status: creating docs/Makefile
config.status: creating tests/Makefile
config.status: creating libpkg/Makefile
config.status: creating libpkg/repo/Makefile
config.status: creating libpkg/pkg.h
config.status: creating libpkg/pkg.pc
config.status: creating scripts/periodic/400.status-pkg
config.status: creating scripts/periodic/410.pkg-audit
config.status: creating scripts/periodic/411.pkg-backup
config.status: creating scripts/periodic/460.pkg-checksum
config.status: creating scripts/periodic/490.status-pkg-changes
config.status: creating scripts/sbin/pkg2ng
config.status: creating scripts/completion/_pkg.bash
config.status: creating scripts/completion/_pkg
config.status: creating libpkg/repo/binary/Makefile
config.status: creating pkg_config.h
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing pkg_repos.h commands
config.status: executing mkdir commands
===> Building for pkg-1.4.10
/usr/bin/make all-recursive
CC libucl/src/libucl_la-ucl_emitter.lo
CC libucl/src/libucl_la-ucl_emitter_utils.lo
CC libucl/src/libucl_la-ucl_emitter_streamline.lo
CC libucl/src/libucl_la-ucl_hash.lo
CC libucl/src/libucl_la-ucl_parser.lo
CC libucl/src/libucl_la-ucl_schema.lo
CC libucl/src/libucl_la-ucl_util.lo
CC libucl/src/libucl_la-xxhash.lo
libucl/src/ucl_schema.c: In function ‘ucl_schema_validate‘:
libucl/src/ucl_schema.c:885: warning: ‘ret‘ may be used uninitialized in this function
CC libucl/src/libucl_static_la-ucl_emitter.lo
CC libucl/src/libucl_static_la-ucl_emitter_utils.lo
CC libucl/src/libucl_static_la-ucl_emitter_streamline.lo
CC libucl/src/libucl_static_la-ucl_hash.lo
CC libucl/src/libucl_static_la-ucl_parser.lo
CC libucl/src/libucl_static_la-ucl_schema.lo
CC libucl/src/libucl_static_la-ucl_util.lo
libucl/src/ucl_schema.c: In function ‘ucl_schema_validate‘:
libucl/src/ucl_schema.c:885: warning: ‘ret‘ may be used uninitialized in this function
CC libucl/src/libucl_static_la-xxhash.lo
CC sqlite/libsqlite_la-sqlite3.lo
CC sqlite/libsqlite_la-shell.lo
sqlite/sqlite3.c: In function ‘sqlite3BtreeBeginTrans‘:
sqlite/sqlite3.c:54924: warning: unused variable ‘pBlock‘
sqlite/sqlite3.c: In function ‘balance_nonroot‘:
sqlite/sqlite3.c:59023: warning: unused variable ‘key‘
CC sqlite/libsqlite_static_la-sqlite3.lo
CC sqlite/libsqlite_static_la-shell.lo
sqlite/sqlite3.c: In function ‘sqlite3BtreeBeginTrans‘:
sqlite/sqlite3.c:54924: warning: unused variable ‘pBlock‘
sqlite/sqlite3.c: In function ‘balance_nonroot‘:
sqlite/sqlite3.c:59023: warning: unused variable ‘key‘
CC expat/lib/libexpat_la-xmlparse.lo
CC expat/lib/libexpat_la-xmlrole.lo
CC expat/lib/libexpat_la-xmltok.lo
CC expat/lib/libexpat_static_la-xmlparse.lo
CC expat/lib/libexpat_static_la-xmlrole.lo
CC expat/lib/libexpat_static_la-xmltok.lo
CC libsbuf/libsbuf_la-subr_sbuf.lo
CC libsbuf/libsbuf_static_la-subr_sbuf.lo
CC picosat/libpicosat_la-picosat.lo
CC picosat/libpicosat_la-version.lo
CC picosat/libpicosat_static_la-picosat.lo
....................
.............................................
===> Installing for pkg-1.4.10
===> Checking if pkg already installed
===> Registering installation for pkg-1.4.10
Installing pkg-1.4.10...
If you are upgrading from the old package format, first run:
root@localhost:/usr/ports/ports-mgmt/pkg # pkg2ng
Converting packages from /var/db/pkg
Analysing shared libraries, this will take a while...
Checking all packages: 100%
root@localhost:/usr/ports/ports-mgmt/pkg # ls
Makefile distinfo files pkg-descr pkg-message pkg-plist work
For more information on available commands and options see ‘pkg help‘.
//然后更新pkg
root@localhost:/usr/ports/ports-mgmt/pkg # pkg update
Updating FreeBSD repository catalogue...
Fetching meta.txz: 100% 968 B 1.0kB/s 00:01
Fetching packagesite.txz: 100% 5 MiB 58.1kB/s 01:31
Processing entries: 100%
FreeBSD repository update completed. 23775 packages processed
root@localhost:/usr/ports/ports-mgmt/pkg #
//此时在看pkg版本
root@localhost:/usr/ports/ports-mgmt/pkg # pkg -v
1.4.10
此时pkg更新完毕
支持程序全部安装,web服务器我们需要nginx php5 及php5-extensions扩展,此扩展包含了gd等的扩展程序
pecl扩展,mysql数据库
如下:
root@localhost:/usr/local # pkg install nginx php5 php5-extensions pecl-APC mysql56-server
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
Updating database digests format: 100%
The following 28 packages will be affected (of 0 checked):
nginx: 1.6.2_1,2
php5: 5.4.37
php5-extensions: 1.7
pecl-APC: 3.1.14_1
mysql56-server: 5.6.22
pcre: 8.35_2
libxml2: 2.9.2_2
libiconv: 1.14_6
php5-session: 5.4.37
php5-xmlwriter: 5.4.37
php5-xmlreader: 5.4.37
php5-dom: 5.4.37
php5-xml: 5.4.37
php5-simplexml: 5.4.37
php5-ctype: 5.4.37
php5-posix: 5.4.37
php5-hash: 5.4.37
php5-filter: 5.4.37
php5-tokenizer: 5.4.37
php5-json: 5.4.37
php5-sqlite3: 5.4.37_1
sqlite3: 3.8.8.1
php5-pdo_sqlite: 5.4.37_1
php5-pdo: 5.4.37
php5-iconv: 5.4.37
php5-phar: 5.4.37
perl5: 5.18.4_11
mysql56-client: 5.6.22
28 MiB to be downloaded.
///选择“y”pkg会自动将所需包全部安装完毕
Proceed with this action? [y/N]: y
Fetching nginx-1.6.2_1,2.txz: 100% 239 KiB 49.0kB/s 00:05
Fetching php5-5.4.37.txz: 100% 1 MiB 63.0kB/s 00:28
Fetching php5-extensions-1.7.txz: 100% 1 KiB 1.1kB/s 00:01
Fetching pecl-APC-3.1.14_1.txz: 100% 94 KiB 48.6kB/s 00:02
Fetching mysql56-server-5.6.22.txz: 100% 8 MiB 49.5kB/s 02:50
Fetching pcre-8.35_2.txz: 100% 1 MiB 58.7kB/s 00:19
Fetching libxml2-2.9.2_2.txz: 100% 709 KiB 66.0kB/s 00:11
Fetching libiconv-1.14_6.txz: 100% 594 KiB 60.9kB/s 00:10
Fetching php5-session-5.4.37.txz: 100% 29 KiB 29.7kB/s 00:01
Fetching php5-xmlwriter-5.4.37.txz: 100% 12 KiB 13.0kB/s 00:01
Fetching php5-xmlreader-5.4.37.txz: 100% 13 KiB 13.4kB/s 00:01
Fetching php5-dom-5.4.37.txz: 100% 54 KiB 56.0kB/s 00:01
Fetching php5-xml-5.4.37.txz: 100% 19 KiB 19.8kB/s 00:01
Fetching php5-simplexml-5.4.37.txz: 100% 21 KiB 21.5kB/s 00:01
Fetching php5-ctype-5.4.37.txz: 100% 6 KiB 6.7kB/s 00:01
Fetching php5-posix-5.4.37.txz: 100% 11 KiB 11.5kB/s 00:01
Fetching php5-hash-5.4.37.txz: 100% 116 KiB 39.9kB/s 00:03
Fetching php5-filter-5.4.37.txz: 100% 19 KiB 20.3kB/s 00:01
Fetching php5-tokenizer-5.4.37.txz: 100% 8 KiB 8.7kB/s 00:01
Fetching php5-json-5.4.37.txz: 100% 17 KiB 17.6kB/s 00:01
Fetching php5-sqlite3-5.4.37_1.txz: 100% 17 KiB 18.3kB/s 00:01
Fetching sqlite3-3.8.8.1.txz: 100% 660 KiB 96.6kB/s 00:07
Fetching php5-pdo_sqlite-5.4.37_1.txz: 100% 13 KiB 13.5kB/s 00:01
Fetching php5-pdo-5.4.37.txz: 100% 44 KiB 45.5kB/s 00:01
Fetching php5-iconv-5.4.37.txz: 100% 17 KiB 18.0kB/s 00:01
Fetching php5-phar-5.4.37.txz: 100% 101 KiB 104.0kB/s 00:01
Fetching perl5-5.18.4_11.txz: 100% 12 MiB 52.7kB/s 04:14
Fetching mysql56-client-5.6.22.txz: 100% 1 MiB 62.6kB/s 00:30
Checking integrity... done (0 conflicting)
[1/28] Installing libiconv-1.14_6...
[1/28] Extracting libiconv-1.14_6: 100%
[2/28] Installing pcre-8.35_2...
[2/28] Extracting pcre-8.35_2: 100%
[3/28] Installing libxml2-2.9.2_2...
[3/28] Extracting libxml2-2.9.2_2: 100%
[4/28] Installing php5-5.4.37...
[4/28] Extracting php5-5.4.37: 100%
[5/28] Installing php5-dom-5.4.37...
[5/28] Extracting php5-dom-5.4.37: 100%
[6/28] Installing php5-hash-5.4.37...
[6/28] Extracting php5-hash-5.4.37: 100%
[7/28] Installing sqlite3-3.8.8.1...
[7/28] Extracting sqlite3-3.8.8.1: 100%
[8/28] Installing php5-pdo-5.4.37...
[8/28] Extracting php5-pdo-5.4.37: 100%
[9/28] Installing php5-session-5.4.37...
[9/28] Extracting php5-session-5.4.37: 100%
[10/28] Installing php5-xmlwriter-5.4.37...
[10/28] Extracting php5-xmlwriter-5.4.37: 100%
[11/28] Installing php5-xmlreader-5.4.37...
[11/28] Extracting php5-xmlreader-5.4.37: 100%
[12/28] Installing php5-xml-5.4.37...
[12/28] Extracting php5-xml-5.4.37: 100%
[13/28] Installing php5-simplexml-5.4.37...
[13/28] Extracting php5-simplexml-5.4.37: 100%
[14/28] Installing php5-ctype-5.4.37...
[14/28] Extracting php5-ctype-5.4.37: 100%
[15/28] Installing php5-posix-5.4.37...
[15/28] Extracting php5-posix-5.4.37: 100%
[16/28] Installing php5-filter-5.4.37...
[16/28] Extracting php5-filter-5.4.37: 100%
[17/28] Installing php5-tokenizer-5.4.37...
[17/28] Extracting php5-tokenizer-5.4.37: 100%
[18/28] Installing php5-json-5.4.37...
[18/28] Extracting php5-json-5.4.37: 100%
[19/28] Installing php5-sqlite3-5.4.37_1...
[19/28] Extracting php5-sqlite3-5.4.37_1: 100%
[20/28] Installing php5-pdo_sqlite-5.4.37_1...
[20/28] Extracting php5-pdo_sqlite-5.4.37_1: 100%
[21/28] Installing php5-iconv-5.4.37...
[21/28] Extracting php5-iconv-5.4.37: 100%
[22/28] Installing php5-phar-5.4.37...
[22/28] Extracting php5-phar-5.4.37: 100%
[23/28] Installing perl5-5.18.4_11...
[23/28] Extracting perl5-5.18.4_11: 100%
[24/28] Installing mysql56-client-5.6.22...
[24/28] Extracting mysql56-client-5.6.22: 100%
[25/28] Installing nginx-1.6.2_1,2...
===> Creating users and/or groups.
Using existing group ‘www‘.
Using existing user ‘www‘.
[25/28] Extracting nginx-1.6.2_1,2: 100%
[26/28] Installing php5-extensions-1.7...
[27/28] Installing pecl-APC-3.1.14_1...
[27/28] Extracting pecl-APC-3.1.14_1: 100%
[28/28] Installing mysql56-server-5.6.22...
===> Creating users and/or groups.
Creating group ‘mysql‘ with gid ‘88‘.
Creating user ‘mysql‘ with uid ‘88‘.
[28/28] Extracting mysql56-server-5.6.22: 100%
Message for pecl-APC-3.1.14_1:
************************************************************************
You may edit /usr/local/etc/php.ini to change this variables:
^^^ -> Default value
^^^^ -> Default value
If there is an informational section for APC, the installation was
successful.
************************************************************************
Message for mysql56-server-5.6.22:
************************************************************************
after an upgrade from an earlier version.
root@localhost:/usr/local #
//编辑系统启动文件
//FreeBSD下面自带vi,ee,编辑器看情况习惯使用
//在配置文件中加入下面几行:
# Created: Tue Feb 10 14:06:43 2015
# Enable network daemons for user convenience.
# Please make all changes to this file, not to /etc/defaults/rc.conf.
# This file now contains just the overrides from /etc/defaults/rc.conf.
sendmail="NONE"
defaultrouter="192.168.1.1"
hostname="localhost"
ifconfig_em0="inet 192.168.1.105 netmask 255.255.255.0"
keymap="us.iso"
sshd_enable="YES"
###################################
nginx_enable="YES"
mysql_enable="YES"
php_fpm_enable="YES"
//配置mysql系统文件,此安装默认将mysql安装至:/usr/local/share/mysql下
进入目录,拷贝下面的配置文件至/usr/local/etc
root@localhost:/usr/local/share/mysql # ls
binary-configure errmsg-utf8.txt italian
bulgarian estonian japanese
charsets fill_help_tables.sql korean
czech french magic
danish german my-default.cnf
dictionary.txt greek mysql-log-rotate
dutch hungarian mysql.server
english innodb_memcached_config.sql
root@localhost:/usr/local/share/mysql # cp my-default.cnf /usr/local/etc/my.cnf
root@localhost:/usr/local/share/mysql #
root@localhost:/usr/local # service mysql-server start
Starting mysql.
root@localhost:/usr/local #
//设置root密码,系统装后默认的mysql指令全部在bin下面
root@localhost:/usr/local/etc # ls
bash_completion.d periodic php.ini-development
devd perl5_version php.ini-production
man.d php pkg
my.cnf php-fpm.conf pkg.conf.sample
nginx php-fpm.conf.default rc.d
pam.d php.conf
root@localhost:/usr/local/etc # mv php.ini-production php.ini
root@localhost:/usr/local/etc # ls
bash_completion.d periodic php.ini
devd perl5_version php.ini-development
man.d php pkg
my.cnf php-fpm.conf pkg.conf.sample
nginx php-fpm.conf.default rc.d
pam.d php.conf
root@localhost:/usr/local/etc #
root@localhost:/usr/local/etc # service php-fpm start
Starting php_fpm.
root@localhost:/usr/local/etc #
root@localhost:/usr/local/etc # echo ‘apc.enable="1"‘ >> /usr/local/etc/php.ini
root@localhost:/usr/local/etc # echo ‘apc.shm_size="32M"‘ >> /usr/local/etc/php.ini
//重新启动php
root@localhost:/usr/local/etc # service php-fpm restart
Stopping php_fpm.
Waiting for PIDS: 82460.
Starting php_fpm.
root@localhost:/usr/local/etc #
root@localhost:/usr/local # cd etc/
root@localhost:/usr/local/etc # ls
bash_completion.d my.cnf periodic php-fpm.conf php.ini pkg.conf.sample
devd nginx perl5_version php-fpm.conf.default php.ini-development rc.d
man.d pam.d php php.conf pkg
root@localhost:/usr/local/etc # cd nginx/
root@localhost:/usr/local/etc/nginx # ls
fastcgi_params koi-win nginx.conf scgi_params-dist win-utf
fastcgi_params-dist mime.types nginx.conf-dist uwsgi_params
koi-utf mime.types-dist scgi_params uwsgi_params-dist
root@localhost:/usr/local/etc/nginx # ee nginx.conf
#user nobody;
user www;
worker_processes 1;
#error_log logs/error.log notice;
#error_log logs/error.log info;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
# ‘$status $body_bytes_sent "$http_referer" ‘
# ‘"$http_user_agent" "$http_x_forwarded_for"‘;
#tcp_nopush on;
keepalive_timeout 65;
file "nginx.conf", 118 lines
................
server {
listen 80;
server_name localhost;
root /usr/local/www/nginx;
index index.php index.html index.htm;#这里加入php页面支持
}
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
#将这里的注释#去掉,让nginx解析php脚本
location ~ \.php$ {
root /usr/local/www/nginx;#修改文件目录
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# concurs with nginx‘s one
#
#location ~ /\.ht {
# deny all;
#}
//启动nginx
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
root@localhost:/usr/local/etc/nginx #
//进入web默认目录新建phpinfo.php文件
<?php
phpinfo();
?>
root@localhost:/usr/local/www/nginx # ls
50x.html index.html
EXAMPLE_DIRECTORY-DONT_ADD_OR_TOUCH_ANYTHING phpinfo.php
root@localhost:/usr/local/www/nginx # ee phpinfo.php
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。