zoukankan      html  css  js  c++  java
  • centos6.3编译安装Apache2.4.3+PHP5.4.8+Mysql5.5.8

    http://www.myxzy.com/post-348.html 原文地址

    http://sudhir-web.blogspot.com/2012/07/how-to-install-nginx-with-php-and-mysql.html 编译错误

    以虚拟机VirtualBox 版本是4.1.20(内存设置为512M,centos安装是文本模式下安装),全新以最小化包安装了32位的CentOS6.3系统,作为本地web环境,上次讲了在windows下安装Apache2.4.3+PHP5.4.8+Mysql5.5.8,这次就说说linux(centos)下编译安装的过程(全命令模式下完成)。

    以下分为几部分来说:

    第一部分:准备工作。

    1.全新centos6.3(以下简称centos)最基本的设置略过(比如用户、网络设置等等)。

    2.这里可以联网了。这里用到的我不写到一起了。

    安装wget工具。

    [root@localhost ~]# yum -y install wget

    安装GCC软件套件

    [root@localhost ~]# yum -y install gcc

    [root@localhost ~]# yum -y install gcc-c++

    安装make

    [root@localhost ~]# yum -y install make

    安装vim

    [root@localhost ~]# yum -y install vim

    3.下载各个安装包:基本上多是官网提供的源。

    [root@localhost ~]# wget http://apache.etoak.com/httpd/httpd-2.4.3.tar.gz

    [root@localhost ~]# wget http://apache.etoak.com/apr/apr-1.4.6.tar.gz

    [root@localhost ~]# wget http://apache.etoak.com/apr/apr-util-1.5.1.tar.gz

    [root@localhost ~]# wget http://hk1.php.net/distributions/php-5.4.8.tar.gz

    [root@localhost ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz

    [root@localhost ~]# wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

    (注意大小写,不然会报404错误的。)

    [root@localhost ~]#ls

    查看下有没有全部下好,如图片中红色的就是刚刚下载的。

    点击查看原图

    4.以上源码包全部用tar zxvf xxx.tar.gz解压缩

    [root@localhost ~]# tar zxvf httpd-2.4.3.tar.gz

    [root@localhost ~]# tar zxvf apr-1.4.6.tar.gz

    [root@localhost ~]# tar zxvf apr-util-1.5.1.tar.gz

    [root@localhost ~]# tar zxvf php-5.4.8.tar.gz

    [root@localhost ~]# tar zxvf pcre-8.31.tar.gz

    [root@localhost ~]# tar zxvf libmcrypt-2.5.8.tar.gz

    [root@localhost ~]#ls

    查看如图中蓝色的就是解压好文件夹。

    点击查看原图

    第二部分:安装Apache。

    1.安装apache依赖包pcre

    [root@localhost ~]# cd ./pcre-8.31

    [root@localhost ~]# ./configure --prefix=/usr/local/pcre

    [root@localhost ~]# make && make install

    2.安装openssl

    [root@localhost ~]# yum -y install openssl-devel

    3.移动apr和apr-util到httpd-2.4.3文件夹下srclib内并且重命名

    [root@localhost ~]# mv apr-1.4.6 /httpd-2.4.3/srclib/apr

    [root@localhost ~]# mv apr-util-1.5.1 /httpd-2.4.3/srclib/apr-util

    4.安装Apache 2.4.3主程序

    [root@localhost ~]# cd ./httpd-2.4.3

    [root@localhost ~]# ./configure --prefix=/usr/local/apache --enable-so --enable-deflate=shared --enable-ssl=shared --enable-expires=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support --with-included-apr --with-mpm=prefork --enable-cache --enable-file-cache --with-pcre=/usr/local/pcre

    [root@localhost ~]# make && make install

    5.基本配置让apache自启动。

    修改httpd.conf,wq保存退出

    [root@localhost ~]# vim /usr/local/apache/conf/httpd.conf

    找到“#ServerName www.example.com:80”,在下面加上这一行

    ServerName localhost:80

    注意:没有没有修改直接执行自启动修改,会出现错误提示:“AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using centos.huoba. Set the 'ServerName' directive globally to suppress this message”

    加入配置文件实现自启动

    [root@localhost ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

    [root@localhost ~]# vim /etc/init.d/httpd

    在#!/bin/sh 下面加上这两行,wq保存退出

    # chkconfig: 345 90 90

    # description: Apache

    [root@localhost ~]# chkconfig --add /etc/init.d/httpd

    [root@localhost ~]# service httpd start

    暂时关闭防火墙测试。

    [root@localhost ~]# /etc/init.d/iptables status                ##查看防火墙状态

    [root@localhost ~]# /etc/init.d/iptable stop                   ##本次关闭防火墙

    [root@localhost ~]# /etc/init.d/iptable restart                ##重启防火墙

    [root@localhost ~]#chkconfig --level 35 iptables off        ##永久关闭防火墙

    由于我用的是虚拟机,关闭防火墙后访问测试。浏览输入ip地址,出现“It works”就说明Apache已经正常安装。

    点击查看原图

    防火墙设置:

    如果是虚拟机的话,用来作为本地环境的,还是永久关闭防火墙比较简单。

    当然你也可以对防火墙进行设置。

    添加端口80,443以及ssh端口22,你也可以添加ftp端口21等等

    [root@localhost ~]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

    [root@localhost ~]# /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT

    [root@localhost ~]# /sbin/iptables -I INPUT -p tcp --dport 443 -j ACCEPT

    [root@localhost ~]# /etc/init.d/iptables save               ##保存配置

    [root@localhost ~]# /etc/init.d/iptable restart             ##重启防火墙 

    到此。Apache的设置基本完成。


    第三部分:安装MySQL

    1.下载mysql,上面的时候忘记下了

    [root@localhost ~]# wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28.tar.gz

    解压mysql-5.5.28.tar.gz

    [root@localhost ~]#  tar zxvf mysql-5.5.28.tar.gz

    2.安装cmake

    [root@localhost ~]# yum -y install cmake make

    安装一些其他

    [root@localhost ~]# yum  -y install  autoconf bison automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*

    3.安装mysql 5.5.28主程序

    [root@localhost ~]# cd mysql-5.5.28

    [root@localhost ~]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFIGDIR=/usr/local/mysql/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1

    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql

    [root@localhost ~]# make && make install

    官方说明:

    The MyISAM, MERGE, MEMORY, and CSV engines are mandatory (always compiled into the server) and need not be installed explicitly.(说明:mysql默认支持的数据库引擎有MyISAM, MERGE, MEMORY, CSV,无需在编译时再声明)

    所以上面的编译条件省掉了如下两行

    -DWITH_MYISAM_STORAGE_ENGINE=1 

    -DWITH_MEMORY_STORAGE_ENGINE=1

    但INNODB一定要声明式安装,所以多了这一行

    -DWITH_INNOBASE_STORAGE_ENGINE=1 

    4.配置mysql 5.5.28

    [root@localhost ~]# cp /usr/loacl/mysql/support-files/my-huge.cnf etc/my.cnf

    [root@localhost ~]# vi /etc/my.cnf

    修改my.cnf配置,把innodb相关选项前面的#去掉,大概在115-130行之间。

    以下命令为mysql 启动及自启动配置

    [root@localhost ~]# cp /usr/loacl/mysql/support-files/mysql.server /etc/init.d/mysqld

    [root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &

    chkconfig --add mysqld

    chkconfig --level 345 mysqld on

    [root@localhost ~]# service mysqld start 

    一般只要把my.cnf设置好这里就不会报错。如果有错请留言评论,我会试着帮你解决

    剩下就是mysql的设置了。

    [root@localhost ~]# /usr/local/server/mysql/bin/mysql -u root -p -S /tmp/mysql.sock

    弹出输入password的提示,直接回车。

    设置密码:

    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');

    mysql> quit

    删除root密码为空的记录

    mysql> use mysql;

    mysql> delete from user where password='';

    mysql> flush privileges;

    配置mysql允许root远程登录                                 

    mysql> grant all privileges on *.* to root@'%' identified by "123456";

    mysql> flush privileges;

    mysql> quit

    主机可以通过软件来远程访问centos的mysql数据库了。

    点击查看原图

    到此mysql安装和设置基本完成。


    第四部分:安装PHP 5.4.8

    1.查看apache版本

    [root@localhost ~]# /usr/local/apache/bin/httpd -v

    查看apache已编译安装的模块

    [root@localhost ~]# /usr/local/apache/bin/httpd -M

    2.安装相关资源及依赖包

    [root@localhost ~]# yum -y install bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel

    3.安装php 5.4.8程序

    [root@localhost ~]# vim /usr/local/apache/bin/apxs

    编辑apxs,把#!/replace/with/path/to/perl/interpreter -w 这一行(一般是第一行)更改为"#!/usr/bin/perl -w"。

    注意:如果没有改,编译的时候会出现了“Sorry, I cannot run apxs”的错误提示。因为没有指明正确的perl执行程序的位置。

    [root@localhost ~]# cd php-5.4.8

    [root@localhost ~]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/include/libxml2 --with-config-file-path=/usr/local/apache/conf --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd --enable-gd-native-ttf --with-zlib --with-mcrypt --with-pdo-mysql=/usr/local/mysql --enable-shmop --enable-soap --enable-sockets --enable-wddx --enable-zip --with-xmlrpc --enable-fpm --enable-mbstring --with-zlib-dir --with-bz2 --with-curl --enable-exif --enable-ftp --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-freetype-dir=/usr/lib/

    [root@localhost ~]# make && make install

    php配置,编译安装时我的php.ini文件目录指向/usr/local/apache/conf

    [root@localhost ~]# cd php-5.4.8

    [root@localhost ~]# cp php.ini-production /usr/local/apache/conf/php.ini

    4.apache配置文件httpd.conf相关修改以支持PHP

    [root@localhost ~]# vim /usr/local/apache/conf/httpd.conf

    1. 添加php支持。

    AddType application/x-httpd-php .php .phtml

    AddType application/x-httpd-php-source .phps

    2. 添加默认索引页面index.php,再找到“DirectoryIndex”,在index.html后面加上“ index.php”

    DirectoryIndex index.html index.php

    3. 不显示目录结构,找到“Options Indexes FollowSymLinks”,修改为

    Options FollowSymLinks

    4. 开启Apache支持伪静态,找到“AllowOverride None”,修改为

    AllowOverride All

    保存httpd.conf配置,然后再执行以下两行命令

    [root@localhost ~]# chown -R nobody. /usr/local/apache/htdocs/

    [root@localhost ~]# chmod -R 777 /usr/local/apache/htdocs/

    [root@localhost ~]# service httpd restart

    注意:重启有可能libphp5.so报错,这个有多种情况,这里就不一一说明了。你可以把错误提示贴出来求解决方法。

    我在htdocs新建了一个index.php,

    <?php phpinfo();?>

    运行了下,部分截图如下:

    点击查看原图

    点击查看原图

    点击查看原图

    到了这里php的基本安装已经完成了。


    总之,在编译安装的时候,等的时间最久。安装这3个软件中报错n多,大部分是由于没有相关资源或者没有依赖包出现的报错。

    这里碰到的错误就不一一说明了。本来我还想全部用离线资源包来本地编译安装,发现要安装的东西太多了,所以也就一部分相关资源和依赖包用了在线源更新安装。

    最后不得不说一句:不用源更新安装,不用一键安装包就是找罪受。

    最后再附上emlog5.0安装好之后的展示图,忙了这么久装个程序试试:

    点击查看原图

    点击查看原图

  • 相关阅读:
    bzoj3007: 拯救小云公主
    bzoj4316: 小C的独立集
    PostgreSQL Replication之第三章 理解即时恢复(3)
    PostgreSQL Replication之第三章 理解即时恢复(2)
    PostgreSQL Replication之第三章 理解即时恢复(1)
    PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(5)
    PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(4)
    PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(3)
    PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(2)
    PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(1)
  • 原文地址:https://www.cnblogs.com/google4y/p/2946447.html
Copyright © 2011-2022 走看看