CentOS下源码安装Apache2.4+PHP5.4+MySQL5.5

一、准备(把所有的源文件放在‘/home/yuanjun’目录下)
apr http://mirror.bjtu.edu.cn/apache/apr/apr-1.4.6.tar.gz
apr-util http://mirror.bjtu.edu.cn/apache/apr/apr-util-1.4.1.tar.gz
pcre ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.zip
httpd http://mirror.bjtu.edu.cn/apache/httpd/httpd-2.4.1.tar.gz
php5.4 http://cn2.php.net/get/php-5.4.0.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/
# 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 /home/yuanjun
# tar zxf apr-1.4.6.tar.gz 
# cd apr-1.4.6/
# ./configure --prefix=/usr/local/apr
# make 
# make install
2.1.2安装 apr-util
# cd /home/yuanjun
# tar zxf apr-util-1.4.1.tar.gz
# cd apr-util-1.4.1/
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install
2.1.3安装 pcre
# cd /home/yuanjun
# unzip pcre-8.30.zip 
# cd pcre-8.30/
# ./configure --prefix=/usr/local/pcre
# make
# make install
2.1.4安装 apache
# cd /home/yuanjun
# tar zxf httpd-2.4.1.tar.gz
# cd httpd-2.4.1/
# ./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
# iptables -F
# iptables -P INPUT ACCEPT
2.2 安装 mysql
2.2.1安装 cmake
# cd /home/yuanjun
# wget http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz
# tar zxf cmake-2.8.3.tar.gz
# cd cmake-2.8.3
# 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 /home/yuanjun
# tar zxf mysql-5.5.21.tar.gz
# cd mysql-5.5.21
# yum -y install ncurses-devel
# yum install bison
# cmake .
如果出现错误:
 # rm CMakeCache.txt
 # cmake .


# make 
# make install
# cd /usr/local/mysql/
# chown -R mysql .
# chgrp -R mysql .
# scripts/mysql_install_db --user=mysql
# chown -R root .
# chown -R mysql data
# cp support-files/my-medium.cnf /etc/my.cnf
# bin/mysqld_safe --user=mysql &
# bin/mysqladmin -u root password "111111"
# cp support-files/mysql.server /etc/init.d/mysqld
# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
# chmod +x /etc/init.d/mysqld
# service mysqld start
测试一下:
# 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.4.8.tar.gz

#cd php-5.4.8

#./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
# make
# make install
# cp php.ini-development /usr/local/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
加入“<?php phpinfo();?>”,保存退出
#service httpd restart
在浏览器中输入"http://localhost/index.php",查看是否有phpinfo的消息。
2.3.4 测试php-mysql
# vi /usr/local/apache2/htdocs/php_mysql.php
输入
<?php
$link=mysql_connect('localhost','root','850909');
if(!$link) echo "connect error!";
else echo "connected!";
mysql_close();
?>
在浏览器输入“http://localhost/php_mysql.php”,若显示“connected!”,说明成功了
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页