LNMP centos6.7+nginx1.9.12+mysql5.7.11+php5.6.13+PHP各项扩展安装 以及openresty nginx+lua环境,lnmpopenresty


###   依 赖   ###
yum groupinstall "Development tools";
yum -y install gcc gcc-c++ cmake autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers;

### 安装Apache ab测试工具
yum install httpd-tools 

###  libiconv  ###
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz;
tar zxvf libiconv-1.14.tar.gz; 
cd libiconv-1.14/; 
./configure --prefix=/usr/local; 
make && make install; 
cd ../;


###  libcrypt  ###
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz;
tar zxvf libmcrypt-2.5.7.tar.gz; 
cd libmcrypt-2.5.7/; 
./configure; 
make && make install;

cd libltdl/; 
./configure --enable-ltdl-install; 
make && make install; 
cd ../../;


###  mhash  ###
wget http://iweb.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar zxvf mhash-0.9.9.9.tar.gz; 
cd mhash-0.9.9.9/; 
./configure; 
make && make install; 
cd ../;



ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la; 
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so; 
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4; 
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8; 
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a; 
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la; 
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so; 
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2; 
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1; 
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config;
export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH


###  mcrypt  ###
wget http://pilotfiber.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz;
tar zxvf mcrypt-2.6.8.tar.gz;
cd mcrypt-2.6.8/;
./configure; 
make && make install; 
cd ../;


###  mysql  ###
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz;
wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.11.tar.gz;
useradd -M -s /sbin/nologin mysql

tar -zxvf boost_1_59_0.tar.gz;
tar -zxvf mysql-5.7.11.tar.gz;
mkdir -p /data/mysql;
cd mysql-5.7.11;
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DDOWNLOAD_BOOST=1 \   #从MySQL 5.7.5开始Boost库是必需的
-DWITH_BOOST=../boost_1_59_0 \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1;

make -j `grep processor /proc/cpuinfo | wc -l`  #编译很消耗系统资源,小内存可能编译通不过
make install

/bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on


cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
#skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF

### 初始化 ###
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
"--initialize"会生成一个随机密码(~/.mysql_secret),而"--initialize-insecure"不会生成密码
--datadir目标目录下不能有数据文件

/usr/local/mysql/bin/mysqladmin -uroot password "123";
/etc/init.d/mysqld start;



### php ###
cp -frp /usr/lib64/libldap* /usr/lib/;  [Cannot find ldap libraries in /usr/lib]
tar jxvf php-5.6.13.tar.bz2;
cd php-5.6.13;
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-embed --enable-maintainer-zts --enable-debug --enable-opcache --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config;

make ZEND_EXTRA_LIBS='-liconv' && make install;

cp php.ini-development /usr/local/php/etc/php.ini;
cp sapi/fpm/init.d.php-fpm /usr/local/php/sbin/
chmod a+x /usr/local/php/sbin/init.d.php-fpm

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
user = nginx
group = nginx
useradd -M -s /sbin/nologin nginx
/usr/local/php/sbin/init.d.php-fpm start
cd ../ 


### pcre ###
wget http://iweb.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.bz2;
tar -jxvf pcre-8.38.tar.bz2;
cd pcre-8.38/;
./configure;
make && make install;
cd ../;


### nginx ###
tar -zxvf nginx-1.9.12.tar.gz;   
cd nginx-1.9.12/   
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module   
make && make install   
cd ../


mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
vim /usr/local/nginx/conf/nginx.conf

user nginx nginx; 
worker_processes 2;
#相当于cpu个数

error_log logs/nginx_error.log;
pid /usr/local/nginx/nginx.pid; 

#Specifies the value for maximum file descriptors that can be opened by this process. 
worker_rlimit_nofile 65535; 

events { 
	use epoll; 
	worker_connections 65535; 
} 

http { 
	include mime.types; 
	default_type application/octet-stream;
	#charset gb2312; 

	server_names_hash_bucket_size 128; 
	client_header_buffer_size 32k; 
	large_client_header_buffers 4 32k; 
	client_max_body_size 8m; 

	sendfile on; 
	tcp_nopush on; 

	keepalive_timeout 65; 

	tcp_nodelay on; 

	fastcgi_connect_timeout 300; 
	fastcgi_send_timeout 300; 
	fastcgi_read_timeout 300; 
	fastcgi_buffer_size 64k; 
	fastcgi_buffers 4 64k; 
	fastcgi_busy_buffers_size 128k; 
	fastcgi_temp_file_write_size 128k; 

	gzip on; 
	gzip_min_length 1k; 
	gzip_buffers 4 16k; 
	gzip_http_version 1.0; 
	gzip_comp_level 2; 
	gzip_types text/plain application/x-javascript text/css application/xml; 
	gzip_vary on; 

	#limit_zone crawler $binary_remote_addr 10m;

	server { 
		listen 80; 
		server_name test.com; 
		index index.html index.htm index.php; 
		root /www; 

		#limit_conn crawler 20; 

		location ~ .*\.(php|php5)?$ { 
			#fastcgi_pass unix:/tmp/php-cgi.sock; 
			fastcgi_pass 127.0.0.1:9000; 
			fastcgi_index index.php;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
			include fastcgi_params; 
		} 

		location /nginxstatus{
			stub_status on;
			access_log off;
		}

		location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { 
			expires 30d; 
		} 

		location ~ .*\.(js|css)?$ {
			expires 1h; 
		} 
	} 
}
/usr/local/nginx/sbin/nginx -t

vim /etc/rc.local
/usr/local/php/sbin/init.d.php-fpm start
/usr/local/nginx/sbin/nginx
/etc/init.d/mysqld

vim /etc/profile
ulimit -SHn 65535
export PATH=/usr/local/nginx/sbin:/usr/local/php/bin:$PATH

平滑重启nginx进程
1)Pkill -HUP nginx
2)kill -HUP `pgrep -uroot nginx`
3)/usr/local/nginx/sbin/nginx -s reload


### PHP extension ### [https://pecl.php.net/package/包名]

#  yaf  #
wget https://pecl.php.net/get/yaf-2.3.3.tgz; [php7 => yaf 3.0]
tar zxvf yaf-2.3.3.tgz;
cd yaf-2.3.3;
phpize;
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install;

#  swoole  #
wget https://pecl.php.net/get/swoole-1.8.2.tgz;
tar zxvf swoole-1.8.2.tgz;
cd swoole-1.8.2;
phpize;
./configure --with-php-config=/usr/local/php/bin/php-config --enable-async-mysql=/usr/local/mysql/ --enable-swoole-debug --enable-sockets --enable-openssl --enable-swoole;
make && make install;


# pdo-mysql #
wget https://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
tar zxvf PDO_MYSQL-1.0.2.tgz;
cd PDO_MYSQL-1.0.2;
phpize;
ln -s /usr/local/mysql/include/* /usr/local/include/
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make && make install;


#  xdebug  #

wget https://pecl.php.net/get/xdebug-2.4.0.tgz;
tar zxvf xdebug-2.4.0.tgz;
cd xdebug-2.4.0;
phpize;
./configure --with-php-config=/usr/local/php/bin/php-config --enable-xdebug;
make && make install; [ https://xdebug.org/docs/ ]

[xdebug]
xdebug.remote_enable         = On
xdebug.remote_host           = "localhost" [or ip]
xdebug.remote_port           = 9000
xdebug.remote_handler        = "dbgp"
xdebug.auto_trace            = 1
xdebug.collect_includes      = 1
xdebug.collect_params        = 1
xdebug.collect_return        = 1
xdebug.default_enable        = 1
xdebug.collect_assignments   = 1
xdebug.collect_vars          = 1
xdebug.remote_autostart      = 1
xdebug.remote_connect_back   = 1
xdebug.show_local_vars       = 1
xdebug.show_exception_trace  = 0




cd /php源码目录/php-5.6.13/ext/exif/
phpize;
./configure --with-php-config=/usr/local/php/bin/php-config --enable-exif
make && make install;

cd /php源码目录/php-5.6.13/ext/mbstring/
phpize;
./configure --with-php-config=/usr/local/php/bin/php-config --enable-mbstring
make && make install;//编译之后不用修改php.ini


#  memcached  #
wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
tar zxvf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable
 ./configure --prefix=/usr
make && make install

wget http://memcached.org/latest
tar zxvf latest
cd memcached-1.4.25/
./configure --with-libevent=/usr --prefix=/usr/local/memcached
make && make install

启动Memcache的服务:  
# /usr/local/bin/memcached -d -m 64  -u root -l 192.168.0.100 -p 11211 -c 1024 -P /tmp/memcached.pid 
-p memcached监听的TCP端口
-l 监听ip地址,如果你需要多个服务器都能够读取这台memcached的缓存数据,那么就必须设定这个ip
-d 以daemon方式运行,将程序放入后台
-u memcached的运行用户
-P memcached的pid文件路径
-m memcached可以使用的最大内存数量
-c memcached同时可以接受的最大的连接数
如果你希望以socket方式来访问memcached,那么在启动的时候就必须去掉 -l和-p参数,并加上-s参数:
-s memcached的socket文件路径


wget https://pecl.php.net/get/memcache-3.0.8.tgz;
tar zxvf memcache-3.0.8.tgz;
cd memcache-3.0.8;
phpize;
./configure --with-php-config=/usr/local/php/bin/php-config;
make && make install;

# memcached #
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar zxvf libmemcached-1.0.18.tar.gz;
cd libmemcached-1.0.18;
./configure --prefix=/usr/local/libmemcached --with-memcached=/usr/local/memcached --with-mysql=/usr/local/mysql --with-gearmand=/usr/local/gearmand
make && make install

wget https://pecl.php.net/get/memcached-2.2.0.tgz
tar zxvf memcached-2.2.0.tgz;
cd memcached-2.2.0;
phpize;
./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcached --enable-memcached-json --enable-debug --with-libmemcached-dir=/usr/local/libmemcached
make && make install;



#  redis  #
wget http://download.redis.io/redis-stable.tar.gz;
tar zxvf redis-stable.tar.gz;  
cd redis-stable;
make;  
cd src/;  
make install;

mkdir -p /usr/local/redis/{bin,data,etc,logs}

cp redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server /usr/local/redis/bin/;  
cd ../;
cp redis.conf /usr/local/redis/etc/

/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf  
/usr/local/redis/bin/redis-cli -a yunduan -h 127.0.0.1 -p 6379 shutdown  
/usr/local/redis/bin/redis-cli shutdown  
pkill redis-server  
killall redis-server 

wget https://pecl.php.net/get/redis-2.2.7.tgz
tar redis-2.2.7.tgz
cd redis-2.2.7
./configure --with-php-config=/usr/local/php/bin/php-config  
make && make install


#  mongodb  #
https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.4.tgz
mv mongodb-linux-x86_64-rhel62-3.2.3 /usr/local/mongodb
mkdir -p /usr/local/mongodb/{data,dblogs}
echo "/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --fork --logpath=/usr/local/mongodb/dblogs/log">> /etc/rc.local

# mongodb #
wget https://pecl.php.net/get/mongodb-1.1.4.tgz
tar zxvf mongodb-1.1.4.tgz;
cd mongodb-1.1.4;
/usr/local/php/bin/phpize;
./configure --with-php-config=/usr/local/php/bin/php-config;
make&& make install;

# mongo #
wget https://pecl.php.net/get/mongo-1.6.13.tgz;


#  xhprof  #
wget https://pecl.php.net/get/xhprof-0.9.4.tgz;
tar zxvf xhprof-0.9.4.tgz;
cd xhprof-0.9.4/extension;
/usr/local/php/bin/phpize;
./configure --with-php-config=/usr/local/php/bin/php-config;
make&& make install;


1 下载 https://github.com/perftools/xhgui  (git clone https://github.com/perftools/xhgui.git)
2 将cache目录改为777权限 chmod -R 0777 cache
3 开启mongodb 如果mongodb需要密码登陆  则需要更改config/config.php
4 安装 cd path/to/xhgui; php install.php 或者 composer update --prefer-dist --no-dev
在composer.json添加一个国内镜像
,
    "repositories": {
        "packagist": {
            "type": "composer",
            "url": "https://packagist.phpcomposer.com"
        }
    }

5 开启rewrite 
6 将header.php文件引入需要记录的虚拟机配置中
三种方式 任选其一 添加到需要检测到网站:
1. fastcgi_param PHP_VALUE "auto_prepend_file=/Users/markstory/Sites/xhgui/external/header.php";
2. <?php  
require '/path/to/xhgui/external/header.php'; 
3. php -d auto_prepend_file=/path/to/xhgui/external/header.php do_work.php

xhgui配置一个可访问的虚拟机
server  
{  
    listen 80;  
    server_name    xhgui.test.com;  
    root   /home/yunduan/www/xhgui/webroot/;  
    index index.html index.php;  
  
    location / {  
        try_files $uri $uri/ /index.php?$query_string;  
    }
  
    location ~ \.php$ {  
        fastcgi_pass    127.0.0.1:9000;  
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;  
        fastcgi_index index.php;  
        include fastcgi_params;  
    }  
}  

echo "127.0.0.1 xhgui.test.com" >> /etc/hosts; 
pkill -HUP nginx

或者

<?php
<pre name="code" class="php">//统计开始
xhprof_enable(XHPROF_FLAGS_CPU+XHPROF_FLAGS_MEMORY);

/**  code  **/

//统计结束
xhprof_end();

function xhprof_end()
{
    $data = xhprof_disable();
    
    $xhprof_root = "/usr/local/php/xhprof";
    include_once $xhprof_root."/xhprof_lib/utils/xhprof_lib.php";
    include_once $xhprof_root."/xhprof_lib/utils/xhprof_runs.php";
    
    $xhprof_runs = new \XHprofRuns_Default();
    $run_id = $xhprof_runs->save_run($data, "domain");//第二个参数在接下来的地方作为命名空间一样的概念来使用
    setcookie("xhprof_url", "$run_id", $_SERVER['REQUEST_TIME'] + 3600, "/", "xx.com", false, true);//不影响正常的输出结果 将本次的run_id 写到cookie
    //访问domain/index.php?run=$run_id&source=domain就能够看到一个统计列表了。
}




### Other install ###


<= gearmand =>
wget https://launchpad.net/gearmand/1.2/1.1.12/+download/gearmand-1.1.12.tar.gz;
tar zxvf gearmand-1.1.12.tar.gz;
cd gearmand-1.1.12;
./configure --prefix=/usr/local/gearmand/;
[yum -y install boost-devel*   configure: error: could not find boost-devel]
[yum -y install gperf*          configure: error: could not find gperf]
[yum -y install libevent-devel*   configure: error: could not find libevent-devel]
[yum -y install libuuid*        configure: error: Unable to find libuuid]
make && make install;


wget http://pecl.php.net/get/gearman-1.1.2.tgz;
tar zxvf gearman-1.1.2.tgz;
cd gearman-1.1.2;
phpize;
./configure --with-php-config=/usr/local/php/bin/php-config --with-gearman=/usr/local/gearmand/
make && make install;



rabbitMQ erlang
wget http://erlang.org/download/otp_src_18.3.tar.gz
tar zxvf otp_src_18.3.tar.gz;
cd otp_src_18.3;
./configure --prefix=/usr/local/erlang;
make && make install;
ln -s /usr/local/erlang/bin/erl /usr/bin/erl




tar xvf rabbitmq-server-generic-unix-3.6.1.tar;
mv rabbitmq_server-3.6.1/ /usr/local/rabbitMQ-3.6.1;
chmod -R a+x /usr/local/rabbitMQ-3.6.1;
./rabbitmq-server -detached;
./rabbitmq-plugins enable rabbitmq_management;
http://localhost:15672/ guest:guest


php extension


安装librabbitmq
wget https://github.com/alanxz/rabbitmq-c/releases/download/v0.7.1/rabbitmq-c-0.7.1.tar.gz  [https://github.com/alanxz/rabbitmq-c]
tar zxvf rabbitmq-c-0.7.1.tar.gz;
cd rabbitmq-c-0.7.1;
./configure --prefix=/usr/local/rabbitmq-c-0.7.1;
make && make install;


wget https://pecl.php.net/get/amqp-1.7.0alpha2.tgz;
cd amqp-1.7.0alpha2;
phpize;
./configure --with-php-config=/usr/local/php/bin/php-config --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-c-0.7.1;
make && make install;
http://php.net/manual/pl/amqp.examples.php




svm install:
wget 
mv libsvm.cgi\?+http\:%2F%2Fwww.csie.ntu.edu.tw%2F~cjlin%2Flibsvm+tar.gz  libsvm.tar.gz
tar zxvf libsvm.tar.gz
cd libsvm-3.21/
make lib
cp libsvm.so.2 /usr/lib/libsvm.so
cp libsvm.so.2 /usr/lib/




wget https://pecl.php.net/get/svm-0.1.9.tgz
tar zxvf svm-0.1.9.tgz
cd svm-0.1.9
phpize
./configure --with-php-config=/usr/local/php/bin/php-config;
make && make install;


<?php
$data = array(
    array(-1, 1 => 0.43, 3 => 0.12, 9284 => 0.2),
    array(1, 1 => 0.22, 5 => 0.01, 94 => 0.11),
);


$svm = new SVM();
$model = $svm->train($data);


$data = array(1 => 0.43, 3 => 0.12, 9284 => 0.2);
$result = $model->predict($data);
var_dump($result);
$model->save('model.svm');
?>



wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz;
tar xzvf coreseek-4.1-beta.tar.gz;
cd coreseek-4.1-beta;


#安装mmseg
cd mmseg-3.2.14;
./bootstrap;
./configure --prefix=/usr/local/mmseg3;
make && make install;
cd ../csft-4.1;


#安装coreseek
sh buildconf.sh;
./configure --prefix=/usr/local/coreseek  --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql;
make && make install; 
[sphinx.cpp:22292: undefined reference to `libiconv_open' -> 
vim src/Makefile == LIBS = -ldl -lm -lz -lexpat -liconv -L/usr/local/lib -lrt  -lpthread]
cd ../testpack;


#测试mmseg分词,coreseek搜索
/usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml
/usr/local/coreseek/bin/indexer -c etc/csft.conf --all
/usr/local/coreseek/bin/search -c etc/csft.conf 网络搜索




cd ../coreseek-4.1-beta/csft-4.1/api/libsphinxclient/;
./configure  --prefix=/usr/local/sphinxclient --enable-debug;
[config.status: error: cannot find input file: src/Makefile.in]
{aclocal;
libtoolize --force;
automake --add-missing;
autoconf;
autoheader;
make clean;}
make && make install;
[error while loading shared libraries: libiconv.so.2]
{ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
ldconfig}


wget https://pecl.php.net/get/sphinx-1.3.3.tgz;
tar zxvf sphinx-1.3.3.tgz;
cd sphinx-1.3.3
phpize;
./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinxclient
make && make install




end:


amqp.so  
gearman.so   
memcached.so  
mongodb.so  
opcache.so    
redis.so   
svm.so     
xdebug.so  
yaf.so
exif.so  
memcache.so   
mongo.so    
pdo_mysql.so  
sphinx.so  
swoole.so  
xhprof.so




extension=memcache.so
extension=memcached.so
extension=mongodb.so
extension=mongo.so
extension=redis.so
extension=xhprof.so
extension=gearman.so
extension=amqp.so
extension=svm.so
extension=pdo_mysql.so
extension=sphinx.so
extension=swoole.so
extension=yaf.so
zend_extension=opcache.so//必须在 Xdebug 扩展之前加载 OPcache 扩展
zend_extension=xdebug.so




[opcache]
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1




ls -d */ | grep -v ^php | xargs rm -rf;








#openresty  nginx lua 环境
wget https://openresty.org/download/openresty-1.9.15.1.tar.gz
tar -xzvf openresty-1.9.15.1.tar.gz


#安装LuaJIT
cd openresty-1.9.15.1/bundle/LuaJIT-2.1-20160517/
make clean && make && make install
#如果没有执行ln -sf luajit-2.1.0-beta2 /usr/local/bin/luajit 则手动执行一次


#安装ngx_cache_purge模块,该模块用于清理nginx FastCGI, proxy, SCGI and uWSGI caches
cd ../
wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
tar -xvf 2.3.tar.gz


#安装nginx_upstream_check_module模块,该模块用于ustream健康检查
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz  
tar -xvf v0.3.0.tar.gz 


#安装ngx_openresty
cd ../
./configure --user=nginx --group=nginx --prefix=/usr/local/servers --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module  --with-pcre  --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ 
gmake && gmake install


/usr/local/servers


vim /usr/local/servers/nginx/conf/nginx.conf
http部分添加{
<span >	</span>#lua模块路径,多个之间”;”分隔,其中”;;”表示默认搜索路径,默认到/usr/local/servers/nginx下找  
<span >	</span>lua_package_path "/usr/local/servers/nginx/lualib/?.lua;;";  #lua 模块
<span >	</span>lua_package_cpath "/usr/local/servers/nginx/lualib/?.so;;";  #c模块
<span >	</span>include lua.conf;
}


lua.conf文件为测试lua开发,包含[
<span >	</span>server {  
<span >	</span>    listen       80;
<span >	</span>    server_name  _;


<span >	</span>    location /lua {  
<span >		</span>    default_type 'text/html';
<span >		</span>    lua_code_cache off;#关闭缓存,这样调试时每次修改lua代码不需要reload nginx;但是正式环境一定记得开启缓存。 
<span >		</span>    #content_by_lua 'ngx.say("hello ")';  
<span >		</span>   <span >	</span>content_by_lua_file conf/lua/test.lua; #相对于nginx安装目录
<span >		</span>}
<span >	</span>}
]
vim /usr/local/servers/nginx/conf/lua/test.lua[
<span >	</span>ngx.say("world");
]


/usr/local/servers/nginx/sbin/nginx -t
/usr/local/servers/nginx/sbin/nginx -s reload


curl http://luat.com/lua
world


nginx+lua项目构建目录结构
example
    example.conf     ---该项目的nginx 配置文件
    lua              ---我们自己的lua代码
      test.lua
    lualib            ---lua依赖库/第三方依赖
      *.lua
      *.so





相关内容

    暂无相关文章