一、准备工作(把安装环境需要使用到的包都下载好)
nginx
(官网):http://nginx.org/;选择稳定版本(Nginx
有很多种版本
,
比如
mainline(
主线版
),stable(
稳定版
))
1>.安装编译工具gcc、gcc-c++:
# yum -y install gcc
# yum -y install gcc-c++
2>.关闭SELinux,允许防火墙80端口访问
# vi /etc/selinux/config
SELINUX=disabled * 若安装时没有禁用SELinux ,将enforcing改为disabled;修改后需重新启动Linux方可生效!
3>.关闭防火墙Netfilter/iptables
# iptables -F * 如果没有禁用防火墙,默认80端口禁止访问
二、编译安装
*
每个源码包配置编译安装完成后,确认安装目录下是否生成安装文件
make clean(仅仅是清除之前编译的可执行文件及配置文件)
# 安装
libxml2
yum install libxml2
yum install libxml2-devel
# 安装 libxml
cd /libxml2-2.9.1
./configure --prefix=/usr/local/libxml2/
make && make install
# 安装 libmcrypt
cd /libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt/
make && make install
# 安装 libltdl,也在libmcrypt源码目录中,非新软件
cd /libmcrypt-2.5.8/libltdl
./configure --enable-ltdl-install
make && make install
# 安装mhash
cd /mhash-0.9.9.9
./configure
make && make install
# 安装
mcrypt
cd /mcrypt-2.6.8
LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/lib \
./configure --with-libmcrypt-prefix=/usr/local/libmcrypt
#以上为一条命令。LD_LIBRARY_PATH用于指定libmcrypt和mhash的库的位置。--with-libmcrypt-prefix用于指定libmcrypt软件位置
make && make install
#mcrypt没有安装完成,这是php的模块,需要等php安装完成之后,再继续安装
# 安装 zlib
cd /zlib-1.2.3
./configure
make && make install >> /root/zlib.log
* zlib指定安装目录可能造成libpng安装失败,故不指定,为卸载方便,建议make install执行结果输出到安装日志文件,便于日后卸载
# 安装 libpng
cd /libpng-1.2.31
./configure --prefix=/usr/local/libpng
make && make install
# 安装 jpeg6(目录必须手动创建)
mkdir /usr/local/jpeg6
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/include
mkdir -p /usr/local/jpeg6/man/man1
cd /lamp/jpeg-6b
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
make && make install
* --enable-shared与--enable-static参数分别为建立共享库和静态库使用的libtool
# 安装 freetype
cd /freetype-2.3.5
./configure --prefix=/usr/local/freetype/
make && make install
# 安装GD库
mkdir /usr/local/gd2
cd /lamp/gd-2.0.35
* png错误,修改方法:vi gd_png.c 为改把 #include “png.h” 替换为 #include "/usr/local/libpng/include/png.h"
./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/ --with-png=/usr/local/libpng/
make && make install
# 安装 nginx (1.11.8版本)
tar zxvf nginx-1.10.0.tar.gz
cd nginx-1.10.0.
./configure --prefix=/usr/local/nginx
make && make install
报错(缺少pcre):
yum install pcre
yum install pcre-devel
编译安装成功后,检查是否安装成功:
cd /usr/local/nginx/sbin/
(查看是否存在
nginx
文件)
./nginx -t(
出现如下字样就是成功了
)
启动nginx:./nginx
查看端口:netstat -ntlp
访问之前必须关闭Linux防火墙【iptables -F】
你也可以在你本地环境(windows)环境访问此linux
的
ip
地址,会出现以下画面:
# 安装 ncurses
yum -y install ncurses-devel
注:如果报错,包找不到,是*通配符没有识别,给文件名加双引号 “ncurses*”
cd /packet/ncurses-5.9
./configure --with-shared --without-debug --without-ada --enable-overwrite
make && make install
* 若不安装ncurses编译MySQL时会报错
* --without-ada参数为设定不编译为ada绑定,因进入chroot环境不能使用ada ;--enable-overwrite参数为定义把头文件安装到/tools/include下而不 是/tools/include/ncurses目录
* --with-shared 生成共享库
/*# 安装 cmake和bison
mysql在5.5以后,不再使用./configure工具,进行编译安装。而使用cmake工具替代了./configure工具。cmake的具体用法参考文档cmake说明。
bison是一个自由软件,用于自动生成语法分析器程序,可用于所有常见的操作系统
yum -y install cmake*/
yum -y install bison
# 安装 mysql(5.5以上版本)
groupadd mysql
useradd -g mysql mysql
* 添加用户组mysql ,将mysql用户默认组设置为mysql用户组
解压5.7.17MySQL源码包
tar -xzvf PATH/MYSQL/ & mv PATH/MYSQL/* /usr/local/mysql/
编译MySQL(记录成功的随机密码)
/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
检测下是否能启动mysql服务
cd /usr/local/mysql
./support-files/mysql.server start
创建软连接
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
创建配置文件
# cd /usr/local/mysql/support-files
cp my-default.cnf /etc/my.cnf & cp my.cnf my.cnf.bak .
修改配置文件/etc/my.cnf, 设置编码为utf8以防乱码
配置mysql服务开机自动启动
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld # 拷贝启动文件到/etc/init.d/下并重命令为mysqld
# chmod 755 /etc/init.d/mysqld # 增加执行权限
# chkconfig --list mysqld # 检查自启动项列表中没有mysqld这个,
# chkconfig --add mysqld # 如果没有就添加mysqld:
# chkconfig mysqld on # 用这个命令设置开机启动:
mysql服务的启动/重启/停止
# service mysqld start # 启动服务
# service mysqld restart # 重启服务
# service mysqld stop # 停止服务
(可略过)初始化mysql用户root密码
# cd /home/mysql
# ./bin/mysqladmin -u root -p '**mjT,#x_5sW' password '123456' mysqladmin:
修改密码方式,登录进去的情况下依次执行。
mysql>
SET
PASSWORD
=
PASSWORD
(
'123456'
); #
PASSWORD
()里面的123456 是我设置的新密码,你也可以设置成你的密码
Query OK, 0
rows
affected, 1 warning (0.00 sec)
Rows
matched: 2 Changed: 0 Warnings: 1
mysql>
ALTER
USER
'root'
@
'localhost'
PASSWORD
EXPIRE NEVER;
Query OK, 0
rows
affected, 1 warning (0.00 sec)
Rows
matched: 2 Changed: 0 Warnings: 1
mysql> flush
privileges
;
Query OK, 0
rows
affected, 1 warning (0.00 sec)
Rows
matched: 2 Changed: 0 Warnings: 1
修改查看编码
mysql> use mysql
Reading table information
for
completion of table and column names
You can turn off
this
feature to
get
a quicker startup with -A
Database changed
mysql> \s
--------------
/usr/soft/mysql/bin/mysql Ver 14.14 Distrib 5.7.13,
for
linux-glibc2.5 (x86_64)
using
EditLine wrapper
Connection id: 2
Current database: mysql
Current user: root@localhost
SSL: Not
in
use
Current pager: stdout
Using outfile:
''
Using delimiter: ;
Server version: 5.7.13 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: latin1 ---需要修改成你想要的编码
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 27 sec
Threads: 1 Questions: 43 Slow queries: 0 Opens: 136 Flush tables: 1 Open tables: 129 Queries per second avg: 1.592
--------------
mysql> show variables like
'character%'
;
+--------------------------+---------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/soft/mysql/share/charsets/ |
+--------------------------+---------------------------------+
8 rows
in
set
(0.00 sec)
mysql> SET character_set_database = utf8; ----设置编码
MySQL远程授权
[root@testfornss ~]# mysql -u root -p
Enter
password
:
Welcome
to
the MySQL monitor. Commands
end
with
;
or
\g.
Your MySQL
connection
id
is
4
Server version: 5.7.13 MySQL Community Server (GPL)
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>
grant
all
privileges
on
*.*
to
'root'
@
'%'
identified
by
'123456'
;
Query OK, 0
rows
affected, 1 warning (0.00 sec)
mysql>
连接测试是否成功。
# 安装 php(7.1.0)
下载源码wget URL
解压PHP7.1.0
安装必要库
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
编译php
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mcrypt=/usr/include --enable-mysqlnd --with-gd --with-iconv --with-zlib --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --with-curl --with-jpeg-dir --with-freetype-dir --with-mysqli --enable-embedded-mysqli --with-pdo-mysql
make
make install
make-test
[root@localhost /]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@localhost /]# cp /tar/php-7.1.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost /]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost /]# vim /usr/local/php7/etc/php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid //创建对应的文件
error_log = /data1/logs/php/php-fpm.log //创建对应的文件
log_level = notice
[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 200
pm.start_servers = 80
pm.min_spare_servers = 50
pm.max_spare_servers = 200
request_terminate_timeout = 100
request_slowlog_timeout = 2
slowlog = /data1/logs/php/slow.log
catch_workers_output = yes
使用php mcrypt 前必须先安装Libmcrypt
libmcrypt源码安装方法:
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure –prefix=/usr/local
make
make install
configure: error: off_t undefined; check your library configuration
解决办法:XXX
保存配置文件后,检验配置是否正确的方法为:
/usr/local/php/sbin/php-fpm -t
(出现test is successful字样就代表成功)
接下来就是启动php-fpm了
cp /usr/local/src/packet/php-5.6.6/sapi/fpm/init.d.php-fpm /usr/local/php/bin/php-fpm
chmod 755 /usr/local/php/bin/php-fpm
/usr/local/php/bin/php-fpm start
如果想让它开机自启动:
vi /etc/rc.local 加入下面这句
/usr/local/php/bin/php-fpm start
检测是否已成功启动(大概有20多个进程):
ps aux | grep php-fpm
到此lnmp环境就算搭建完成了,接下来就是需要配置你的nginx了........
总结一下mysql、php、nginx的启动方法(查看是否启动 ps aux|grep mysql/php/nginx):
mysql:/usr/local/mysql/bin/mysqld_safe --user=mysql &
nginx:/usr/local/nginx/sbin/nginx &
php:/usr/local/php/bin/php-fpm start