centos 6.4 源码安装php5.4 mysql5.5 apahce2

参考:http://blog.csdn.net/simpleiseasy/article/details/8053215

一、准备(把所有的源文件放在‘/home/yuanjun’目录下)
apr       wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.1.tar.gz
apr-util  wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
pcre      wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
httpd     wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.10.tar.gz
php5.4    wget http://cn2.php.net/get/php-5.4.33.tar.gz/from/this/mirror
mysql5.5  wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.40.tar.gz


# 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 zxvf apr-1.5.1.tar.gz
# cd apr-1.5.1
# ./configure --prefix=/usr/local/apr
# make
# make install

2.1.2安装 apr-util
# cd /home/yuanjun
# 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 /home/yuanjun
# tar zxvf pcre-8.34.tar.gz
# cd pcre-8.34
# ./configure --prefix=/usr/local/pcre
# make && make install

2.1.4安装 apache
# cd /home/yuanjun
# tar zxf httpd-2.4.10.tar.gz
# cd httpd-2.4.10
# ./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 zxf mysql-5.5.40.tar.gz
# cd zxf mysql-5.5.40
# 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  --enable-fpm --with-xml --with-jpeg-dir --with-zlib --with-freetype --with-gd
# 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!”,说明成功了

测试gd
vi /usr/local/apache2/htdocs/php_gd.php
<?php
imagecreatetruecolor(200,200);
?>
在浏览器输入“http://localhost/php_gd.php”,如果不出错, 就表示成功了.


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

安装php curl的扩展.
$ cd /soft/php-5.4.33/ext/curl
$ phpize
$ ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql  --enable-fpm --with-xml --with-jpeg-dir --with-zlib --with-freetype --with-gd --with-curl=DIR
#也就是把php给重新编译一下, 

然后重启apache

service httpd restart

从上面的可以看出, 一些扩展可以直接就这样执行. 进行到ext/相应扩展目录, 执行phpize

猜你喜欢

转载自wen66.iteye.com/blog/2128314