centos7源码装apache,mysql,php及各种问题的解决办法

一、准备(把所有的源文件放在‘/root/’目录下)
apr http://mirror.bjtu.edu.cn/apache/apr/apr-1.5.2.tar.gz
apr-util http://mirror.bjtu.edu.cn/apache/apr/apr-util-1.5.4.tar.gz
pcre ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.zip
httpd http://mirror.bjtu.edu.cn/apache/httpd/httpd-2.4.20.tar.gz
php http://cn2.php.net/get/php-5.6.27.tar.gz/from/this/mirror
mysql http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.21.tar.gz/from/http://mysql.spd.co.il/
我更喜欢下载mysql-5.6版本的,可到一下地址下载或者自己去官网下载
http://download.csdn.net/download/sunny_sailor/8072429
# yum install gcc gcc-c++ glibc glibc-devel gd gd-devel zlib zlib-devel libtool-ltdl-devel flex autoconf automake

二、安装
2.1 安装 apache

2.1.1安装 apr
# cd /root/
# tar zxf apr-1.5.2.tar.gz
# cd apr-1.5.2/
# ./configure –prefix=/usr/local/apr
# make
# make install

编译APR包的时候可能出现 rm: cannot remove `libtoolT’: No such file or directory
网上查阅了一下资料,提示编辑configure这个文件,将 RM cfgfile” 那行注释掉 ,然后重新编译即可。
原文出自http://blog.csdn.net/c1520006273/article/details/50491595

2.1.2安装 apr-util
# cd /root/
# tar zxf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4/
# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
# make
# make install

2.1.3安装 pcre
# cd /root/
# unzip pcre-8.39.zip
# cd pcre-8.39/
# ./configure –prefix=/usr/local/pcre
# make
# make install

2.1.4安装 apache
# cd /root/
# tar zxf httpd-2.4.20.tar.gz
# cd httpd-2.4.20/
# ./configure –prefix=/usr/local/apache2 –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –with-pcre=/usr/local/pcre –enable-so –enable-rewrite
# make
# make install

2.1.5将apache安装为系统服务

# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

然后 vi /etc/rc.d/init.d/httpd 添加(# !/bin/sh下面)

# chkconfig: 2345 50 90

# description: Activates/Deactivates Apache Web Server
保存退出

最后,运行chkconfig把Apache添加到系统的启动服务组里面:

# chkconfig –add httpd

# chkconfig httpd on
然后再service httpd start

2.1.6打开iptables 这个是设置防火墙centos7用另一种方法
请到http://www.cnblogs.com/phpshen/p/5842118.html
http://linux.it.net.cn/CentOS/fast/2014/1102/7635.html
这两篇是有关防火墙的

# iptables -F
# iptables -P INPUT ACCEPT

2.2 安装 mysql

2.2.1安装 cmake
# cd /root/
# wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz
# tar zxf cmake-3.6.2.tar.gz
# cd cmake-3.6.2
# yum install gcc
# yum install gcc-c++
# ./configure
# make
# make install
# ln -s /usr/local/bin/cmake /usr/bin/cmake

2.2.2安装mysql
# groupadd mysql
# useradd -r -g mysql mysql
# cd /root/
# tar zxf mysql-5.5.21.tar.gz
# cd mysql-5.5.21
# yum -y install ncurses-devel
# yum install bison
# cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=dir
如果出现错误:
# rm CMakeCache.txt
# cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=dir

# make
#make install
# cd /usr/local/mysql/
# chown -R mysql .
# chgrp -R mysql .
# scripts/mysql_install_db –user=mysql
# bin/mysqld –initialize-insecure –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data
更改本目录的主用户(设为root是为了防止普通用户不小心删除数据库)
# chown -R root .
更改数据存放目录的主用户
# chown -R mysql data
复制my.cnf
# cp support-files/my-default.cnf /etc/my.cnf
这部是mysql后台启动,但是我在做的时候会出错,然后我跳过这步也可以
# bin/mysqld_safe –user=mysql &
复制服务启动脚本
#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
编辑PATH搜索路径
vi /etc/profile
在profile文件末尾增加两行
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH

使PATH搜索路径立即生效:
#source /etc/profile
启动MySQL服务
#service mysqld start
如果报错,可以service mysqld restart
给root设置密码
# bin/mysqladmin -u root password “root”
#chkconfig mysql on
# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
# chmod +x /etc/init.d/mysqld
# service mysqld restart
测试一下:
# mysql -u root -p
然后输入密码,如果能够进入就说明安装好了

把mysql安装为系统启动项
# vi /etc/rc.d/init.d/mysqld 添加(# !/bin/sh下面)
# chkconfig: 2345 51 89
# description: Activates/Deactivates MySQL Server
保存退出
# chkconfig –add mysqld
# chkconfig mysqld on
# service mysqld restart

2.3 安装 php
2.3.1 安装libxml2
#yum install libxml2
#yum install libxml2-devel -y

2.3.2 安装php

#cd /home/yuanjun

#tar zxf php-5.6.27.tar.gz

#cd php-5.4.8
#./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql
如果安装php7 需要将 –with-mysql 改成 –with-pdo-mysql 注意php7是纯面向对象不支持面向过程

如果需要支持mb_cubstr()这个函数
需要在./configure是增加–enable-mbstring,也就是
#./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql –enable-mbstring
原文在
http://php.net/manual/en/mbstring.installation.php

如果服务器内存较小会出现
virtual memory exhausted: Cannot
allocate memory make: * [ext/fileinfo/libmagic/apprentice.lo] Error 1
解决方法
在./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql时添加
–disable-fileinfo
也就是
./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql –disable-fileinfo

原文在
https://bugs.php.net/bug.php?id=48809

# make
# make install
# cp php.ini-development /usr/local/php/lib/php.ini
# vi /usr/local/apache2/conf/httpd.conf
确保以下字符串是否存在
LoadModule php5_module modules/libphp5.so
如果没有就加上
在AddType application*后面加如下一行
AddType application/x-httpd-php .php .phtml
在DirectoryIndex index.html加上index.php
DirectoryIndex index.php index.html
#service httpd restart
若有error发生
# setenforce 0
# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so
# service httpd restart

2.3.3 测试php
# vi /usr/local/apache2/htdocs/index.php
加入“

以下是我在安装过程中用到的所有文章

安装过程
http://www.linuxidc.com/Linux/2013-03/81506.htm
http://www.cnblogs.com/dongjc/p/5225761.html

make: * No targets specified and no makefile found. Stop.解决方法
http://blog.csdn.net/l1028386804/article/details/48710993

mysql5.6.14下载,其他版本不好装
http://download.csdn.net/download/sunny_sailor/8072429

linux apache web站点配置详解
http://blog.csdn.net/white__cat/article/details/32733005

Linux下安装mysql后,添加服务的问题
http://blog.chinaunix.net/uid-28597757-id-3503976.html

安装php7时要用–with-pdo-mysql

apr configure不正常执行问题
http://blog.csdn.net/c1520006273/article/details/50491595

configure介绍
http://www.chinaz.com/server/2009/0807/85792.shtml

解决virtual memory exhausted: Cannot allocate memory make: * [ext/fileinfo/libmagic/apprentice.lo] Error 1
https://bugs.php.net/bug.php?id=48809

关于防火墙
http://www.cnblogs.com/phpshen/p/5842118.html
http://linux.it.net.cn/CentOS/fast/2014/1102/7635.html

解决mb_cubstr不能用问题
http://php.net/manual/en/mbstring.installation.php

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值