我们利用pkg工具直接安装web服务所需的程序包,可以一次将所需包安装,此时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):
New packages to be INSTALLED:
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
The process will require 192 MiB more space.
28 MiB to be downloaded.
Proceed with this action? [y/N]:
///选择“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:
apc.enabled="1"
^^^ -> Default value
apc.shm_size="30"
^^^^ -> Default value
* More information on /usr/local/share/doc/APC/INSTALL
Then restart your web server and consult the output of phpinfo().
If there is an informational section for APC, the installation was
successful.
************************************************************************
Message for mysql56-server-5.6.22:
************************************************************************
Remember to run mysql_upgrade the first time you start the MySQL server
after an upgrade from an earlier version.
************************************************************************
root@localhost:/usr/local #
//编辑系统启动文件
//FreeBSD下面自带vi,ee,编辑器看情况习惯使用
root@localhost:/usr/local # ee /etc/rc.conf
//在配置文件中加入下面几行:
=====line 16 col 20 lines from top 16 =========================================
# -- sysinstall generated deltas -- # Tue Feb 10 14:06:43 2015
# 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"
//按“Esc"退出,提示是否保存时保存并退出
//配置mysql系统文件,此安装默认将mysql安装至:/usr/local/share/mysql下
进入目录,拷贝下面的配置文件至/usr/local/etc
root@localhost:/usr/local # cd share/mysql/
root@localhost:/usr/local/share/mysql # ls
binary-configure errmsg-utf8.txt italian
mysql_system_tables.sql romanian
bulgarian estonian japanese
mysql_system_tables_data.sql russian
charsets fill_help_tables.sql korean
mysql_test_data_timezone.sql serbian
czech french magic
mysqld_multi.server slovak
danish german my-default.cnf
norwegian spanish
dictionary.txt greek mysql-log-rotate
norwegian-ny swedish
dutch hungarian mysql.server
polish ukrainian
english innodb_memcached_config.sql
mysql_security_commands.sql portuguese
root@localhost:/usr/local/share/mysql # cp my-default.cnf /usr/local/etc/my.cnf
root@localhost:/usr/local/share/mysql #
//然后启动mysql
root@localhost:/usr/local # service mysql-server start
Starting mysql.
root@localhost:/usr/local #
//设置root密码,系统装后默认的mysql指令全部在bin下面
# /usr/local/bin/mysqladmin -u root password ‘123456‘
//配置php
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 #
//其他保持默认,启动php-fpm
root@localhost:/usr/local/etc # service php-fpm start
Starting php_fpm.
root@localhost:/usr/local/etc #
//配置apc,这里也可以直接打开php.ini文件编辑,以下我们直接写入
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 #
//下面配置nginx
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;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
# ‘$status $body_bytes_sent "$http_referer" ‘
# ‘"$http_user_agent" "$http_x_forwarded_for"‘;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
file "nginx.conf", 118 lines
................
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/local/www/nginx;
index index.php index.html index.htm;#这里加入php页面支持
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#将这里的注释#去掉,让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;
}
# deny access to .htaccess files, if Apache‘s document root
# concurs with nginx‘s one
#
#location ~ /\.ht {
# deny all;
#}
//启动nginx
root@localhost:/usr/local/etc/nginx # service nginx start
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 #
此时在浏览器输入http://192.168.1.105/应该能看到如下界面
//进入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