您的位置:首页 > 运维架构 > Apache

RHEL6.3_x86_64 下源码安装Apache(2.2.5)MySQL(5.5.25a) PHP(5.2.17)

2013-08-02 14:53 477 查看
一、 系统环境

系统平台:Red Hat Enterprise Linux Server release 6.3(Santiago)
Apache版本:httpd-2.2.5.tar.gz
Mysql版本:mysql-5.5.25a.tar.gz
Php版本:php-5.2.17.tar.gz

二、Apache安装

1)
安装apr: apr-1.4.6.tar.bz2


#tar –jxvf apr-1.4.6.tar.bz2

#cd apr- apr-1.4.6

#./configure –prefix=/usr/local/apr

#make

#make install

2) 安装apr-util: apr-util-1.3.12.tar.gz

#tar –zxvf apr-util-1.3.12.tar.gz

#cd apr-util-1.3.12

#./configure –prefix=/usr/local/apr-util

#make

#make install

3)
安装 pcre: pcre-8.10.zip


#unzip pcre-8.10.zip

#cd pcre-8.10

#./configure –prefix=/usr/local/pcre

#make

#make install

4)
卸载Apache


# rpm -qa | grep httpd

说明:检查是否安装了httpd软件包

# rpm –e httpd-2.2.3-63.el5.centos --nodeps

说明:卸载软件包,--nodeps如果有连带关系,也强制卸载

# cd /etc/httpd/

# rm -rf *

说明:到原来的apache安装目录下,将其所有的安装目录和文件都删掉

5) 关闭selinux,清空防火墙规则

vim
/etc/selinux/config

查找SELINUX,将SELINUX=disabled

6)
安装Apache


# tar -zxvf httpd-2.2.25.tar.gz

# cd httpd-2.2.25

# ./configure \

--prefix=/usr/local/apache2 \

--sysconfdir=/etc/httpd \

--with-z=/usr/local/zlib \

--with-apr=/usr/local/apr \

--with-apr-util=/usr/local/apr-util \

--with-pcre=/usr/local/pcre \

--enable-so \

--enable-deflate=shared \

--enable-expires=shared \

--enable-rewrite=shared \

--enable-static-support

# make && make install

7)
配置Apache


启动Apache

# /usr/local/apache2/bin/apachectl start

关闭Apache

# /usr/local/apache2/bin/apachectl stop

查看80端口是否开启

# netstat -tnl|grep 80

访问Apache服务器



添加自启动

# echo "/usr/local/apache2/bin/apachectl start" >>/etc/rc.d/rc.local

三、安装MySQL

1)相关依赖包:

ncurses-5.9.tar.gz

bison-2.5.tar.gz

2)安装依赖包

(1)ncurses

[root@test ~]# cd /data1/lnmp/

[root@test lnmp]# tar -xzf ncurses-5.9.tar.gz

[root@test lnmp]# cd ncurses-5.9

[root@test ncurses-5.9]# ./configure

[root@test ncurses-5.9]# make && make install

(2)bison

[root@test lnmp]# tar -xzf bison-2.5.tar.gz

[root@test lnmp]# cd bison-2.5

[root@test bison-2.5]# ./configure

[root@test bison-2.5]# make && make install

3)安装用于编译 MySQL的 cmake
工具


[root@test lnmp]# tar -xzf cmake-2.8.8.tar.gz

[root@test lnmp]# cd cmake-2.8.8

[root@test cmake-2.8.8]#./configure

[root@test cmake-2.8.8]#make && make install

4)源码安装 MySQL

(1)建立运行MySQL的用户和组

[root@test ~]# groupadd mysql

[root@test ~]# useradd -M -g mysql -s /sbin/nologin mysql

(2)建立相关目录

[root@test ~]# mkdir /usr/local/mysql

[root@test ~]# mkdir /var/lock/mysql

[root@test ~]# mkdir /var/run/mysql

[root@test ~]# mkdir /var/log/mysql

[root@test ~]# mkdir /data1/mysql_db

[root@test ~]# chown -R mysql:mysql /usr/local/mysql/

[root@test ~]# chown mysql:mysql /var/run/mysql/

[root@test ~]# chown mysql:mysql /var/lock/mysql/

[root@test ~]# chown mysql:mysql /var/log/mysql/

[root@test ~]# chown mysql:mysql /data1/mysql_db/

(3)源码安装 MySQL

[root@test ~]# cd /data1/lnmp/

[root@test lnmp]# tar -xzf mysql-5.5.25a.tar.gz

[root@test lnmp]# cd mysql-5.5.25a

[root@test mysql-5.5.25a]# cmake .-DCMAKE_INSTALL_PREFIX=/usr/local/mysql

-DSYSCONFDIR=/etc

-DINSTALL_MANDIR=/usr/share/man \

-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \

-DMYSQL_DATADIR=/data1/mysql_db \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DWITH_READLINE=ON \

-DWITH_SSL=system \

-DWITH_DEBUG=0 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DINSTALL_LAYOUT=STANDALONE \

-DENABLED_LOCAL_INFILE=1 \

-DENABLED_PROFILING=1 \

-DMYSQL_MAINTAINER_MODE=0 \

-DWITH_EMBEDDED_SERVER=1 \

-DMYSQL_TCP_PORT=3306 \

-DMYSQL_USER=mysql

[root@test mysql-5.5.25a]#make

[root@test mysql-5.5.25a]#make install

(4)建立 MySQL配置文件

[root@test mysql-5.5.25a]# cp support-files/my-huge.cnf /etc/my.cnf

[root@test mysql-5.5.25a]# cp support-files/mysql.server/etc/rc.d/init.d/mysqld

[root@test mysql-5.5.25a]# chmod 755 /etc/rc.d/init.d/mysqld

[root@test mysql-5.5.25a]# echo "export PATH=$PATH:/usr/local/mysql/bin">> /etc/profile

[root@test mysql-5.5.25a]#source /etc/profile

------------------------------------------------------------------------------------------

注意:

在mysql-5.5.25a/support-files下共有5种my.cnf配置文件。

★my-small.cnf:适用于小型数据库,该配置文件专为物理内存小于64MB的服务器而设计。

★my-medium.cnf:适用于物理内存在32MB到64MB之间的专用于运行MySQL服务器,或物理内存在128MB以上。

★my-large.cnf:适用于物理内存在512MB以上的专用于运行MySQL数据库的服务器。

★ my-huge.cnf:适用于物理内存在1GB到2GB之间的专用于运行MySQL数据库服务器。

★my-innodb-heavy-4G.cnf:适用于服务器物理内存在4GB以上,且需要运行复杂查询的MySQL数据库。

------------------------------------------------------------------------------------------

(5)修改/etc/rc.d/init.d/mysqld脚本文件

根据 cmake
时指定的配置参数和my.cnf 配置文件中的参数修改 mysqld这个脚本中的变量;my.cnf
配置文件中的参数优先于 cmake时指定的参数。如果 my.cnf
配置文件没有设置对应的参数,则数据库运行时会以 cmake时指定的参数为准。my.cnf
中参数优先级高于 cmake时的配置参数。

[root@test ~]# vim /etc/rc.d/init.d/mysqld

basedir=/usr/local/mysql

datadir=/data1/mysql_db

lockdir='/var/lock/mysql'

lock_file_path="$lockdir/mysql.lock"

mysqld_pid_file_path = /var/run/mysql/mysql.pid

(6)修改 /etc/my.cnf配置文件

根据 cmake
时的配置修改 my.cnf文件的部分参数。如果 my.cnf配置文件没有设置对应的参数,则数据库运行时会以 cmake
时指定的参数为准。my.cnf中参数优先级高于 cmake
时的配置参数。

[root@test ~]# vim /etc/my.cnf

# The following options will be passed to all MySQL clients

[client]

#password =your_password

port = 3306

socket = /tmp/mysql.sock

# The MySQL server

[mysqld]

user = mysql

port = 3306

socket =/tmp/mysql.sock

basedir =/usr/local/mysql

datadir =/data1/mysql_db

pid-file =/var/run/mysql/mysql.pid

log-error =/var/log/mysql/mysql.log

character-set-server = utf8

(7)初始化数据库

[root@test scripts]# pwd

/usr/local/mysql/scripts

[root@test scripts]# ll

total 16

-rwxr-xr-x. 1 mysql mysql 14816 Jul 13 14:50 mysql_install_db

[root@test scripts]#./mysql_install_db--user=mysql--defaults-file=/etc/my.cnf --basedir=/usr/local/mysql--datadir=/data1/mysql_db

[root@test ~]#chown -R mysql:mysql /data1/mysql_db/ #根据具体情况决定做不做这一步。

(8)启动mysql

[root@test ~]# chkconfig --add mysqld

[root@test ~]# chkconfig --level 35 mysqld on

[root@test ~]# service mysqld start

(9)设置 mysql用户 root
的密码


[root@test ~]# mysqladmin-u root -p password 123456

—————出现ERROR:

mysqladmin: connect toserver at 'localhost' failederror: 'Access denied for user 'root'@'localhost'(using password: YES)'

解决方法:忘记本地root的登录密码

解决过程:

1、编辑/etc/my.cnf

在[mysqld] 配置部分添加一行

skip-grant-tables

2、保存后重启mysql

[root@localhost etc]# service mysqld restart

Shutting down MySQL. [ OK ]

Starting MySQL. [ OK ]

3、登录数据库重新设置root密码

[root@localhost ~]# mysql -uroot -p mysql

[b]Enter password:
[/b]

直接回车进入

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.1.47-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| test |

+--------------------+

3 rows in set (0.00 sec)

执行下列语句

mysql> update user set password=password("mysql") where user='root';

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4 Changed: 4 Warnings: 0

mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

4、删除/etc/my.cnf文件中添加的“skip-grant-tables”行,重启mysql;

用新设的密码就能正常登录了;

——————————————————————————————————————————————————————————————————————————————

(10)重新进入mysql

[root@test ~]# service mysqld restart

[root@test ~]# mysqladmin -u root -p password mysql

Enter Password: mysql

[root@test ~]#mysql –u root –p mysql

Enter Password:mysql;

出现下面,证明成功进入Mysql.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.5.25a-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rightsreserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement.

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| test |

+--------------------+

4 rows in set (0.00 sec)

四、安装PHP

1)库文件准备

在安装PHP之前,应先安装PHP5需要的最新版本库文件,例如libxml2、libmcrypt以及GD2库等文件。安装GD2库是为了让PHP5支持GIF、PNG和JPEG图片格式,所以在安装GD2库之前还要先安装最新的zlib、libpng、freetype和jpegsrc等库文件。而且中间还会穿插安装一些软件。

autoconf-2.61.tar.gz

freetype-2.3.5.tar.gz

gd-2.0.35.tar.gz

jpegsrc.v6b.tar.gz

libmcrypt-2.5.8.tar.gz

libpng-1.2.31.tar.gz

libxml2-2.6.30.tar.gz

zlib-1.2.3.tar.gz

ZendOptimizer-3.2.6-linux-glibc23-x86_64.tar.gzphpMyAdmin-3.0.0-rc1-all-languages.tar.gz

2) 安装库文件

安装前先检查一下,相应的包是否已经安装,若已安装先不必安装,在安装PHP时如果出现Error,再安装相应的库文件。

我安装了以下几个库文件

1)安装zlib

# cd /usr/local/src/zlib-1.2.3

# ./configure

# make && make install

2)安装libpng

# cd /usr/local/src/libpng-1.2.31

# ./configure --prefix=/usr/local/libpng

# make && make install

3)安装GD库

# cd /usr/local/src/gd-2.0.35

# ./configure \

--prefix=/usr/local/gd2/ \

--enable-m4_pattern_allow \

--with-zlib=/usr/local/zlib/ \

--with-jpeg=/usr/local/jpeg6/ \

--with-png=/usr/local/libpng/ \

--with-freetype=/usr/local/freetype/

# make

3) 安装PHP

#tar –zxvf php-5.2.17.tar.gz

# cd php-5.2.17

# ./configure \

--prefix=/usr/local/php \

--with-config-file-path=/usr/local/php/etc\

--with-apxs2=/usr/local/apache2/bin/apxs\

--with-mysql=/usr/local/mysql/ \

--with-libxml-dir=/usr/local/libxml2/\

--with-png-dir=/usr/local/libpng/\

--with-jpeg-dir=/usr/local/jpeg6/\

--with-freetype-dir=/usr/local/freetype/\

--with-gd=/usr/local/gd2/ \

--with-zlib-dir=/usr/local/zlib/ \

--with-mcrypt=/usr/local/libmcrypt/\

--with-mysqli=/usr/local/mysql/bin/mysql_config\

--enable-soap \

--enable-mbstring=all \

--enable-sockets

# make && make install

4)配置PHP

(1)创建配置文件

# cp php.ini-dist/usr/local/php/etc/php.ini

(2)使用vi编辑apache配置文件

# vi /etc/httpd/httpd.conf

查找AddType application/x-gzip .gz.tgz

在下面添加这代码

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

AddTypeapplication/x-httpd-php-source .phps

注意:一定要正确添加这两条的位置,否则,打开PHP页面时显示源码或下载对话框

(3)查找DirectoryIndex,添加index.php

<IfModuledir_module>

DirectoryIndexindex.php index.html

</IfModule>

(4)重启Apache

#/usr/local/apache2/bin/apachectl restart

五、安装Zend加速器

#ZendOptimizer-3.2.6-linux-glibc23-x86_64.tar.gz

# cdZendOptimizer-3.2.6-linux-glibc23-x86_64/

# ./install.sh

六、安装phpMyAdmin

1)
安装


#tar –zxvf phpMyAdmin-4.0.5-rc2-all-languages.tar.gz


# cp -a
phpMyAdmin-4.0.5-rc2-all-languages/usr/local/apache2/htdocs/phpmyadmin


# cd/usr/local/apache2/htdocs/phpmyadmin/

# cpconfig.sample.inc.php config.inc.php

2)配置phpMyAdmin

# vi/usr/local/apache2/htdocs/phpmyadmin/config.inc.php

将auth_type改为http

七、测试PHP

写一个test.php放到:/etc/httpd/httpd.conf的DocumentRoot所指的路径下。

test.php:



通过浏览器访问http://192.168.1.220/test.php,获得php的详细配置信息



八、访问phpAdmin

用户名和密码是mysql的用户名和密码





参考:

http://www.cnblogs.com/mchina/archive/2012/11/28/2778779.html http://www.linuxidc.com/Linux/2012-07/66920.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: