lnmp

Centos7安装Lnmp环境nginx1.10.1-php5.6.22/7.0.7-mysql5.7.11

2015-01-13 15:26:51

更新时间:2016-06-04 11:18

准备工作

     安装make        yum -y install gcc automake autoconf libtool make

     安装g++          yum -y install gcc gcc-c++

1、下载nginx

           http://nginx.org/download/nginx-1.10.1.tar.gz​

2、下载php

           http://cn2.php.net/distributions/php-5.6.22.tar.gz

           http://cn2.php.net/distributions/php-7.0.7.tar.gz​

3、下载mysql​

           http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz

一、安装Nginx

下载pcre,是Nginx的重写Rewrite,zlib为了网页Gzip压缩,openssl加密传输

1、安装pcre

    https://sourceforge.net/projects/pcre/files/pcre/

    下载:http://pilotfiber.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz

    ①、首先看服务器是否已安装pcre

    ​[root@localhost src]# rpm -qa pcre

    pcre-8.32-15.el7.x86_64

上面查到了pcre已存在,但是不是最新版的,我要安装一个最新版的

​   ②、编译安装pcre

    ​[root@localhost src]# tar -zxf pcre-8.38.tar.gz

    ​[root@localhost src]# cd pcre-8.38

    ​[root@localhost pcre-8.38]# ./configure --prefix=/usr/local/pcre

    ​[root@localhost pcre-8.38]# make

    ​[root@localhost pcre-8.38]# make install

​   

2、安装zlib

下载地址:http://zlib.net/zlib-1.2.8.tar.gz

    ​[root@localhost src]# wget http://zlib.net/zlib-1.2.8.tar.gz

    ​[root@localhost src]# tar -zxf zlib-1.2.8.tar.gz

    ​[root@localhost src]# cd zlib-1.2.8

    ​[root@localhost zlib-1.2.8]# ./configure --prefix=/usr/local/zlib

    ​[root@localhost zlib-1.2.8]# make && make install

   ​

3、安装openssl

下载地址:http://www.openssl.org/source/openssl-1.0.1t.tar.gz​

    ​[root@localhost src]# wget http://www.openssl.org/source/openssl-1.0.1t.tar.gz

    ​[root@localhost src]# tar -zxf openssl-1.0.1t.tar.gz

    ​[root@localhost src]# cd openssl-1.0.1t

    ​[root@localhost openssl-1.0.1t]# ./config --prefix=/usr/local/openssl

    ​[root@localhost openssl-1.0.1t]# make && make install

    ​[root@localhost openssl-1.0.1t]# export PATH=$PATH:/usr/local/openssl/bin

    ​[root@localhost openssl-1.0.1t]# source /etc/profile

 

注意,这里安装是用config不是configure哦~~编译相对比上面久一点

4、安装gd库

[root@localhost src]# yum -y install gd-devel​

5、安装Nginx

[root@localhost nginx-1.10.1]# groupadd​ nginx​

[root@localhost nginx-1.10.1]# useradd -g nginx nginx -s /bin/false

[root@localhost nginx-1.10.1]# tar -zxf nginx-1.10.1.tar.gz​

[root@localhost nginx-1.10.1]# cd nginx-1.10.1

[root@localhost nginx-1.10.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.38 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.1t

[root@localhost nginx-1.10.1]# ​make && make install

小技巧:

       ./configure --help #可以查看编译选项,如上面的--with-http_ssl_module​

图01  

【参考文献】http://tengine.taobao.org/book/appendix_c.html#nginxlinux

​                    http://nginx.org/en/docs/configure.html

① 修改配置文件

​[root@localhost nginx-1.6.2]# vi /usr/local/nginx/conf/nginx.conf

将http -> server -> server_name改为服务器的外网ip地址,或你的网站域名​

② 启动Nginx

[root@localhost nginx-1.6.2]# /usr/local/nginx/sbin/nginx

Nginx安装完毕,这个是在虚拟机上面安装的,ip地址是192.168.1.202,这是我们用浏览器访问192.168.1.202,访问失败,什么原因,你应该很快想到是防火墙

③ 开机自启动​​

方法一:在/etc/rc.d/rc.local文件里面增加一行,如下

/usr/local/nginx/sbin/nginx

方法二:将nginx加入服务

在/etc/​rc.d/init.d/下面增加一个脚本,名称 nginx,脚本内容查看这里​

 

④ 防火墙配置

Centos6】​

1、要么关闭防火墙 [root@localhost nginx-1.8.1]# service iptables stop

2、要么配置防火墙

[root@localhost202 nginx-1.8.1]# vim /etc/sysconfig/iptables

​在里面添加一句-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

保存退出,

[root@localhost202 nginx-1.8.1]#service iptables restart

重启防火墙使配置生效​​

​Centos7】

systemctl stop firewalld.service //停止firewall

systemctl disable firewalld.service //禁止firewall开机启动

​yum -y install iptables-services​

[root@localhost202 nginx-1.8.1]# vim /etc/sysconfig/iptables

​在里面添加一句-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

​systemctl restart iptables.service #重启防火墙使配置生效

systemctl enable iptables.service #设置防火墙开机启动

 

⑤加入环境变量

​​[root@localhost ~]# vim /etc/profile​ # 在文件末尾增加如下内容

​#add by tomener ~ php mysql nginx openssl

​export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib:/usr/local/openssl/bin:/usr/local/nginx/sbin:/usr/local/php/bin

​​[root@localhost ~]# source /etc/profile

三、安装PHP

下载地址:http://cn2.php.net/distributions/php-5.6.19.tar.gz

1、安装一些必要的工具和库​

[root@localhost202 src]# yum -y install libxslt-devel 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

2、安装php

[root@localhost202 src]# wget http://cn2.php.net/distributions/php-5.6.19.tar.gz

[root@localhost202 src]# tar -zxf php-5.6.19.tar.gz

[root@localhost202 src]# cd php-5.6.19

[root@localhost202 php-5.6.19]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir --with-jpeg-dir --with-freetype-dir --with-xpm-dir=/usr/lib --with-zlib-dir=/usr/local/zlib --enable-bcmath --enable-shmop --enable-sysvsem --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-opcache --enable-pcntl --enable-sockets --enable-sysvmsg --enable-sysvsem  --enable-sysvshm --with-xmlrpc --enable-zip --enable-soap --without-pear --with-mcrypt --with-curl --with-mhash --with-openssl=/usr/local/openssl

-------------------------------------小插曲 Start---------------------------------------

编译时遇到一个错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

用rpm -qa|grep mcrypt  没有查到,

用yum -list installed | grep mcrypt,也没查到​​那我们就来安装一下了,

可以用yum安装,也可以编译安装,

3、我们就来编译安装libmcrypt

[root@localhost202 src]# wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

[root@localhost202 src]# ​tar -zxf libmcrypt-2.5.8.tar.gz

[root@localhost202 src]# ​cd libmcrypt-2.5.8

[root@localhost202 libmcrypt-2.5.8]#./configure

[root@localhost202 libmcrypt-2.5.8]# make && make install

-------------------------------------小插曲 End---------------------------------------

configure success 图02

./configure 后看见这个就表示配置没问题了,开始下面的编译和安装

[root@localhost php-5.6.19]# make

Build complete 图03     

编译完了,看上面有一句Don't forget to run 'make test'.

那我们就make test一下了

​[root@localhost php-5.6.19]# make test

make test  图04 

测试了好久,是不是我们不应该这么听话呢? 唉,慢慢等了~~~

[root@localhost php-5.6.19]# make install

make install success 图05

PHP编译安装到此结束~~ , 下面我们来配置php和php-fpm

1、php.ini配置

①查看php.ini配置文件的路径​

[root@localhost php-5.6.19]# /usr/local/php/bin/php --ini

Configuration File (php.ini) Path: /usr/local/php/lib

显示在lib下面,所有我们应该拷贝源码包里面配置文件到/usr/local/php/lib下面

[root@localhost php-5.6.19]# cp php.ini-production /usr/local/php/lib/php.ini

​②配置php.ini

     A.关闭在http头中显示php版本信息​

​     expose_php = Off

     B. 设置时区

     date.timezone = PRC​

更多配置请查看 PHP7配置文件设置

2、php-fpm配置

[root@localhost php-5.6.19]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php54/etc/php-fpm.conf

① 去掉25行 ;pid = run/php-fpm.pid  前面的分号,是之生效

② 第148行改为 user = nginx 设置php-fpm运行账号为nginx,因为我们安装nginx的时候用的是nginx这个用户,可以看上面的nginx安装那步。

③ 第149行改为 group = nginx #设置php-fpm运行组为nginx,和上面一个原理

④ 设置socket的监听

listen = /dev/shm/php-fpm.sock​

listen.owner = nginx​

listen.group = nginx

3、设置php-fpm开机自启动

​[root@localhost php-5.4.36]# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@localhost php-5.4.36]# chmod 0755 /etc/init.d/php-fpm

[root@localhost php-5.4.36]# chkconfig --level 35 php-fpm on

然后可以用chkconfig --list 来查看是否将php-fpm添加到了自启动​

4、启动php-fpm

[root@localhost html]# /usr/local/php/sbin/php-fpm

当然,第3步我们已经把php-fpm加入了开机自启动,也就是加入了服务,所有,我就可以用这样的命令来控制php-fpm了:

​[root@localhost html]# service php-fpm start|restart|stop|reload|status|force-quit

5、配置nginx支持php脚本

修改哪里呢?这还问么,自然是nginx的配置文件了

​​[root@localhost nginx]# vim /usr/local/nginx/conf/nginx.conf​

①顶部的user那行设置为 user nginx nginx

②找到

location ​/ {

      root    html;

      index index.html index.htm

}​

改为:

​location ​/ {

      root    /data/webroot;

      index index.php index.html index.htm

}​​

③如下图:

图06  

 Nginx + PHP-FPM设置虚拟主机 + 开启PATHINFO模式

6、重启nginx

[root@localhost nginx]# /usr/local/nginx/sbin/nginx -s reload

7、修改web根目录的所有者所属组

​[root@localhost nginx]# chown -R nginx:nginx /data/webroot

这步,先可以不做​

8、测试php-fmp是否配置成功

[root@localhost nginx]# vim /usr/local/nginx/html/phpinfo.php

echo phpinfo();

:wq

http://localhost/phpinfo.php

--------------------------------------------------------------------------------------​

小提示:php核心编译选项:http://php.net/manual/zh/configure.about.php

查看更多选项 ./configure --help 或者

./configure --help >> /data/php-configure.txt 从定向到文件,拿到本地来慢慢研究

二、安装MySQL​

安装一些必要的软件:ncurses-devel、cmake

刚开始没装ncurses-devel,编译不成功,然后yum install ncurses-devel,后面编译就成功了。

MySQL从5.5开始使用cmake来编译安装了,

1、安装cmake

下载地址:http://www.cmake.org/files/v3.1/cmake-3.1.0.tar.gz​

    ​[root@localhost src]# wget http://www.cmake.org/files/v3.1/cmake-3.1.0.tar.gz

    ​[root@localhost src]# tar -zxf cmake-3.1.0.tar.gz

    ​[root@localhost src]# cd cmake-3.1.0

    ​[root@localhost cmake-3.1.0]# ./configure --prefix=/usr/local/cmake

    ​[root@localhost cmake-3.1.0]# make

    ​[root@localhost cmake-3.1.0]# make install

​    [root@localhost cmake-3.1.0]# export PATH=$PATH:/usr/local/openssl/bin​

    [root@localhost cmake-3.1.0]# source /etc/profile

 

 

小提示:下载有点满,5.7M下了10多分钟~~,查看cmake是否安装:

which cmake 或者 whereis cmake

2、安装MySQL

下载地址:http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz

                 http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz

    ​[root@localhost src]# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz

    ​[root@localhost src]# tar -zxf mysql-5.6.22.tar.gz

    ​[root@localhost src]# cd mysql-5.6.22

    ​[root@localhost mysql-5.6.22]# groupadd mysql

    ​[root@localhost mysql-5.6.22]# useradd -g mysql mysql -s /bin/false

    ​[root@localhost mysql-5.6.22]# mkdir -p /usr/local/mysql

    ​[root@localhost mysql-5.6.22]# mkdir -p /data/mysql

    [root@localhost mysql-5.6.22]# chown -R mysql:mysql /data/mysql

    ​[root@localhost mysql-5.6.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci​​

    ​[root@localhost mysql-5.6.22]# make

    ​[root@localhost mysql-5.6.22]# make install

    ​[root@localhost mysql-5.6.22]# cd /usr/local/mysql

 

5.7版本在cmake的时候需要增加两个参数  -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost​​

小提示:如果cmake后出错,需删除mysql-5.6.22目录下面的CMakeCache.txt这个文件后再cmake,我就是开始cmake出错了,安装了ncurses-devel后再cmake

 

参考文献:http://my.oschina.net/looly/blog/297980

编译参数:

http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

可能遇到问题:

1、Warning: Bison executable not found in PATH
​解决: yum -y install bison

2、Could NOT find Git (missing: GIT_EXECUTABLE)​

解决: yum -y install git

~~~~~~~~~~~~~MySQL安装完毕~~~~~~~~~~~​

配置MySQL​

1、初始化mysql数据库

​[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb/ #生成mysql系统数据库

2、复制mysql服务启动配置文件

[root@localhost support-files]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

3、复制mysql服务启动脚本及加入PATH路径

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@localhost mysql]# vim /etc/profile #编辑profile添加环境变量

在profile最后加上:
​# add by Tomener ~ mysql,openssl

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib:/usr/local/openssl/bin

保存退出​​

[root@localhost mysql]# source /etc/​profile

4、启动MySQL

[root@localhost202 mysql]# service mysqld start

Starting MySQL... SUCCESS!

​5、将MySQL加入开机自启动

[root@localhost202 mysql]# chkconfig --level 35 mysqld on​

6、检查MySQL是否已启动

[root@localhost202 mysql]# netstat -ntpl | grep mysql​

看见3306端口就表示启动了~~

7、用mysql客服端登录

​[root@localhost202 mysql]# mysql -u root -p

密码是空的,直接回车

8、修改MySQL的root密码

[root@localhost202 mysql]# mysql_secure_installation​

这里可以设置root的密码(我们设置为tomenr888),删除匿名用户,设置是否阻止root帐号远程登录,是否删除test库,是否从新加载权限表

第二种方法,一般安装完MySQL后root密码都为空,我们可以mysql客服端里面修改

mysql> set password for root@localhost = password('tomener888');

Query OK, 0 rows affected (0.10 sec)​

当然设置root的密码有很多方法,可自行百度

9、添加MySQL用户

​首先进入mysql客服端

[root@localhost202 mysql]#mysql -u root -p

mysql>​create user 'tomener'@'localhost' IDENTIFIED BY 'tomenr888';

 更多关于MySQL用户知识,请看我之前的一篇文章:

http://blog.sina.com.cn/s/blog_75ad10100101o3hi.html

完毕~~

本文来自:http://blog.sina.com.cn/tomener

原文链接:​http://blog.sina.com.cn/s/blog_75ad10100102vc14.html

posted @ 2016-08-31 02:19  招斯文  阅读(238)  评论(0编辑  收藏  举报