沈逸老师.web程序员角度ubuntu自修速学课程:7.手工编译安装mysql5.7.x,排坑
sudo apt-get install libxml2-dev libpcre3 libpcre3-dev libzlcore-dev -y
#说明:所有环境,我都是安装在/usr/local/sxin目录下
#所以 首先要在/usr/local目录下建sxin文件夹 然后更改文件夹所有者
#这么做不为什么,个人喜好。你也可以建个fuck目录。然后都装在fuck目录下也可以
$sudo mkdir /usr/local/sxin
$sudo chown sxin:sxin /usr/local/sxin
下载 Apache24,PHP7源码包, 解压.
http://httpd.apache.org/docs/2.4/install.html
APR,APR-util下载地址
编译安装apr
./configure --prefix=/usr/local/sxin/tools/apr
make && make install
编译安装apr-util
./configure --prefix=/usr/local/sxin/tools/apr-util --with-apr=/usr/local/sxin/tools/apr
make && make install
编译安装ZLIB
./configure --prefix=/usr/local/sxin/tools/zlib
make && make install
编译安装libiconv
./configure --prefix=/usr/local
在make的时候出错
./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
解决方案:·
#修改libiconv目录下srclib/stdio.h源码
vim srclib/stdio.h
根据出错信息定位到 gets is a security hole 这一行
删除 出错的这一行 然后加上下面代码
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif
重新make && sudo make install
sudo ldconfig
编译安装Apache
./configure --prefix=/usr/local/sxin/httpd24 --with-apr=/usr/local/sxin/tools/apr --with-apr-util=/usr/local/sxin/tools/apr-util --enable-so
make && make install
编译安装Mysql5.7
安装cmake,git,libncurses5,libncurses5-dev
sudo apt-get install cmake git libncurses5 libncurses5-dev -y
http://dev.mysql.com/downloads/mysql/
拉到最下面 选择 Source Code
下载 mysql-5.7.12.tar.gz mysql-boost-5.7.12.tar.gz
解压(自动都会解压到mysql-5.7.12)
$cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/sxin/mysql -DSYSCONFDIR=/etc/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_DATADIR=/usr/local/sxin/mysql/data -DWITH_BOOST=boost
(当依赖都安装好
yum install bison ncurses ncurses-devel
仍编译不通过提示 Could NOT find Curses。
find /usr -name libncurses*
确实查找到这个目录,用-D参数定义宏,指定头文件和库的所在目录可
用此条命令
$cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/sxin/mysql -DSYSCONFDIR=/etc/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_DATADIR=/usr/local/sxin/mysql/data -DWITH_BOOST=boost -DCURSES_LIBRARY=/usr/lib/libncurses.so -DCURSES_INCLUDE_PATH=/usr/include
)
--计算make所用时间
$time -p make
$make install
mysqld --verbose --help | grep cnf
这代表它mysql会读取配置文件,按顺序读,直至读到位置。
接下来们来模拟my.cnf丢失的情况
来到你下载的mysql文件夹中有个 supports-files
sudo mkdir /etc/mysql
sudo chown sxin:sxin /etc/mysql
cp my-default.cnf /etc/mysql
my.cnf
[client]
port = 3306
socket = /usr/local/sxin/mysql/data/mysql.sock
[mysqld]
port = 3306
socket = /usr/local/sxin/mysql/data/mysql.sock
basedir = /usr/local/sxin/mysql
datadir = /usr/local/sxin/mysql/data
初始化数据库。这个很重要
1、首要根据我们前面设置的数据库目录
2、来到bin目录
./mysqld --initialize --user=sxin --basedir=/usr/local/sxin/mysql --datadir=/usr/local/sxin/mysql/data
会告诉你一个临时密码 (root)
H1qLEhNNir-7
接下来我们就要来运行mysql服务了
直接运行mysqld_safe
进入mysql客户端 ./mysql -u root -p
输入密码
修改密码,否则不能运行
ALTER USER USER() IDENTIFIED BY ‘123’;
允许所有主机访问
Grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
flush privileges;
./mysqladmin -u root -p密码 shutdown 关闭mysql服务
编译安装php7
$./configure --prefix=/usr/local/sxin/php7 --with-config-file-path=/usr/local/sxin/php7/conf --with-apxs2=/usr/local/sxin/httpd24/bin/apxs --with-iconv-dir=/usr/local/sxin/tools/libiconv/lib --with-pdo-mysql=/usr/local/sxin/mysql --with-zlib-dir=/usr/local/sxin/tools/zlib
( 如果报 PDO_MYSQL configure failed, MySQL 4.1 needed. Please check config.log for more information. 错误
vim configure
定位到报错的这行 句首加# 进行注释
然后重新 make clean && ./config xxxxxxx )
$make ZEND_EXTRA_LIBS='-liconv' && make install
修改httpd.conf
LoadModule php7_module modules/libphp7.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
配置虚拟主机
Listen 1024
<VirtualHost *:1024>
ServerName localhost:1024
DocumentRoot /home/sxin/workspaces/phpstorm/
DirectoryIndex index.php
<Directory "/home/sxin/workspaces/phpstorm">
Options FollowSymLinks
Require all granted
</Directory>
</VirtualHost>