CentOS6.9编译安装LNMP环境php
今天尝试一下用编译的方式来搭建lnmp运行环境。全部软件都采用当前最新版本,除了CentOS。这是因为目前企业大多数应该都还在使用CentOS6的缘故,而且CentOS7目前还在迭代中。虽然说不会有大的改动,但也算不上彻底稳定下来吧。html
那么开始吧,此次也是边装边写的方式。java
运行环境和软件版本python
CentOS是运行在Virtual Box虚拟机上的 CentOS 6.9 x86_64 minimal 版本。宿主机是Windows10家庭普通版64位,这一点关系不大,姑且说明一下。在安装好系统后依次运行了 yum update yum groupinstall "development tools" yum install vim yum install wget 来更新系统、安装开发者环境包、安装vim和wget。mysql
Nginx、PHP、MySQL使用当前最新版本的 nginx-1.12.0 php-7.1.4 mysql-5.7.18 。linux
安装步骤nginx
1.下载要安装的软件包c++
我这里是直接在虚拟机上用wget工具下载,命令以下:git
1 wget http://nginx.org/download/nginx-1.12.0.tar.gz -O /usr/local/src/nginx-1.12.0.tar.gzweb
1 wget http://am1.php.net/distributions/php-7.1.4.tar.gz -O /usr/local/src/php-7.1.4.tar.gz
1 wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.18.tar.gz -O /usr/local/src/mysql-boost-5.7.18.tar.gz
固然你也能够在其它地方下载好再传到虚拟机上,随意。
注意文件访问权限,有些文件夹非root用户是不能访问的。还有,之因此选择mysql-boost-5.7.18.tar.gz这个安装包是由于mysql5.7编译安装须要用到boost,因此干脆选择了带boost的版本。虽然我也不太明白boost是个啥,好像是编译器的一种?
下载完毕:
接下来就开始编译安装了。
2.编译安装Nginx
就先从nginx开始吧。首先解压:
1 tar -zxv -f /usr/local/src/nginx-1.12.0.tar.gz -C /usr/local/src/
解压完成:
而后进入解压目录:
1 cd /usr/local/src/nginx-1.12.0
经过 ls 命令能够查看解压结果里包含了哪些文件。经过 ./configure --help | less 命令查看编译选项,按 q 退出。
不过我这里只会安装 --with-http_ssl_module 、 --with-http_stub_status_module 、 --with-http_auth_request_module 、 --with-http_perl_module 、 --with-mail 、 --with-stream 、 --with-pcre 这几个模块。
安装模块须要环境的支持,考虑到我以前已经安装了development tools,应该没问题的。若是缺的话,报错了再补。
而后,须要建立nginx运行帐号和nginx安装目录,命令以下:
1 useradd nginx -s /sbin/nologin -M
2 mkdir /usr/local/nginx-1.12.0
能够经过 cat /etc/passwd 和 ls /usr/local 查看建立的帐号和目录。
接下来执行预编译脚本,以下:
1 ./configure \
2 --prefix=/usr/local/nginx-1.12.0 \
3 --user=nginx \
4 --group=nginx \
5 --with-select_module \
6 --with-poll_module \
7 --with-http_ssl_module \
8 --with-http_stub_status_module \
9 --with-http_auth_request_module \
10 --with-http_perl_module \
11 --with-mail \
12 --with-stream \
13 --with-pcre
而后报错了:
1 ./configure: error: the HTTP rewrite module requires the PCRE library.
2 You can either disable the module by using --without-http_rewrite_module
3 option, or install the PCRE library into the system, or build the PCRE library
4 statically from the source with nginx by using --with-pcre=<path> option.
看来是缺乏pcre支持,那么补上: yum install pcre-devel pcre-static ,而后再执行一次。
此次是缺乏openssl:
1 ./configure: error: SSL modules require the OpenSSL library.
2 You can either do not enable the modules, or install the OpenSSL library
3 into the system, or build the OpenSSL library statically from the source
4 with nginx by using --with-openssl=<path> option.
执行 yum install openssl-devel openssl-perl openssl-static ,而后再执行一次。
又又报错了:
1 checking for perl
2 + perl version: v5.10.1 (*) built for x86_64-linux-thread-multi
3 Can't locate ExtUtils/Embed.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
4 BEGIN failed--compilation aborted.
5
6 ./configure: error: perl module ExtUtils::Embed is required
好像又是少了什么东西,搜索了一下,大概是要装这个: yum install perl-ExtUtils-Embed 。那么,再再执行一次吧。
此次没报错,执行预编译脚本成功。
能够编译安装了,分别执行 make 和 make install 吧。
等执行完毕,用 ls /usr/local/nginx-1.12.0 命令能够看到安装目录下有文件生成,接下来执行nginx命令查看是否成功安装。
执行 /usr/local/nginx-1.12.0/sbin/nginx -t ,结果以下:
说明安装成功。接着执行 /usr/local/nginx-1.12.0/sbin/nginx 就能够启动nginx服务。
执行 curl http://localhost 能够看到以下结果:
默认的主页html文件内容被获取了,说明服务确实成功启动。
为了避免影响接下来的操做,执行 /usr/local/nginx-1.12.0/sbin/nginx -s quit 关闭nginx服务。
接下来安装PHP。
3.编译安装PHP
先解压: tar -zxv -f /usr/local/src/php-7.1.4.tar.gz -C /usr/local/src/ 。
建立安装目录: mkdir /usr/local/php-7.1.4 。
进入安装包目录: cd /usr/local/src/php-7.1.4 ,能够经过执行预编译脚本 ./configure --help | less 来查看有哪些安装选项。
能够看到php的安装选项众多,扩展数量多也是php的强大之处。
考虑到经常使用的功能和特性,还有php能够在安装后安装扩展,如今仍是尽量少的选择安装选项吧。
1 ./configure \
2 --prefix=/usr/local/php-7.1.4 \
3 --enable-fpm \
4 --with-fpm-user=nginx \
5 --with-fpm-group=nginx \
6 --with-mysqli \
7 --with-pdo-mysql \
8 --with-zlib \
9 --with-gd \
10 --with-curl \
11 --with-mcrypt \
12 --enable-mbstring \
13 --enable-soap \
14 --enable-zip \
15 --enable-ftp \
16 --with-openssl
稍微查了一下,暂且按上述选项编译吧。
报错了:
1 configure: error: xml2-config not found. Please check your libxml2 installation.
望文生义貌似是libxmls的缺乏形成的。那么执行 yum install libxml2 libxml2-devel libxml2-static 补上我猜可能必要的开发环境。而后接着执行上述的预编译脚本。
又报错了:
1 configure: error: Please reinstall the libcurl distribution -
2 easy.h should be in <curl-dir>/include/curl/
此次是libcurl,补上 yum install libcurl libcurl-devel ,再来。
又又报错了:
1 checking for GD support... yes
2 checking for the location of libwebp... no
3 checking for the location of libjpeg... no
4 checking for the location of libpng... no
5 checking for the location of libXpm... no
6 checking for FreeType 2... no
7 checking whether to enable truetype string function in GD... no
8 checking whether to enable JIS-mapped Japanese font support in GD... no
9 If configure fails try --with-webp-dir=<DIR>
10 If configure fails try --with-jpeg-dir=<DIR>
11 configure: error: png.h not found.
此次是和GD库又关,由于是和图像处理有关的扩展,因此jpeg、png、gif等图像开发环境是必要的。
可是我想尽量少安装,因此先试试 yum install gd gd-devel 。而后执行预编译脚本。
gd库的检测经过了,可是出现了新的错误:
1 configure: error: mcrypt.h not found. Please reinstall libmcrypt.
此次是mcrypt库的问题,问题是CentOS6.9的yum库已经不支持mcrypt的安装,改用gcrypt了。没办法,本身下载吧。
根据php的官方文档:
这些函数须要使用 » mcrypt 库。 请从 » http://mcrypt.sourceforge.net/ 下载 libmcrypt-x.x.tar.gz, 并按如下指导完成安装。
从 PHP 5.0.0 开始,你须要使用 libcrypt 2.5.6 或更高版本。
PHP 5.2 的 Windows 二进制发行版中已经包含了本库。 PHP 5.3 的 Windows 二进制发行版中开始使用 MCrypt 静态库, 因此再也不须要 DLL。
若是使用 libmcrypt 2.4.x 或更高版本连接编译 PHP,支持如下附加的分组加密算法: CAST,LOKI97,RIJNDAEL,SAFERPLUS,SERPENT, 以及如下流密码:ENIGMA(加密), PANAMA,RC4 和 WAKE。 若是使用 libmcrypt 2.4.x 或更高版本,那么还支持 nOFB 密码模式。
能够知道php所须要的mcrypt库的下载地址和安装方法,照作就能够了。
先下载 wget https://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz -O /usr/local/src/libmcrypt-2.5.8.tar.gz ,而后解压 tar -zxv -f /usr/local/src/libmcrypt-2.5.8.tar.gz -C /usr/local/src/ ,建立安装目录 mkdir/usr/local/libmcrypt-2.5.8 ,进入解压生成的目录 cd /usr/local/src/libmcrypt-2.5.8 ,执行预编译脚本 ./configure --prefix=/usr/local/libmcrypt-2.5.8 ,编译和安装 make && make install 。到此,libmcrypt的安装就完成了。接着进入php安装包解压生成的目录执行php的预编译脚本。
执行后发现仍是报和以前同样的错误,多是安装libmcrypt时自定义了安装路径的缘由。这里须要修改一下php的预编译脚本的编译选项:
1 ./configure \
2 --prefix=/usr/local/php-7.1.4 \
3 --enable-fpm \
4 --with-fpm-user=nginx \
5 --with-fpm-group=nginx \
6 --with-mysqli \
7 --with-pdo-mysql \
8 --with-zlib \
9 --with-gd \
10 --with-curl \
11 --with-mcrypt=/usr/local/libmcrypt-2.5.8 \
12 --enable-mbstring \
13 --enable-soap \
14 --enable-zip \
15 --enable-ftp \
16 --with-openssl
注意第11行, --with-mcrypt 选项指明了安装路径。再次执行php的预编译脚本,此次没有报错,执行成功。
接着只要依次执行 make 和 make install 就能够了,固然也能够放在一块儿执行 make && make install 。
通常在编译和安装的过程当中是不会出什么问题,我也历来没在这出过问题,因此也没有解决的经验。
而后就是简单配置一下看看能不能用。
根据预编译选项 --prefix 和帮助信息,得知php.ini文件应该放在[PREFIX]/lib目录下。那么咱们就在该目录下生成一个配置文件吧: cp/usr/local/src/php-7.1.4/php.ini-development /usr/local/php-7.1.4/lib/php.ini 。我记得不用改什么吧。
而后是php-fpm。首先 cp /usr/local/php-7.1.4/etc/php-fpm.conf.default /usr/local/php-7.1.4/etc/php-fpm.conf ,大概看了一下,还须要 cp/usr/local/php-7.1.4/etc/php-fpm.d/www.conf.default /usr/local/php-7.1.4/etc/php-fpm.d/www.conf 。内容不用改,反正是试运行。
还须要配置一下nginx并启动,执行 vim /usr/local/nginx-1.12.0/conf/nginx.conf :
将65行至71行的注释去掉,并将69行的内容按上图改动,接着保存退出。
生成一个测试用的php脚本 vim /usr/local/nginx-1.12.0/html/index.php :
注意文件位置。
启动nginx服务: /usr/local/nginx-1.12.0/sbin/nginx 。或者在启动前检查一下配置文件是否出错: /usr/local/nginx-1.12.0/sbin/nginx -t 。
启动php-fpm: /usr/local/php-7.1.4/sbin/php-fpm 。
关闭iptables: service iptables stop 。
而后在宿主机的浏览器内输入 http://192.168.31.222/index.php 。前面的ip地址因人而异,能够经过 ifconfig 命令查看。显示以下页面说明成功了:
能够经过 ps -aux | grep "php-fpm" 命令查看php-fpm的主进程号,而后经过 kill -quit 2505 来关闭服务。注意这个2505是个人虚拟机上运行的php-fpm的主进程号,这个号码通常都是不一样的。
4.编译安装MySQL
5.7版本的MySQL编译和初始化都挺麻烦的,尤为是要自定义安装路径和选项。走到这一步我也不肯定可否顺利安装好,姑且按照文档走一步算一步吧。
经过文档的2.9 Installing MySQL from Source这一章节能够知道,cmake工具在编译时是必要的。此外,还须要安装boost。若是安装的是development source tree这一版本,还须要安装git和bison。
那么先准备安装环境吧。执行 yum install cmake 来安装cmake。虽然不知道development source tree是什么,可是为了以防万一仍是把git和bison也装上吧: yum install bison git 。
解压安装包: tar -zxv -f /usr/local/src/mysql-boost-5.7.18.tar.gz -C /usr/local/src/ 。经过 ls /usr/local/src/mysql-5.7.18/ 命令能够看到解压生成的目录中附带了boost。
一层层的看进去发现并非安装文件,更像是已经安装好的文件,那咱们就不用再安装boost了。反正根据文档,boost只是在编译的时候用到。
那么如今查看文档看看安装的步骤吧。
首先要建立MySQL服务运行时的帐户 useradd mysql -s /sbin/nologin -M 。而后建立安装目录 mkdir /usr/local/mysql-5.7.18 。
接着进入解压生成的目录 cd /usr/local/src/mysql-5.7.18/ 。能够经过 ls 命令查看目录下的文件。还能够经过 cmake . -LAH | less 来查看帮助和安装选项。
发现经过上述命令获取的帮助信息很差懂且没有调理,仍是得看文档2.9.4 MySQL Source-Configuration Options。研究了一下,编译选项以下:
1 cmake . \
2 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.18 \
3 -DWITH_BOOST=/usr/local/src/mysql-5.7.18/boost
打算偷个懒,就这样预编译试试看吧。
啊,报错了:
1 -- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
2 CMake Error at cmake/readline.cmake:64 (MESSAGE):
3 Curses library not found. Please install appropriate package,
4
5 remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
6 Call Stack (most recent call first):
7 cmake/readline.cmake:107 (FIND_CURSES)
8 cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE)
9 CMakeLists.txt:488 (MYSQL_CHECK_EDITLINE)
10
11
12 -- Configuring incomplete, errors occurred!
13 See also "/usr/local/src/mysql-5.7.18/CMakeFiles/CMakeOutput.log".
14 See also "/usr/local/src/mysql-5.7.18/CMakeFiles/CMakeError.log".
查了一下,好像是缺ncurses组件。那就补上吧: yum install ncurses ncurses-devel ncurses-libs ncurses-static 。以后再次执行预编译。
再次执行却以更快的速度报同样的错,仔细一看原来少执行了一步操做: remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel. 。好吧,删掉目录下的CMakeCache.txt文件 rm CMakeCache.txt ,而后再次执行。
此次顺利预编译完了:
接下来依次执行 make 和 make install 就好了。
编译的过程至关之慢,我去作其余事情好了。
编译过程当中报了这个错误,不知道有什么影响没有。话说这和boost有关吧?难道是个人boost没好好安装的缘由?
阿西吧,终于编译完了,中间我洗了个澡还看了集动漫。接着执行 make install 。
我擦,报错了:
1 CMake Error at libmysqld/examples/cmake_install.cmake:44 (FILE):
2 file INSTALL cannot copy file
3 "/usr/local/src/mysql-5.7.18/libmysqld/examples/CMakeFiles/CMakeRelink.dir/mysql_client_test_embedded"
4 to "/usr/local/mysql-5.7.18/bin/mysql_client_test_embedded".
5 Call Stack (most recent call first):
6 cmake_install.cmake:122 (INCLUDE)
7
8
9 make: *** [install] Error 1
算了算了,时间不早了。先睡觉,明天再说吧。
我回来了。
查了一下,上述错误是由缺乏gcc和gcc-c++引发的,那就干脆补上全部有关的: yum install gcc gcc-c++ gcc-java gcc-gnat libgcc compat-gcc-34compat-gcc-34-c++ compat-gcc-34-g77 gcc-objc gcc-objc++ 。
我勒个擦,虚拟机的硬盘满了:
1 Running rpm_check_debug
2 Running Transaction Test
3
4
5 Transaction Check Error:
6 installing package gcc-objc-4.4.7-18.el6.x86_64 needs 11MB on the /usr filesystem
7 installing package ecj-1:4.5.2-3.el6.x86_64 needs 21MB on the /usr filesystem
8 installing package libgnat-devel-4.4.7-18.el6.x86_64 needs 46MB on the /usr filesystem
9 installing package libgnat-4.4.7-18.el6.x86_64 needs 50MB on the /usr filesystem
10 installing package gcc-gnat-4.4.7-18.el6.x86_64 needs 73MB on the /usr filesystem
11 installing package jpackage-utils-0:1.7.5-3.16.el6.noarch needs 73MB on the /usr filesystem
12 installing package compat-gcc-34-c++-3.4.6-19.el6.x86_64 needs 162MB on the /usr filesystem
13 installing package gcc-java-4.4.7-18.el6.x86_64 needs 172MB on the /usr filesystem
14 installing package compat-gcc-34-3.4.6-19.el6.x86_64 needs 185MB on the /usr filesystem
15 installing package compat-libf2c-34-3.4.6-19.el6.x86_64 needs 185MB on the /usr filesystem
16 installing package libgcj-devel-4.4.7-18.el6.x86_64 needs 203MB on the /usr filesystem
17 installing package gcc-objc++-4.4.7-18.el6.x86_64 needs 213MB on the /usr filesystem
18 installing package java_cup-1:0.10k-5.el6.x86_64 needs 214MB on the /usr filesystem
19 installing package compat-gcc-34-g77-3.4.6-19.el6.x86_64 needs 220MB on the /usr filesystem
20 installing package sinjdoc-0.5-9.1.el6.x86_64 needs 223MB on the /usr filesystem
21 installing package libobjc-4.4.7-18.el6.x86_64 needs 223MB on the /usr filesystem
22 installing package java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64 needs 223MB on the /usr filesystem
23
24 Error Summary
25 -------------
26 Disk Requirements:
27 At least 223MB more space needed on the /usr filesystem.
这叫老夫如何是好,网上查查怎么加硬盘或者从新分区之类的吧。实在不行只能重装了。
网上看了看,可能要用到fdisk和Virtual Box Manager。我都不太熟并且好麻烦QAQ,算了算了,重装一个虚拟机吧orz
此次分30G给/usr/local,总没问题了吧。
等等等等,仔细看了一下,发现容量都是被下载的软件包和解压包给占据了,只要把它们删掉就好。
总之,删掉就行了。
啊~不用重装了,被救赎。
继续吧,运行 yum install gcc gcc-c++ gcc-java gcc-gnat libgcc compat-gcc-34 compat-gcc-34-c++ compat-gcc-34-g77 gcc-objc gcc-objc++ 。
考虑到以前编译MySQL的过程当中好像报了boost相关的warning,决定仍是老老实实的安装boost吧。
首先下载安装包:
1 wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.18.tar.gz -O /usr/local/src/mysql-5.7.18.tar.gz
1 wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz -O /usr/local/src/boost_1_59_0.tar.gz
此次换不带boost的MySQL版本,而后按文档里说的,boost必须是1.59版本。
用wget下载boost实在太慢了,最后我上了迅雷,下载好后传到了虚拟机上。
解压boost tar -zxv -f /usr/local/src/boost_1_59_0.tar.gz -C /usr/local/src/ 。建立安装目录 mkdir /usr/local/boost-1.59.0 。进入解压生成的目录 cd /usr/local/src/boost-1.59.0 。执行预编译脚本 ./bootstrap.sh --prefix=/usr/local/boost-1.59.0 。而后执行 ./b2 ,这一步必较久,等着吧。报了一些看不懂的错误,查了一下还要安装依赖什么的,那就装上吧 yum install gcc gcc-c++ bzip2 bzip2-libs bzip2-devel python python-devel 。删掉解压的目录前面的步骤再执行一次。接着执行 ./b2 install 就ok了。
接下来从新编译安装MySQL。
删除以前的安装生成文件 rm -rf /usr/local/mysql-5.7.18/* 。解压新的安装文件 tar -zxv -f /usr/local/src/mysql-5.7.18.tar.gz -C /usr/local/src/ 。进入解压生成的目录 cd /usr/local/src/mysql-5.7.18 。执行预编译命令 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.18 -DWITH_BOOST=/usr/local/boost-1.59.0 。
啊,报错了:
1 CMake Error at cmake/boost.cmake:81 (MESSAGE):
2 You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
3
4 This CMake script will look for boost in <directory>. If it is not there,
5 it will download and unpack it (in that directory) for you.
6
7 If you are inside a firewall, you may need to use an http proxy:
8
9 export http_proxy=http://example.com:80
10
11 Call Stack (most recent call first):
12 cmake/boost.cmake:167 (COULD_NOT_FIND_BOOST)
13 CMakeLists.txt:460 (INCLUDE)
14
15
16 -- Configuring incomplete, errors occurred!
17 See also "/usr/local/src/mysql-5.7.18/CMakeFiles/CMakeOutput.log".
18 See also "/usr/local/src/mysql-5.7.18/CMakeFiles/CMakeError.log".
想一想应该是预编译时boost的包含路径有问题,应该包含安装生成文件里的include目录。那么,依次执行 rm CMakeCache.txt 和 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.18 -DWITH_BOOST=/usr/local/boost-1.59.0/include 。
结果ok。接下来执行 make 和 make install 就能够了。
漫长的等待过程,去干点别的吧。
终...终于好了。
接下来就是初始化了。
按照文档,要先修改安装目录和文件所属组和所属用户 chgrp -R mysql /usr/local/mysql-5.7.18 chown -R mysql /usr/local/mysql-5.7.18 。
接下来建立一个放数据库文件、socket文件、pid文件和配置文件的目录,就放在/var目录下好了
1 mkdir /var/local/mysql-5.7.18
2 mkdir /var/local/mysql-5.7.18/data
3 mkdir /var/local/mysql-5.7.18/run
4 mkdir /var/local/mysql-5.7.18/log
5 mkdir /var/local/mysql-5.7.18/etc
生成一个配置文件 vim /var/local/mysql-5.7.18/etc/my.cnf ,内容为:
[client]
port=3306
socket=/var/local/mysql-5.7.18/run/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
basedir=/usr/local/mysql-5.7.18
datadir=/var/local/mysql-5.7.18/data
user=mysql
port=3306
socket=/var/local/mysql-5.7.18/run/mysql.sock
pid-file=/var/local/mysql-5.7.18/run/mysql.pid
网上抄来的,似懂非懂。
把上述目录和文件都修改所属 chgrp -R mysql /var/local/mysql-5.7.18 chown -R mysql /var/local/mysql-5.7.18 。
而后执行初始化命令:
1 /usr/local/mysql-5.7.18/bin/mysqld \
2 --defaults-file=/var/local/mysql-5.7.18/etc/my.cnf \
3 --initialize \
4 --character_set_server=utf8 \
5 --collation_server=utf8_general_ci
虽然报了一些看不懂的警告,可是初始化好像是成功了,还生成了随机密码:
1 2017-04-24T10:27:35.480795Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2 2017-04-24T10:27:36.378470Z 0 [Warning] InnoDB: New log files created, LSN=45790
3 2017-04-24T10:27:36.557201Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
4 2017-04-24T10:27:36.666538Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a2c08f2f-28d8-11e7-b53a-08002728b6d3.
5 2017-04-24T10:27:36.673556Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
6 2017-04-24T10:27:36.676216Z 1 [Note] A temporary password is generated for root@localhost: jyJoLj>9G_!-
接下来试着启动服务 /usr/local/mysql-5.7.18/bin/mysqld --defaults-file=/var/local/mysql-5.7.18/etc/my.cnf & ,按 Ctrl + C 退出控制台占用,执行 /usr/local/mysql-5.7.18/bin/mysql --defaults-file=/var/local/mysql-5.7.18/etc/my.cnf -u root -p ,以后要输入密码。后面的密码来自以前初始化后成功的提示的最后一行。
5.8版本规定进入MySQL后并不能执行任何操做,必须先改密码 ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; 。且密码必须大于8位,包含字符数字字母,真是烦死了。
如图,终于成功了。接下来能够执行 exit 退出。再接着能够执行 /usr/local/mysql-5.7.18/bin/mysqladmin --defaults-file=/var/local/mysql-5.7.18/etc/my.cnf shutdown -u root -p 后输入密码来结束服务。
至此,MySQL5.7.18终于他喵的装好了。
5.测试Nginx、PHP和MySQL协同工做
接下来就是让这三个软件协同工做,成为一个能够跑php代码的环境。
首先启动全部服务:
1 /usr/local/nginx-1.12.0/sbin/nginx
2 /usr/local/php-7.1.4/sbin/php-fpm
3 /usr/local/mysql-5.7.18/bin/mysqld --defaults-file=/var/local/mysql-5.7.18/etc/my.cnf &
记得关闭iptables服务 service iptables stop 。
在数据库中建立一个test数据库。
建立一个测试用的PHP脚本 vim /usr/local/nginx-1.12.0/html/mysql.php vim /usr/local/nginx-1.12.0/html/mysql.php ,其内容为:
1 <?php
2 echo "hello world";
3 echo "<br>";
4 echo "MySQLi<br>";
5 $mysqli=new mysqli("127.0.0.1","root",'!@#123qwe',"test");
6 if($mysqli->connect_error){
7 echo "数据库链接失败!";
8 }else{
9 echo "数据库链接成功!";
10 }
11 echo "<br>";
12 echo "PDO<br>";
13 try{
14 $dbc=new PDO("mysql:host=127.0.0.1;dbname=test","root","!@#123qwe");
15 }catch(PDOExtension $e){
16 echo "数据库链接失败:".$e->getMessage();
17 }
18 echo "数据库链接成功!";
19 ?>
而后访问这个脚本 http://192.168.31.222/mysql.php ,结果以下:
OK~没有问题~
总结
一步步操做下来,发现环境搭配对萌新来讲一点都不友好。因此我以为志不在运维的同窗仍是用集成环境吧,那个多省事的。
还有半吊子就不要参与运维了,会给人添麻烦的。
这还只是配了个能跑的环境,还没考虑性能的优化,MySQL主从这些蛋疼的东西。因此运维仍是得交给专业的来。
有空的话多学学MySQL,颇有必要。