[[email protected] ~]# yum groupinstall "Development Tools" "Server Platform Development" -y
[[email protected] ~]# yum -y install pcre-devel
在www.nginx.org 下载nginx的压缩包
[[email protected] tool]# du -sh nginx-1.10.2.tar.gz
892Knginx-1.10.2.tar.gz
[[email protected] tool]# tar -xf nginx-1.10.2.tar.gz
[[email protected] tool]# cd nginx-1.10.2
[[email protected] nginx-1.10.2]# ll
total 692
drwxr-xr-x. 6 1001 1001 4096 Dec 23 13:00 auto
-rw-r--r--. 1 1001 1001 264254 Oct 18 23:03 CHANGES
-rw-r--r--. 1 1001 1001 402997 Oct 18 23:03 CHANGES.ru
drwxr-xr-x. 2 1001 1001 4096 Dec 23 13:00 conf
-rwxr-xr-x. 1 1001 1001 2481 Oct 18 23:03 configure
drwxr-xr-x. 4 1001 1001 4096 Dec 23 13:00 contrib
drwxr-xr-x. 2 1001 1001 4096 Dec 23 13:00 html
-rw-r--r--. 1 1001 1001 1397 Oct 18 23:03 LICENSE
drwxr-xr-x. 2 1001 1001 4096 Dec 23 13:00 man
-rw-r--r--. 1 1001 1001 49 Oct 18 23:03 README
drwxr-xr-x. 9 1001 1001 4096 Dec 23 13:00 src
[[email protected] nginx-1.10.2]# groupadd -g 111 nginx
[[email protected] nginx-1.10.2]# useradd -r -u 111 -g 111 nginx
[[email protected] ~]# ./configure \
> --prefix=/usr \
> --sbin-path=/usr/sbin/nginx \
> --conf-path=/etc/nginx/nginx.conf \
> --error-log-path=/var/log/nginx/error.log \
> --http-log-path=/var/log/nginx/access.log \
> --pid-path=/var/run/nginx/nginx.pid \
> --lock-path=/var/lock/nginx.lock \
> --user=nginx \
> --group=nginx \
> --with-http_ssl_module \
> --with-http_flv_module \
> --with-http_stub_status_module \
> --with-http_gzip_static_module \
> --http-client-body-temp-path=/var/tmp/nginx/client/ \
> --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
> --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
> --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
> --http-scgi-temp-path=/var/tmp/nginx/scgi \
> --with-pcre \
> --with
[root[email protected] nginx]# make
[[email protected] nginx]# make install
[[email protected] nginx]# vim /etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -`
options=`$nginx -V 2>&1 | grep ‘configure arguments:‘`
for opt in $options; do
if [ `echo $opt | grep ‘.*-temp-path‘` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
[[email protected] nginx]# chmod +x /etc/rc.d/init.d/nginx
[[email protected] nginx]# bash -n /etc/rc.d/init.d/nginx
[[email protected] nginx]# chkconfig --add nginx
[[email protected] nginx]# chkconfig --list nginx
nginx 0:off1:off2:off3:off4:off5:off6:off
[[email protected] nginx]# service nginx start
Starting nginx: [ OK ]
nginx在你安装的目录下(/usr/)创建了一个html页面
[[email protected] html]# vim /etc/nginx/nginx.conf
location / {
root /web/html;
index index.html index.htm;
}
"/etc/nginx/nginx.conf" 117L, 2661C
[[email protected] nginx]# mkdir -pv /web/html
mkdir: created directory `/web‘
mkdir: created directory `/web/html‘
[[email protected] nginx]# cd /web/html/
[[email protected] html]# vim index.html
<h1> My Nginx_Web Server</h1>
[[email protected] html]# service nginx reload
[[email protected] zxl]# vim /etc/nginx/nginx.conf
location / {
root /web/html;
index index.html index.htm;
}
location /zxl {
root /web;
index index.html index.hml;
[[email protected] web]# mkdir zxl
[[email protected] web]# vim zxl/index.html
[[email protected] web]# service nginx reload
<h1>www.zxl.com</h1>
[[email protected] zxl]# vim /etc/nginx/nginx.conf
error_page 404 /404.html;
[[email protected] zxl]# vim /web/html/404.html
<h1>error! 404</h1>
~
[[email protected] zxl]# vim /etc/nginx/nginx.conf
location / {
root /web/html;
index index.html index.htm;
allow 192.168.139.0;
deny 192.168.139.4;
}
[[email protected] zxl]# curl http://192.168.139.2
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.10.2</center>
</body>
</html>
Forbidden禁止访问
[[email protected] zxl]# htpasswd -c -m /etc/nginx/.users tom #此命令是httpd自带的
[[email protected] zxl]# htpasswd -m /etc/nginx/.users jerry
[[email protected] zxl]# vim /etc/nginx/nginx.conf
location / {
root /web/html;
index index.html index.htm;
allow 192.168.139.0;
deny 192.168.139.4;
auth_basic "limit area......";
auth_basic_user_file /etc/nginx/.users;
}
[[email protected] zxl]# service nginx reload
[[email protected] zxl]# vim /etc/nginx/nginx.conf
location /status {
stub_status on;
}
[[email protected] zxl]# service nginx reload
Active connections: 1 当前活动连接数 1
server accepts handled requests
9 9 53 服务器接受了9个连接,服务器共处理了9个连接,共接受了53个请求(一个长连接可能多个请求)
Reading: 0 Writing: 1 Waiting: 0 Nginx正在读首部的请求个数 正在处理请求的主体的请求个数,或正在想client发送响应的个数 处于长连接的连接个数
定义基于域名的
虚拟主机
[[email protected] zxl]# vim /etc/nginx/nginx.conf
server {
listen 80;
server_name localhost; #为原来的server加一个域名
server_name www.b.org;
}
再定义一个server便可
server {
listen 80;
server_name www.a.org;
location / {
root /web/a.org;
index index.html;
}
[[email protected] zxl]# service nginx reload
[[email protected] zxl]# vim /etc/hosts
192.168.139.2 www.a.org
192.168.139.2 www.b.org
[[email protected] zxl]# curl http://www.a.org/index.html
<h1>www.a.org</h1>
[[email protected] zxl]# curl http://www.b.org/index.html
<h1> My Nginx_Web Server</h1>
创建LNMP: PHP+Msql
[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd -g mysql mysql
[[email protected] ~]# mkdir /mydata/data -p
[[email protected] ~]# chown -R mysql:mysql /mydata/data
[[email protected] ~]# cd /tool
[[email protected] tool]# tar -xf mysql-5.6.34.tar.gz
[[email protected] tool]# cd mysql-5.6.34
[[email protected] mysql-5.6.34]#
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
[[email protected] mysql-5.6.34]# make && make install
[[email protected] mysql]# chown -R mysql:mysql ./*
[[email protected] mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
[[email protected] mysql]# chown -R root /usr/local/mysql/*
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]# chkconfig --add mysql
[[email protected] mysql]# service mysqld start
[[email protected] mysql]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.34-log Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> \q
Bye
[[email protected] mysql]#
[[email protected] mysql]# vim /etc/ld.so.conf.d/mysql-x86_64.conf
/usr/local/mysql/lib
[[email protected] mysql]# ldconfig -v
[[email protected] lib64]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
`/usr/include/mysql‘ -> `/usr/local/mysql/include/‘
[[email protected] mysql]# vim /etc/man.config
MANPATH
/usr/local/mysql/man
[[email protected] mysql]# vim /etc/profile.d/mysql.sh
exportPATH=$PATH:/usr/local/mysql/bin
[[email protected] mysql]# source /etc/profile
[[email protected] mysql]# yum -y install libmcrypt libmcrypt-devel mhash mhash-devel mcrypt
[[email protected] tool]# tar -xf php-5.3.27.tar.bz2
[[email protected] php-5.3.27]# yum -y install libxml2-devel
[[email protected] php-5.3.27]# yum install -y libcurl-devel
[[email protected] php-5.3.27]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with-mysql=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl
如果出现如下错误
configure: error: Cannot find libmysqlclient under /usr
[[email protected] php-5.3.27]#cp /usr/lib64/mysql/libmysqlclient.so.15.0.0 /usr/lib/libmysqlclient.so
PHP 默认是去 /usr/lib/ 搜索 libmysqlclient.so 这个文件,搜不到就报那个错误。cp 一个过去就行了。
看到下面这个,说明PHP配置成功
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
[[email protected] php-5.3.27]# make && make install
/tool/php-5.3.27/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.php] Error 127
[[email protected] php-5.3.27]# vim /etc/ld.so.conf.d/mysql-x86_64.conf
/usr/local/mysql/lib
/usr/lib64/mysql
/usr/local/lib
[[email protected] php-5.3.27]# ldconfig -v
[[email protected] php-5.3.27]# make && make install
make install时出现以下错误
cp: cannot stat `ext/phar/phar.phar‘: No such file or directory
make: *** [install-pharcmd] Error 1
解决如下
[[email protected] php-5.3.27]# cd ext/phar/
[[email protected] phar]# cp ./phar.php ./phar.phar
继续
[[email protected] php-5.3.27]# make install
OK!终于成功了
[[email protected] php-5.3.27]# cp php.ini-production /etc/php.ini
[[email protected] php-5.3.27]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] php-5.3.27]# chmod +x /etc/init.d/php-fpm
[[email protected] php-5.3.27]# chkconfig --add php-fpm
[[email protected] php-5.3.27]# chkconfig php-fpm on
[[email protected] php-5.3.27]# cd /usr/local/php
[[email protected] php]# ls
bin etc include lib man sbin share var
[[email protected] php]# cd etc/
[[email protected] etc]# ls
pear.conf php-fpm.conf.default
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf
[[email protected] etc]# vim /usr/local/php/etc/php-fpm.conf
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pid = /usr/local/php/var/run/php-fpm.pid
[[email protected] etc]# service php-fpm start
Starting php-fpm done
[[email protected] etc]# ps aux | grep php-fpm
root 34955 0.4 0.9 102272 4420 ? Ss 23:22 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody 34956 0.0 0.7 102272 3568 ? S 23:22 0:00 php-fpm: pool www
nobody 34957 0.0 0.7 102272 3568 ? S 23:22 0:00 php-fpm: pool www
nobody 34958 0.0 0.7 102272 3568 ? S 23:22 0:00 php-fpm: pool www
nobody 34959 0.0 0.7 102272 3568 ? S 23:22 0:00 php-fpm: pool www
nobody 34960 0.0 0.7 102272 3568 ? S 23:22 0:00 php-fpm: pool www
nobody 34961 0.0 0.7 102272 3568 ? S 23:22 0:00 php-fpm: pool www
nobody 34962 0.0 0.7 102272 3568 ? S 23:22 0:00 php-fpm: pool www
nobody 34963 0.0 0.7 102272 3572 ? S 23:22 0:00 php-fpm: pool www
root 34965 3.0 0.1 103316 884 pts/0 S+ 23:23 0:00 grep php-fpm
php安装配置完成,进行PHP和Nginx结合
[[email protected] etc]# cd /etc/nginx/
[[email protected] nginx]# vim nginx.conf
location ~ \.php$ {
root /web/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
[[email protected] nginx]# vim fastcgi_params
#pid = /usr/local/php/var/run/php-fpm.pid
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
在主页面下加入index.php
[[email protected] nginx]# vim nginx.conf
location / {
root /web/html;
index.php index index.html index.htm;
}
[[email protected] html]# cd /web/html
[[email protected] html]# mv index.html index.html.bak
[[email protected] html]# vim index.php
<h1> My Nginx_Web Server</h1>
<?php
phpinfo();
?>
[[email protected] html]# service nginx reload
http://jiayimeng.blog.51cto.com/
[[email protected] xcache-3.2.0]tar xf xcache-3.0.3.tar.gz
[[email protected] xcache-3.2.0]cd xcache-3.0.3
[[email protected] xcache-3.2.0]/usr/local/php/bin/phpize
[[email protected] xcache-3.2.0]./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
[[email protected] xcache-3.2.0]make
Build complete.
Don‘t forget to run ‘make test‘.
[[email protected] xcache-3.2.0]make text
Thank you for helping to make PHP better.
[[email protected] xcache-3.2.0]make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so
[[email protected] xcache-3.2.0]# mkdir /etc/php.d
[[email protected] xcache-3.2.0]# cp xcache.ini /etc/php.d
[[email protected] xcache-3.2.0]# vim /etc/php.d/xcache.ini
在[xcache-common]下加入:
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so
[[email protected] xcache-3.2.0]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm [24-Dec-2016 21:41:10] NOTICE: PHP message: PHP Warning: Module ‘XCache‘ already loaded in Unknown on line 0
done
Xcache与PHP结合完成
测试php与mysql是否结合
[[email protected] ~]# vim /web/html/index.php
<h1> My Nginx_Web Server</h1>
<?php
$link=mysql_connect(‘localhost‘,‘root‘,‘‘);
if(!$link) echo "<h1>Link Fail</h1>";
else echo "<h1>Link Success</h1>";
mysql_close();
?>
[[email protected] html]# service nginx restart
Mysql与PHP结合完成
安装Discuz论坛
http://www.discuz.net/forum.php
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘192.168.%.%‘ IDENTIFIED BY ‘123456‘;
Query OK, 0 rows affected (0.18 sec)
[[email protected] tool]# unzip Discuz_X3.2_SC_GBK_\(1\).zip
复制到你的web主页面下
[[email protected] tool]# mv upload/* /web/html/
接下来直接进行浏览器web界面安装
OK!LNMP+Xcache+Discuz安装配置完成
累