技术交流QQ群:①185473046   ②190706903   ③203744115   网站地图
登录

下次自动登录
现在的位置: 首页LAMP>正文
CentOS 6.2编译安装Apache2.4.1+MySQL5.5.21+PHP5.3.10
2012年02月25日 LAMP 评论数 31 ⁄ 被围观 33,405次+


说明:

   操作系统:CentOS 6.2 32位
   系统安装教程:CentOS 6.2安装(超级详细图解教程)
   http://www.osyunwei.com/archives/1537.html
准备篇:
一、配置好IP、DNS 、网关,确保使用远程连接工具能够连接服务器
       CentOS 设置IP地址、网关、DNS教程:http://www.osyunwei.com/archives/423.html
二、配置防火墙,开启80端口、3306端口

vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT(允许80端口通过防火墙)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT(允许3306端口通过防火墙)
特别提示:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面
添加好之后防火墙规则如下所示:
系统运维 www.osyunwei.com 温馨提醒:qihang01原创内容版权所有,转载请注明出处及原文链接
#########################################################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
#########################################################
/etc/init.d/iptables restart  #最后重启防火墙使配置生效
三、关闭SELINUX
vi /etc/selinux/config
#SELINUX=enforcing       #注释掉
#SELINUXTYPE=targeted    #注释掉
SELINUX=disabled         #增加
:wq  保存,关闭
shutdown -r now   #重启系统
四 、系统约定
软件源代码包存放位置:/usr/local/src
源码包编译安装位置:/usr/local/软件名字
五、下载软件包
1、下载apache
http://www.apache.org/dist/httpd/httpd-2.4.1.tar.gz
2、下载MySQL
http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.5/mysql-5.5.21.tar.gz
3、下载php
http://cn.php.net/distributions/php-5.3.10.tar.gz
4、下载cmake(MySQL编译工具)
http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz
5、下载libmcrypt(PHPlibmcrypt模块)
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
6、下载apr(Apache库文件)
http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gz
7、下载apr-util(Apache库文件)
http://mirror.bit.edu.cn/apache/apr/apr-util-1.4.1.tar.gz
用WinSCP远程连接到服务器,把下载好的软件上传到服务器/usr/local/src下面
六、安装编译工具及库文件(使用CentOS yum命令安装)
系统运维 www.osyunwei.com 温馨提醒:qihang01原创内容版权所有,转载请注明出处及原文链接
yum install make apr* autoconf automake gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd  kernel keyutils  patch  perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch
安装篇
以下是用putty工具远程登录到服务器,在命令行下面操作的
1、安装libmcrypt
cd /usr/local/src
tar zxvf  libmcrypt-2.5.7.tar.gz   #解压
cd  libmcrypt-2.5.7 #进入目录
./configure    #配置
make           #编译
make install   #安装
2、安装cmake 
cd /usr/local/src
tar zxvf cmake-2.8.7.tar.gz
cd cmake-2.8.7
./configure
make           #编译
make install   #安装
3、安装apr
cd /usr/local/src
tar zxvf  apr-1.4.6.tar.gz
cd apr-1.4.6
./configure --prefix=/usr/local/apr
make
make install
4、安装apr-util
cd /usr/local/src
tar zxvf apr-util-1.4.1.tar.gz
cd apr-util-1.4.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make
make install
5、安装mysql
groupadd mysql  #添加mysql组
useradd -g mysql mysql -s /bin/false  #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
mkdir -p /data/mysql  #创建MySQL数据库存放目录
chown -R mysql:mysql /data/mysql   #设置MySQL数据库目录权限
mkdir -p /usr/local/mysql #创建MySQL安装目录
cd /usr/local/src
tar zxvf mysql-5.5.21.tar.gz  #解压
cd mysql-5.5.21
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DMYSQL_DATADIR=/data/mysql  -DSYSCONFDIR=/etc   #配置
make #编译
make install  #安装
cd /usr/local/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf   #拷贝配置文件(注意:/etc目录下面默认有一个my.cnf,直接覆盖即可)
vi /etc/my.cnf   #编辑配置文件,在 [mysqld] 部分增加下面一行
datadir = /data/mysql  #添加MySQL数据库路径
:wq!   #保存退出

./scripts/mysql_install_db --user=mysql  #生成mysql系统数据库
cp ./support-files/mysql.server  /etc/rc.d/init.d/mysqld  #把Mysql加入系统启动
chmod 755 /etc/init.d/mysqld   #增加执行权限
chkconfig mysqld on  #加入开机启动
vi /etc/rc.d/init.d/mysqld  #编辑
basedir = /usr/local/mysql   #MySQL程序安装路径
datadir = /data/mysql  #MySQl数据库存放目录
service mysqld start  #启动
vi /etc/profile   #把mysql服务加入系统环境变量:在最后添加下面这一行
export PATH=$PATH:/usr/local/mysql/bin
下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
shutdown -r now     #需要重启系统,等待系统重新启动之后继续在终端命令行下面操作
mysql_secure_installation    #设置Mysql密码
根据提示按Y 回车输入2次密码
或者直接修改密码/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #修改密码
service mysqld restart  #重启
到此,mysql安装完成!
6、安装apache2
cd /usr/local/src
tar -zvxf httpd-2.4.1.tar.gz
cd  httpd-2.4.1
mkdir -p /usr/local/apache2  #创建安装目录
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-ssl --enable-ssl --enable-module=so --enable-rewrite --enable-cgid --enable-cgi    #配置
make    #编译
make install  #安装
/usr/local/apache2/bin/apachectl -k start  #启动
vi /usr/local/apache2/conf/httpd.conf   #编辑配置文件
找到:#ServerName www.example.com:80
修改为:ServerName www.osyunwei.com:80
找到:DirectoryIndex index.html
修改为:DirectoryIndex index.html index.php
找到:Options Indexes FollowSymLinks
修改为:Options FollowSymLinks    #不显示目录结构
找到AllowOverride None 
修改为:AllowOverride All   #开启apache支持伪静态,有三处都做修改
LoadModule rewrite_module modules/mod_rewrite.so   #取消前面的注释,开启apache支持伪静态
vi /etc/profile  #添加apache服务系统环境变量
在最后添加下面这一行
export PATH=$PATH:/usr/local/apache2/bin
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd      #把apache加入到系统启动
vi /etc/init.d/httpd   #编辑文件
在#!/bin/sh下面添加以下两行
#chkconfig:2345 10 90
#description:Activates/Deactivates Apache Web Server
chown  daemon.daemon  -R /usr/local/apache2/htdocs  #更改目录所有者
chmod   700 /usr/local/apache2/htdocs  -R #更改apache网站目录权限
chkconfig httpd on    #设置开机启动
/etc/init.d/httpd start
service httpd restart
7、安装php
cd /usr/local/src
tar -zvxf php-5.3.10.tar.gz
cd  php-5.3.10
mkdir -p /usr/local/php5  #建立php安装目录
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-apxs2=/usr/local/apache2/bin/apxs  --with-mysql=/usr/local/mysql  --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd  --with-iconv --with-freetype --with-jpeg --with-png --with-zlib --with-libxml --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable-suhosin --enable-session --with-mcrypt            #配置
make   #编译
make install    #安装
mkdir /usr/local/php5/etc
cp php.ini-production  /usr/local/php5/etc/php.ini  #复制php配置文件到安装目录
rm -rf /etc/php.ini   #删除系统自带的配置文件
ln -s  /usr/local/php5/etc/php.ini   /etc/php.ini   #创建配置文件软链接
vi /usr/local/php5/etc/php.ini    #编辑
找到:;open_basedir =
修改为:open_basedir = .:/tmp/   #防止php木马跨站,重要!!
找到:disable_functions =
修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
找到:;date.timezone =
修改为:date.timezone = PRC
找到:expose_php = On
修改为:expose_php = OFF  #禁止显示php版本的信息
找到:display_errors = On
修改为:display_errors = OFF  #关闭错误提示
系统运维 www.osyunwei.com 温馨提醒:qihang01原创内容版权所有,转载请注明出处及原文链接
8、配置apache支持php
vi /usr/local/apache2/conf/httpd.conf  #编辑apache配置文件
AddType application/x-gzip .gz .tgz这一行下面添加、
AddType application/x-httpd-php .php 注意:php .php这个点前面有一个空格
service httpd restart    #重启apache
service mysqld restart   #重启mysql
测试篇
cd  /usr/local/apache2/htdocs
vi index.php   #输入下面内容
<?php

phpinfo();
?>
:wq!   #保存
在客户端浏览器输入服务器IP地址,可以看到相关的配置信息!
网站程序上传到/usr/local/apache2/htdocs目录里面,如果安装有问题,请检查目录权限
确保目录为以下权限
chown daemon.daemon -R /usr/local/apache2/htdocs
chmod -R 700 /usr/local/apache2/htdocs
至此,CentOS 6.2编译安装Apache2.4.1+MySQL5.5.21+PHP5.3.10配置完成。

     

  系统运维技术交流QQ群:①185473046 系统运维技术交流□Ⅰ ②190706903 系统运维技术交流™Ⅱ ③203744115 系统运维技术交流™Ⅲ

目前有 31 条留言 其中:访客:31 条, 博主:0 条

  1. card : 2012年03月02日10:57:15  1楼

    在安装Mysql时最后一步报个错!

    In order to log into MySQL to secure it, we’ll need the current
    password for the root user. If you’ve just installed MySQL, and
    you haven’t set the root password yet, the password will be blank,
    so you should just press enter here.

    Enter current password for root (enter for none):
    ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: YES)
    Enter current password for root (enter for none):
    ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: YES)
    Enter current password for root (enter for none):

  2. 燕飞时节 : 2012年03月09日16:57:26  2楼

    博主写错了一个单词:

    在#!/bin/sh下面添加以下两行
    #chkconfig:2345 10 90
    #descrption:Activates/Deactivates Apache Web Server

    这里,descrption应该为description,否则就会在执行

    chkconfig httpd on #设置开机启动

    命令的时候报错:

    service httpd does not support chkconfig

  3. qihang01 : 2012年03月11日21:16:15  3楼

    已经更改,非常感谢!

  4. 燕飞时节 : 2012年03月13日18:17:20  4楼

    博主,/usr/local/apache2/conf/httpd.conf 中的AllowOverride None其实是有三处的,不是两处,所以,三处都要更改吗?
    以下省略,带着就无法显示了,位置当然在开头和结尾

    1. Directory /
    AllowOverride none
    Require all denied
    /Directory

    2. Directory “/usr/local/apache2/htdocs”
    #
    # Possible values for the Options directive are “None”, “All”,
    # or any combination of:
    # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that “MultiViews” must be named *explicitly* — “Options All”
    # doesn’t give it to you.
    #
    # The Options directive is both complicated and important. Please see
    # http://httpd.apache.org/docs/trunk/mod/core.html#options
    # for more information.
    #
    Options FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be “All”, “None”, or any combination of the keywords:
    # Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
    /Directory

    3. Directory “/usr/local/apache2/cgi-bin”
    AllowOverride None
    Options None
    Require all granted
    /Directory

    • qihang01 : 2012年03月13日21:12:29

      只需要修改第一处的AllowOverride None 即可,当然也可以三处都做修改,第一个设置是全局生效,后面两个设置是针对某一个目录的。

      • 燕飞时节 : 2012年03月14日08:51:17

        谢谢博主,学习了

      • 绝缘体 : 2012年03月21日13:48:47

        博主,我按照你上面的命令把httpd加入到系统自启动,结果发现不能完成此目的,每次开机并不是自己启动的,想请教一下该如何修改。
        输入如下命令皆没有任何显示:
        [root@webserver ~]# service httpd start 这个我查过,确认已启动,但不显示结果。
        [root@webserver ~]# service httpd restart 这个我不能确认是否已经重新启动该任务。
        [root@webserver ~]# service httpd status 查看这个服务的状态,结果显示如下
        Not Found

        The requested URL /server-status was not found on this server.
        [root@webserver ~]#

  5. 绝缘体 : 2012年03月20日12:49:54  5楼

    我按照你上面所说安装mysql时,输入
    cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
    结果系统提示
    [root@susan mysql-5.5.21]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
    -bash: cmake: command not found
    [root@susan mysql-5.5.21]#
    这是为什么呢?

    • 绝缘体 : 2012年03月20日14:38:27

      问题已经解决,因为我没有安装cmake软件。

    • qihang01 : 2012年03月21日19:31:18

      cmake: command not found
      找不到cmake软件包
      看教程,从头至尾通读。。。
      教程里面软件的安装顺序等都有是联系的!

  6. 绝缘体 : 2012年03月20日14:39:23  6楼

    又发现新问题,安装APACHE时操作到查看服务运行情况的时候系统显示:
    /etc/init.d/httpd: line 97: lynx: command not found
    这是怎么回事呢?

  7. wsk : 2012年03月21日16:01:16  7楼

    为什么我在安装APACHE到时候 提示这个错误呢
    checking for APR-util… configure: error: the –with-apr-util parameter is incorrect. It must specify an install prefix, a build directory, or an apu-config file.
    apr-util是安装成功了的

    • qihang01 : 2012年03月21日19:22:18

      有可能是Apr、Apr-util与Apache版本问题,照着教程里面的版本,是可以安装成功的!

      • 我就喜欢 : 2012年04月05日16:10:20

        我同样遇到楼主的情况,版本我是按足你教程上面的链接下载的。

        • 我就喜欢 : 2012年04月05日16:16:53

          终于知道什么问题了,可能楼主跟我一样都是懒人,直接复制博主文章的shell命令粘贴到ssh进行编译,可是博主安装apr-util shell之前是没有之前进入/usr/local/src目录的,所以解压命令和安装命令都没有成功运行。根本就没有安装apr-util。

          • qihang01 : 2012年04月05日22:50:36

            编译每一个软件之前,要先进入到软件包的存放目录:cd /usr/local/src

  8. dndn : 2012年04月06日21:45:57  8楼

    在service mysqld start #启动 这步之后,提示
    /etc/init.d/mysqld:line 46: basedir: command not found
    /etc/init.d/mysqld:line 47: datadir: command not found
    怎么解决???

  9. dndn : 2012年04月08日03:36:14  9楼

    还有一个小问题,都安装运行后,发现phpinfo里的GD里没有freetype,网页中无法显示验证码,图片不显示???????

  10. aixiaom : 2012年05月05日15:43:35  10楼

    您好!请问
    make #编译 mysql 时候出现问题:
    make: *** 没有指明目标并且找不到 makefile。 停止。

    是什么原因呢?

  11. Kevin : 2012年06月28日09:12:46  11楼

    我问下博主,为什么要执行下面的命令呢?不执行会怎样?谢谢!

    chown daemon.daemon -R /usr/local/apache2/htdocs #更改目录所有者

    • qihang01 : 2012年06月29日21:33:12

      apache的运行账号是daemon,所以要把网站目录权限的所有者设置为daemon,否则打开站点提示权限错误

  12. 1085757260@qq.com : 2012年09月26日17:43:17  12楼

    博主,请教一下,我安装的是apache2.4.3+php5.4.7+mysql5.5.27 编译安装都是成功的
    可是apache不能识别php文件

  13. 493148735@qq.com : 2012年11月21日02:08:45  13楼

    博主 我在执行
    cmake . -DCMAKE_INSTALL_PREFIX=/USR/LOCAL/MYSQL -DMYSQL_DATADIR=/DATA/MYSQL -DSYSCONFDIR=/etc 时出现

    MySQL 5.5.21
    – Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
    CMake Error at cmake/readline.cmake:83 (MESSAGE):
    Curses library not found. Please install appropriate package,

    remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
    Call Stack (most recent call first):
    cmake/readline.cmake:127 (FIND_CURSES)
    cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)
    CMakeLists.txt:268 (MYSQL_CHECK_READLINE)

    – Configuring incomplete, errors occurred!

    这个错误 请问这是什么原因啊 cmake装了两次还是有这样的提示

  14. 411152544 : 2013年03月25日22:00:30  14楼

    cmake.-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
    bash: cmake.-DCMAKE_INSTALL_PREFIX=/usr/local/mysql: 没有那个文件或目录
    请教一下博主,我的/usr/local/mysql 已经创建好了,不能进行编译是那个文件夹不对吗?

  15. 120455637@qq.com : 2013年07月23日11:47:02  15楼

    好文,正好用上~~~

  16. 469884736@qq.com : 2014年02月13日16:27:17  16楼

    非常好,谢谢啦 :razz:

  17. scott : 2014年05月12日22:37:00  17楼

    正好学习下。

给我留言

您必须 [ 登录 ] 才能发表留言!



Copyright© 2011-2024 系统运维 All rights reserved
版权声明:本站所有文章均为作者原创内容,如需转载,请注明出处及原文链接
陕ICP备11001040号-3