安装gcc
yum -y install gcc gcc-c++
一、安装Mysql5.6
******* mysql安装后初始密码在mysql的错误日志中,通过源码安装,在初始化数据库是会提醒初始密码,注意观察
1、安装yum
下载yum包
wget http://yum.baseurl.org/download/3.2/yum-3.2.28.tar.gz
解压:
tar -zxvf yum-3.2.28.tar.gz
安装yum
./yummain.py install yum
2、mysql5.5以后要使用cmake
安装gcc 和 cmake 和其他一些依赖
yum install cmake gcc-c++ ncnrses-devel perl-Data-Dumper boost boost-doc boost-devel
清理环境
检查boost版本:
rpm -qa boost*
卸载boost-*等库:
yum -y remove boost-*
下载 boost
wget http://www.boost.org/users/download/
tar -zxvf boost_1_59_0.tar.gz
移动到指定路径
mv boost_1_59_0 /usr/local/boost
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DWITH_BOOST=/usr/local/boost \
-DDEFAULT_COLLATION=utf8_general_ci
然后 make; make install
如果编译出现错误,请先删除CMakeCache.txt后,再重新编译:
rm -rf CMakeCache.txt
如果出现下面的提示就表示成功生成了编译环境:
-- Configuring done
-- Generating done
初始化数据库
添加mysql用户
useradd -s /sbin/nologin mysql
新建数据库文件夹及日志文件夹,并更改用户为mysql:
mkdir /mysql_data
mkdir /var/mysql/log
chown -R mysql:mysql /mysql_data/
chown -R mysql:mysql /var/mysql/log
修改配置文件
vim /etc/my.cnf
将[mysqld]项下的内容替换为:
[mysqld]
port=3306
datadir=/mysql_data
log_error=/var/mysql/log/error.log
basedir=/var/mysql/
初始化数据库
/var/mysql/bin/mysqld --initialize --user=mysql
查看数据文件是否生成(进入数据目录 /mysql_data)
查看日志文件是否生成
/var/mysql/log/
配置启动文件及环境变更
1、将启动程序拷贝到系统服务文件脚本中
cp /mysl安装目录/support-files/mysql.server /etc/init.d/mysqld
编辑在服务脚本中mysqld启动配置
vim /etc/init.d/mysqld
找到如下二行:
basedir=
datadir=
改为
basedir= mysql安装目录
datadir= mysql数据目录(/mysql_data)
然后就可以通过
/etc/init.d/mysqld start #启动mysql
或者通过service mysqld start 启动
设置MySQL开机自动启动:
[root@localhost ~]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on
进入mysql
两种方式,软连接方式设置
ln -fs /usr/local/mysql/bin/mysql mysql
或者
vim /root/.bash_profile
找到下面一行:
PATH=$PATH:$HOME/bin
修改为:
PATH=$PATH:$HOME/bin:/var/mysql/bin
第二种方式,进入mysql安装目录下bin目录中输入命令
mysql -u root -p
二、安装php
在php官网下载php压缩包,上传到linux服务器。
解压
/var/mysql/bin/mysqld --initialize --user=mysql
tar -zxvf php-5.6.37.tar.gz
在configure之前需要安装一些环境扩展(安装的系统环境都不一样,最好都执行一遍,装自己需要的模块就行)
yum -y install openssl-devel
yum -y install curl
yum -y install curl-devel
yum -y install libjpeg
yum -y install libjpeg-devel
yum -y install libpng
yum -y install libpng-devel
yum -y install freetype
yum -y install freetype-devel
yum -y install pcre
yum -y install pcre-devel
yum -y install libxslt
yum -y install libxslt-devel
yum -y install bzip2
yum -y install bzip2-devel
配置php扩展
./configure --prefix=/usr/local/php/php-5.6.30 \
--with-apxs2=/work/installed/apache/bin/apxs #这个配置是必须的,源码安装,这里要使得apache能正常识别php
--with-config-file-path=/usr/local/php/etc \
--enable-inline-optimization --disable-debug \
--disable-rpath --enable-shared --enable-opcache \
--enable-fpm --with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl --with-zlib \
--enable-zip \
--with-readline
开始安装
make
make install
php.ini配置
将源码包中的php.ini-development 拷贝到安装目录
具体拷贝到安装目录下的那个目录可以通过以下命令进行查看
php -i | grep php.ini
这样就找出php.ini正确的放置目录了。
三、安装apache
1、先到apache官网下载源码包
http://httpd.apache.org/download.cgi
2、安装httpd软件所需依赖(不安装,扩展配置无法成功,这里我们采用yum安装,方便快捷。)
安装apr http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.34.tar.gz
tar -xzvf apr-1.6.3.tar.gz
cd apr-1.6.3
./configure --prefix=/usr/local/apr
make
make install
安装apr-util http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
解压同上
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install
安装pcrel ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz
cd pcre-8.40#进入解压的软件包目录里面
/*编译安装*/
./configure --prefix=/usr/local/pcre/
make && make install
3、解压安装apache
cd httpd-2.4.25#进入解压的软件包目录里面
/*编译安装*/
./configure --prefix=/usr/local/apache24/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/
make && make install
4、配置apache
更改ServerName 为localhsot:80,之后重启httpd,然后通过ip则可以正常访问
a、遇到的问题解决及办法
httpd: Could not reliably determine the server's fully qualified domain name
用记事本打开 httpd.conf
b、centos编译apr-util-1.6.0出错 缺少expat.h
yum install expat-devel
将里面的 #ServerName localhost:80 注释去掉即可。
再执行 httpd
c、
<code>/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] Error 1
make[2]: Leaving directory `/usr/local/httpd-2.4.26/support'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/httpd-2.4.26/support'
make: *** [all-recursive] Error 1</code>
原来是apr apr-util 用了最新的1.6版本(之前1.6版本在centos7编译安装apache没有问题)
降低了版本,用回1.5版本正常解决。
d、php编译安装时,始终没有生成libphp5.so
原因是apache安装目录下,moudel目录没有写入权限,
解决办法
chmod -r 777 moudels