[[email protected] ~]# yum install -y \ 安装nginx所需要的库
pcre-devel \ //rewrite模块需要?pcre?库
zlib-devel //?gzip模块需要?zlib?库
[[email protected] ~]# useradd -M -s /sbin/nologin nginx 创建程序用户nginx
[[email protected] ~]# tar xf nginx-1.13.9.tar.gz -C /opt/ 解压
[[email protected] ~]# cd /opt/nginx-1.13.9/
[[email protected] nginx-1.13.9]# ./configure \
--prefix=/usr/local/nginx \ //指定安装路径
--user=nginx \ //指定运行用户
--group=nginx \ //指定运行组
--with-http_stub_status_module //添加日志统计模块
注:./configure报以下错误时:
Configure:error:You need a C++ compiler for C++ support
可以使用以下命令解决:yum install -y gcc gcc-c++
[[email protected] nginx-1.13.9]# make && make install
[[email protected] nginx-1.13.9]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ 软连接
[[email protected] nginx-1.13.9]# nginx -t //配置文件语法检查
[[email protected] nginx-1.13.9]# nginx //启动服务
[[email protected] nginx-1.13.9]# killall -1 nginx //安全重启
[[email protected] nginx-1.13.9]# killall -3 nginx //停止服务
启动nginx之后,浏览器中输入192.168.80.140可以验证是否安装成功:
[[email protected] nginx-1.13.9]# vi /etc/init.d/nginx //系统服务管理脚本
#!/bin/bash
#chkconfig: 35 99 20 //运行级别35,第99个开启,第20 个关闭
#description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx" //主路径程序
PIDF="/usr/local/nginx/logs/nginx.pid" //PID存放路径
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF) //根据PID终止Nginx进程
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF) //根据进程号重载配置
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1 //不正常退出,输入错误时退出
esac
exit 0
[[email protected] nginx-1.13.9]# chmod +x /etc/init.d/nginx //给予服务脚本执行权限
[[email protected] nginx-1.13.9]# chkconfig --add nginx //添加为系统服务
[[email protected] ~]# vi /usr/local/nginx/conf/nginx.conf
user nginx nginx; //把前面的注释符号去掉,运行用户,加组时,空格加组名
error_log logs/error.log info; //错误日志消息
events {
use epoll; //新增此行 默认使用select/poll,在events模块内指定epoll模型
worker_connections 1024; //表示每个工作进程允许1024个连接。
log_format main //定义日志格式 把前面的#号去掉
charset utf-8; //更改语言支持
location ~ /status { //配置统计模块
stub_status on;
access_log off;
} //在server 模块里的error_page 上面增加
[[email protected] ~]# service nginx restart
[[email protected] ~]# cat /usr/local/nginx/logs/access.log //查看连接数
在浏览器中输入http:192.168.80.140/status
//当前的活动连接数,已处理的连接数,成功的TCP握手次数,已处理的请求数.
以下配置nginx的授权认证功能
[[email protected] ~]# yum install -y httpd-tools
[[email protected] ~]# htpasswd -c /usr/local/nginx/passwd.db jack //生成用户认证文件
[[email protected] ~]# chmod 400 /usr/local/nginx/passwd.db //为了安全,更改权限和归属
[[email protected] ~]# chown nginx /usr/local/nginx/passwd.db
[[email protected] ~]# vi /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.html index.htm;
allow 192.168.80.0/24; //允许192.168.80.0网段连接
deny all; //拒绝所有
auth_basic "secret"; //添加认证配置
auth_basic_user_file /usr/local/nginx/passwd.db; //指定用户认证文件
}
[[email protected] ~]# nginx -t
[[email protected] ~]# service nginx restart
在浏览器中输入192.168.80.140进行验证:
输入我们创建的用户名和密码:
以下配置虚拟主机功能:
[[email protected] ~]# vi /usr/local/nginx/conf/nginx.conf
server { //基于域名的虚拟主机
listen 80;
server_name www.lq1.com;
charset utf-8;
access_log logs/lq1.access.log main;
location / {
root /var/www/lq1;
index index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
server {
listen 80;
server_name www.lq3.com;
charset utf-8;
access_log logs/lq3.access.log main;
location / {
root /var/www/lq3;
index index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
[[email protected] ~]# mkdir -p /var/www/lq1
[[email protected] ~]# mkdir /var/www/lq3
[[email protected] www]# cd lq1/
[[email protected] lq1]# vi index.html
[[email protected] lq1]# vi /var/www/lq3/index.html
[[email protected] www]# service nginx restart
真机验证时因为服务器没有搭建dns所以要去hosts文件做域名解析
C盘——windows——system32——drivers——etc——hosts //打开hosts路径
然后在浏览器中输入http://www.lq1.com和http://www.lq3.com,在断网情况下
安装MySQL步骤同lamp搭建过程一致,这里就不做解释了
命令如下:
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake
useradd -s /sbin/nologin mysql
tar xf mysql-boost-5.7.20.tar.gz
cd mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
make && make install
chown -R mysql.mysql /usr/local/mysql/ 也可mysql:mysql
vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
chown mysql:mysql /etc/my.cnf //更改归属,方便程序用户读取
echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH‘ >> /etc/profile
echo ‘export PATH‘ >> /etc/profile
source /etc/profile
cd /usr/local/mysql/
bin/mysqld \
--initialize-insecure \ //初始化数据库
--user=mysql \ //指定程序用户
--basedir=/usr/local/mysql \ //设置基础目录
--datadir=/usr/local/mysql/data //设置工作目录
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld
netstat -anpt | grep 3306
systemctl enable mysqld
mysqladmin -u root -p password "abc123" //给root账号设置密码
mysql -u root -p //进入数据库,进入后输入之前设置的密码
以下安装PHP
[[email protected] mysql]# yum -y install \ //安装依赖包
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
[[email protected] ~]# tar xjvf php-7.1.10.tar.bz2 -C /opt/
[[email protected] ~]# cd /opt/php-7.1.10/
[[email protected] php-7.1.10]# ./configure --prefix=/usr/local/php --with-mysql-sock=/usr/local/mysql/mysql.sock --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo --enable-tokenizer --enable-zip --enable-fpm
[[email protected] php-7.1.10]# make && make install
[[email protected] php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[[email protected] php-7.1.10]# vi /usr/local/php/lib/php.ini
mysqli.default_socket = /usr/local/mysql/mysql.sock
date.timezone = Asia/Shanghai
[[email protected] php-7.1.10]# /usr/local/php/bin/php -m
配置及优化FPM模块: //nginx处理动态网页,需要php-fpm模块
[[email protected] php-7.1.10]# cd /usr/local/php/etc/
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf
[[email protected] etc]# cd /usr/local/php/etc/php-fpm.d/
[[email protected] php-fpm.d]# cp www.conf.default www.conf
[[email protected] etc]# vi php-fpm.conf
[[email protected] etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
[[email protected] etc]# netstat -anpt | grep 9000
[[email protected] etc]# ln -s /usr/local/php/bin/ /usr/local/bin/
[[email protected] etc]# ps aux | grep -c "php-fpm"
更新启动脚本
[[email protected] etc]# vi /etc/init.d/nginx
#!/bin/bash
#chkconfig: 35 99 20 //运行级别35,第99个开启,第20 个关闭
#description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/php/sbin/php-fpm"
PIDF_FPM="/usr/local/php/var/run/php-fpm.pid"
case "$1" in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF)
kill -s QUIT $(cat $PIDF_FPM)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
[[email protected] lq]# vi /usr/local/nginx/conf/nginx.conf
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; //注意目录名称
include fastcgi_params;
}
[[email protected] lq]# nginx -t
[[email protected] etc]# cd /usr/local/nginx/html/
[[email protected] html]# vi index.php //编辑网页测试文件
<?php
phpinfo();
?>
在浏览器中输入http://192.168.80.140/index.php
[[email protected] lq]# mysql -u root -p
CREATE DATABASE bbs; //创建数据库bbs
GRANT all ON bbs. TO ‘bbsadm‘@‘%‘ IDENTIFIED BY ‘admin123‘; //给予bbsadm最大权限
GRANT all ON bbs. TO ‘bbsadm‘@‘localhost‘ IDENTIFIED BY ‘admin123‘;
flush privileges; //刷新权限
[[email protected] lq]# vi /var/www/lq/index.php
<?php
$link=mysqli_connect(‘192.168.80.140‘,‘bbsadm‘,‘admin123‘);
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
[[email protected] lq]# service nginx restart
在浏览器中输入http://192.168.80.140/index.php
以下安装Discuz论坛
[[email protected] ~]# yum install -y unzip
[[email protected] ~]# unzip Discuz_X3.4_SC_UTF8_0101.zip -d /tmp/
[[email protected] bbs]# cd /tmp/dir_SC_UTF8/
[[email protected] dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs
//放到nginx的网页根目录中正常生效
[[email protected] dir_SC_UTF8]# cd /usr/local/nginx/html/bbs
[[email protected] bbs]# chown -R root:nginx ./config/
[[email protected] bbs]# chown -R root:nginx ./data/
[[email protected] bbs]# chown -R root:nginx ./uc_client/
[[email protected] bbs]# chown -R root:nginx ./uc_server/
[[email protected] bbs]# chmod -R 777 ./config/
[[email protected] bbs]# chmod -R 777 ./data/
[[email protected] bbs]# chmod -R 777 ./uc_client/
[[email protected] bbs]# chmod -R 777 ./uc_server/
在浏览器中输入192.168.80.140/bbs/install/index.php
在浏览器中,输入192.168.80.140/bbs/index.php
原文地址:http://blog.51cto.com/13496696/2093060