搭建环境:
操作系统:CentOS 6.7
nginx软件:nginx-1.8.1.tar.gz
mysql软件:mysql-5.5.51-linux2.6-x86_64.tar.gz
PHP软件:php-5.6.11.tar.gz
一、LNMP安装前环境准备
1、设置linux防火墙
1)在iptables上开放80,3306,443端口
[[email protected] ~]# vim /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
[[email protected] ~]# service iptables restart-----重启iptables服务
2)关闭selinux防火墙
[[email protected] ~]# vim /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[[email protected] ~]#setenforc 0
3)安装依赖包
[[email protected] ~]#yum -y
install
gcc gcc-c++ 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 openldap-clients openldap-servers
make
libtool* git tree bison pcre-devel perl gd gd-devel
4)编译安装其他软件
A:安装libiconv软件(该软件支持编码转换为函数)
[[email protected] software]# tar xf libiconv-1.14.tar.gz
[[email protected] libiconv-1.14]# .
/configure
--prefix=
/usr/local
[[email protected] libiconv-1.14]# make
&&
make
install
[[email protected] libiconv-1.14]# echo $?
0
(显示0,表示软件编译安装成功了)
B:安装libmcrypt (加密算法扩展库,支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法)
[[email protected] software]# tar xf libmcrypt-2.5.7.tar.gz
[[email protected] software]# cd libmcrypt-2.5.7
[[email protected] libmcrypt-2.5.7]# ./configure
[[email protected] libmcrypt-2.5.7]# cd libltdl/
[[email protected] libltdl]# ./configure --enable-ltdl-install
[[email protected] libltdl]# make && make install
C: 安装mhash(mhash的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存)
[[email protected] software]# tar xf mhash-0.9.9.9.tar.gz
[[email protected] software]# cd mhash-0.9.9.9
[[email protected] mhash-0.9.9.9]# ./configure && make && make install
D:安装mcript(mcrypt 是 php 里面重要的加密支持扩展库,Mcrypt扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。)
[[email protected] software]# tar xf mcrypt-2.6.8.tar.gz
[[email protected] software]# cd mcrypt-2.6.8
[[email protected] mcrypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
[[email protected] mcrypt-2.6.8]# ./configure && make && make install
E:增加库文件
[[email protected] software]# ln
-s
/usr/local/lib/libmcrypt
.la
/usr/lib/libmcrypt
.la
[[email protected] software]# ln
-s
/usr/local/lib/libmcrypt
.so
/usr/lib/libmcrypt
.so
[[email protected] software]# ln
-s
/usr/local/lib/libmcrypt
.so.4
/usr/lib/libmcrypt
.so.4
[[email protected] software]# ln
-s
/usr/local/lib/libmcrypt
.so.4.4.8
/usr/lib/libmcrypt
.so.4.4.8
[[email protected] software]# ln
-s
/usr/local/lib/libmhash
.a
/usr/lib/libmhash
.a
[[email protected] software]# ln
-s
/usr/local/lib/libmhash
.la
/usr/lib/libmhash
.la
[[email protected] software]# ln
-s
/usr/local/lib/libmhash
.so
/usr/lib/libmhash
.so
[[email protected] software]# ln
-s
/usr/local/lib/libmhash
.so.2
/usr/lib/libmhash
.so.2
[[email protected] software]# ln
-s
/usr/local/lib/libmhash
.so.2.0.1
/usr/lib/libmhash
.so.2.0.1
[[email protected] software]# ln
-s
/usr/local/bin/libmcrypt-config
/usr/bin/libmcrypt-config
F:安装cmake (MySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具)
[[email protected] ~]# yum -y install cmake
二、安装mysql数据软件
1)创建mysql用户
[[email protected] software]#groupadd -r mysql
[[email protected] software]# useradd -r -g mysql mysql -s /sbin/nologin
2)创建mysql的数据目录
[[email protected] software]# mkdir -p /data/mysqldb
3)安装mysql
[[email protected] ~]# cd /software/
[[email protected] software]# tar xf mysql-5.5.51-linux2.6-x86_64.tar.gz -C /usr/local/
[[email protected] software]# cd /usr/local/
[[email protected] local]# ll
total 48
drwxr-xr-x. 2 root root 4096 Aug 18 11:46 bin
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 games
drwxr-xr-x. 3 root root 4096 Aug 18 11:45 include
drwxr-xr-x. 3 root root 4096 Aug 18 11:45 lib
drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec
drwxr-xr-x. 3 root root 4096 Aug 18 11:41 man
drwxr-xr-x. 13 root root 4096 Aug 18 11:55 mysql-5.5.51-linux2.6-x86_64
drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin
drwxr-xr-x. 8 root root 4096 Aug 18 11:41 share
drwxr-xr-x. 2 root root 4096 Sep 23 2011 src
[[email protected] local]# ln -sv mysql-5.5.51-linux2.6-x86_64/ mysql
`mysql‘ -> `mysql-5.5.51-linux2.6-x86_64/‘
修改mysql目录权限
[[email protected] mysql]# chown -R mysql:mysql .
[[email protected] mysql]# cd /data/mysqldb/
[[email protected] mysqldb]# chown -R mysql:mysql .
初始化mysql数据库
[[email protected] ~]# cd /usr/local/mysql
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb
编辑mysql配置文件/etc/my.cnf
[mysqld]
datadir=/data/mysqldb
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
复制MySQL启动文件及其命令加入PATH
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]# chmod +x /etc/init.d/mysqld
[[email protected] mysql]# chkconfig mysqld on
[[email protected] mysql]# vim /etc/profile.d/mysqld.sh
PATH=
/usr/local/mysql/bin
:
/usr/local/mysql/lib
:$PATH
[[email protected] mysql]# source
/etc/profile
.d
/mysql
.sh
启动mysql服务器
[[email protected] etc]# service mysqld start
Starting MySQL.. [ OK ]
修改root用户的密码及授权普通用户test可以远程连接到mysql数据库
mysql> grant all on *.* to ‘root‘@‘localhost‘ identified by ‘test123‘;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to ‘test‘@‘%‘ identified by ‘test1234‘;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec