顶九网服务器搭建手册之AMPF环境搭建(2)

二、安装MySQL

1、安装mysql

# cd /usr/ports/databases/mysql50-server

# make WITH_CHARSET=gbk \

WITH_XCHARSET=all \

SKIP_DNS_CHECK=yes \

BUILD_OPTIMIZED=yes \

BUILD_STATIC=yes

#make install

#make clean

2、使mysql50和系统一起启动

# vi /etc/rc.conf  加入

mysql_enable=”YES”

3、启动mysql50

#/usr/local/share/mysql/mysql.server start

/usr/local/etc/rc.d/mysql-server.sh start

如果以上两条命令不能启动mysql

那么请reboot系统来启动mysql

 

4、设置mysql50的密码

# /usr/local/bin/mysqladmin -u root password ‘password’

这里的密码password可以自由设定。不一定为password.

5、登陆mysql5数据库.

# mysql -u root –p password

如果见到下面信息,即表示登陆成功。

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 77 to server version: 5.0.22

 

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

 

mysql>

 

三、mysql数据库优化 .(略)

二、安装apache2.2.2

一、安装apache

# cd /usr/ports/www/apache22

# make install clean

在弹出的PYTHON安装选择框里选择:HUGE_STACK_SIZE  Use a larger thread stack

在安装gettext ,将EXAMPLES 与HTMLMAN 两项选项都选上。

二、编辑/etc/rc.conf,加入

Apache22_enable=”YES”

三、重启服务器。

FreeBSD下NGINX 1.8+PHP5.6 +PERL 5.20 +Mysql 5.6+FTP 环境搭建与优化

FreeBSD下NGINX 1.8+PHP5.6 +PERL 5.20 +Mysql 5.6+FTP 环境搭建与优化

为什么选择FreeBSD做为os,这里不再讲,具体可以看这里《Free BSD,Linux之比较》

附件提供了已做了优化后的配置文件,下载直接可以使用。

#安装perl 支持
--------------------------------------
cd /usr/ports/lang/perl5.20 && make config

#安装完以后发现新版本的5.20的perl改变了目录,这里做个链接。
ln -s /usr/local/bin/perl /usr/bin/perl

#安装perl支持组件(perl on nginx)
cd /usr/ports/databases/rrdtool && make install clean
cd /usr/ports/databases/p5-DBD-mysql && make install clean
cd /usr/ports/devel/p5-File-Tail && make install clean
cd /usr/ports/devel/p5-Time-HiRes && make install clean
cd /usr/ports/graphics/p5-GD && make install clean
cd /usr/ports/sysutils/p5-Unix-Syslog && make install clean
cd /usr/ports/www/p5-LWP-UserAgent-WithCache && make install clean
cd /usr/ports/dns/p5-Net-DNS && make install clean
cd /usr/ports/security/p5-Digest-HMAC && make install clean
cd /usr/ports/security/p5-Digest-MD5 && make install clean
cd /usr/ports/security/p5-Digest-Perl-MD5 && make install clean
cd /usr/ports/security/p5-Digest-SHA1 && make install clean
cd /usr/ports/net-mgmt/p5-Net-IP && make install clean
cd /usr/ports/lang/p5-ExtUtils-F77 && make install clean
cd /usr/ports/www/p5-FCGI && make install clean
cd /usr/ports/www/p5-FCGI-ProcManager && make install clean
--------------------------------------

#安装nginx(组件根据自已需要勾选)
--------------------------------------
cd /usr/ports/www/nginx && make config

#安装php 5.6 on nginx(组件根据自已需要勾选)
cd /usr/ports/lang/php56 && make config

#安装php 5.6的扩展库(组件根据自已需要勾选)
cd /usr/ports/lang/php56-extensions && make config

#安装php常用的支持库
cd /usr/ports/databases/php5-redis && make install clean
cd /usr/ports/databases/pecl-memcache && make install clean
cd /usr/ports/graphics/ImageMagick && make install clean
cd /usr/ports/graphics/pecl-imagick && make install clean
cd /usr/ports/graphics/php-magickwand && make install clean

#安装常用的缓存及数据服务
cd /usr/ports/databases/redis && make install clean
cd /usr/ports/databases/memcached && make install clean
cd /usr/ports/www/xcache && make install clean
cd /usr/ports/databases/mysql56-client && make install clean
--------------------------------------

#将服务加入开机启动项
--------------------------------------
vi /etc/rc.conf

#############################
sendmail_enable=”NO”
sendmail_submit_enable=”NO”
sendmail_outbound_enable=”NO”
sendmail_msp_queue_enable=”NO”
############################
mysql_enable=”YES”
memcached_enable=”YES”
redis_enable=”YES”
############################
php_fpm_enable=”YES”
perl_fcgi_enable=”YES”
nginx_enable=”YES”
############################
pureftpd_enable=”YES”

#先启动redis和memcached服务,这两个无需配置,默认即可。
/usr/local/etc/rc.d/redis restart
/usr/local/etc/rc.d/memcached restart
--------------------------------------

#配置nginx
--------------------------------------
#下载配置脚本:附件 nginx-config.zip
#解压后获取文件(vhosts_params、nginx.conf、mime.types、fastcgi_params、domain.com)

目录结构

nginx /

|—— vhosts_params
|—— nginx.conf
|—— mime.types
|—— fastcgi_params
|——……..
|——vhosts
|——domain.com
|——……

#将 vhosts_params、nginx.conf、mime.types、fastcgi_params 文件移动到如下目录
mv vhosts_params /usr/local/etc/nginx/
mv fastcgi_params /usr/local/etc/nginx/
mv nginx.conf /usr/local/etc/nginx/
mv mime.types /usr/local/etc/nginx/

#然后进入nginx下建立 vhosts 目录
#vhosts目录以后放置 虚拟站点的配置文件
cd /usr/local/etc/nginx/
mkdir vhosts

#将 domain.com 移动到 /usr/local/etc/nginx/vhosts/ 目下
mv domain.com /usr/local/etc/nginx/vhosts/

#有关domain.com 的配置说明
server
{
listen 80;
#server_name _; #这个是所有域名均可访问
server_name abc.domain.com; #这个是指定域名访问

index index.html index.htm index.php index.cgi;
root /usr/local/www/abc.domain.com; #网站文件的目录位置

include vhosts_params;
}

#有关 vhosts_params文件的说明
#vhosts_params 文件是我建立的一个配置文件,主要方便后面做多个虚拟主机时可以快速的引用。

location ~* ^.+.gzjs$ { #支持对js、css等脚本的压缩
add_header Content-Encoding gzip;
gzip off;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { #将图片文件本地缓存30天
expires 30d;
}

location ~ .*\.(js|css)?$ { #将js css文件本地缓存30天
expires 1h;
}

location ~ \.php$ { #php-fcgi的配置,支持php文件
gzip off;
fastcgi_pass unix:/var/run/php-fcgi.sock;
fastcgi_index index.php;
include fastcgi_params;
# fastcgi_cache ngx_fcgi_cache;
# fastcgi_cache_key $scheme$request_method$host$request_uri;
}

location ~ .*\.(pl|cgi)?$ { #perl-fcgi的配置,支持cgi pl文件
gzip off;
fastcgi_pass unix:/var/tmp/perl-fcgi.sock;
fastcgi_index index.cgi;
include fastcgi_params;
# fastcgi_cache ngx_fcgi_cache;
# fastcgi_cache_key $scheme$request_method$host$request_uri;
}

location ~ ^/nginxstatus/ { #打开nginxstatus状态显示
stub_status on;
}

error_page 404 = /404/; #定义404错误的信息

--------------------------------------

#配置nginx支持 php
--------------------------------------
#下载配置脚本:附件 php-config.zip
#替换原有的配置文件
mv php-fpm.conf /usr/local/etc/
mv php.ini /usr/local/etc/

#启动nginx和php-fpm
/usr/local/etc/rc.d/php-fpm restart
/usr/local/etc/rc.d/nginx restart

vi /usr/local/www/domain.com/phptest.php

#访问查看php情况:http://domain.com/phptest.php

--------------------------------------

阅读更多