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

时间:2023-03-09 21:52:16
centos 6.4 源码安装php5.4 mysql5.5 apahce2
参考:http://blog.****.net/simpleiseasy/article/details/8053215

一、准备(把所有的源文件放在‘/home/yuanjun’目录下)

  1. apr       wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.1.tar.gz
  2. apr-util  wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
  3. pcre      wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
  4. httpd     wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.10.tar.gz
  5. php5.4    wget http://cn2.php.net/get/php-5.4.33.tar.gz/from/this/mirror
  6. mysql5.5  wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.40.tar.gz
  1. # 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

  1. # cd /home/yuanjun
  2. # tar zxvf apr-1.5.1.tar.gz
  3. # cd apr-1.5.1
  4. # ./configure --prefix=/usr/local/apr
  5. # make
  6. # make install

2.1.2安装 apr-util

  1. # cd /home/yuanjun
  2. # tar zxf apr-util-1.5.4.tar.gz
  3. # cd apr-util-1.5.4
  4. # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  5. # make && make install

2.1.3安装 pcre

  1. # cd /home/yuanjun
  2. # tar zxvf pcre-8.34.tar.gz
  3. # cd pcre-8.34
  4. # ./configure --prefix=/usr/local/pcre
  5. # make && make install

2.1.4安装 apache

  1. # cd /home/yuanjun
  2. # tar zxf httpd-2.4.10.tar.gz
  3. # cd httpd-2.4.10
  4. # ./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
  5. # make && make install

2.1.5将apache安装为系统服务

  1. # cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

然后 vi /etc/rc.d/init.d/httpd 添加(# !/bin/sh下面)

  1. # chkconfig: 2345 50 90
  2. # description: Activates/Deactivates Apache Web Server

保存退出

最后,运行chkconfig把Apache添加到系统的启动服务组里面:

  1. # chkconfig --add httpd
  2. # chkconfig httpd on

然后再service httpd start 
2.1.6打开iptables 
# iptables -F 
# iptables -P INPUT ACCEPT 
2.2 安装 mysql 
2.2.1安装 cmake

  1. # cd /home/yuanjun
  2. # wget http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz
  3. # tar zxf cmake-2.8.3.tar.gz
  4. # cd cmake-2.8.3
  5. # yum install gcc
  6. # yum install gcc-c++
  7. # ./configure
  8. # make
  9. # make install
  10. # ln -s /usr/local/bin/cmake /usr/bin/cmake

2.2.2安装mysql

  1. # groupadd mysql
  2. # useradd -r -g mysql mysql
  3. # cd /home/yuanjun
  4. # tar zxf zxf mysql-5.5.40.tar.gz
  5. # cd zxf mysql-5.5.40
  6. # yum -y install ncurses-devel
  7. # yum install bison
  8. # cmake .
  9. 如果出现错误:
  10. # rm CMakeCache.txt
  11. # cmake .
  12. # make
  13. # make install
  14. # cd /usr/local/mysql/
  15. # chown -R mysql .
  16. # chgrp -R mysql .
  17. # scripts/mysql_install_db --user=mysql
  18. # chown -R root .
  19. # chown -R mysql data
  20. # cp support-files/my-medium.cnf /etc/my.cnf
  21. # bin/mysqld_safe --user=mysql &
  22. # bin/mysqladmin -u root password "111111"
  23. # cp support-files/mysql.server /etc/init.d/mysqld
  24. # ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
  25. # chmod +x /etc/init.d/mysqld
  26. # service mysqld start

测试一下: 
# mysql -u root -p 
然后输入密码,如果能够进入就说明安装好了

把mysql安装为系统启动项

  1. # vi /etc/rc.d/init.d/mysqld 添加(# !/bin/sh下面)
  2. # chkconfig: 2345 51 89
  3. # description: Activates/Deactivates MySQL Server
  4. 保存退出
  5. # chkconfig --add mysqld
  6. # chkconfig mysqld on
  7. # service mysqld restart

2.3 安装 php 
2.3.1 安装libxml2

  1. #yum install libxml2
  2. #yum install libxml2-devel -y

2.3.2 安装php

  1. #cd /home/yuanjun
  2. #tar zxf php-5.4.8.tar.gz
  3. #cd php-5.4.8
  4. #./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql  --enable-fpm --with-xml --with-jpeg-dir --with-zlib --with-freetype --with-gd
  5. # make
  6. # make install
  7. # cp php.ini-development /usr/local/lib/php.ini
  8. # vi /usr/local/apache2/conf/httpd.conf
  9. 确保以下字符串是否存在
  10. LoadModule php5_module modules/libphp5.so
  11. 如果没有就加上
  12. 在AddType application*后面加如下一行
  13. AddType application/x-httpd-php .php .phtml
  14. 在DirectoryIndex index.html加上index.php
  15. DirectoryIndex index.php index.html
  16. #service httpd restart
  17. 若有error发生
  18. # setenforce 0
  19. # chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so
  20. # 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的扩展.

  1. $ cd /soft/php-5.4.33/ext/curl
  2. $ phpize
  3. $ ./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
  4. #也就是把php给重新编译一下,
  5. 然后重启apache
  6. service httpd restart
  7. 从上面的可以看出, 一些扩展可以直接就这样执行. 进行到ext/相应扩展目录, 执行phpize
Python正确的学习路线,你一定不知道的薪资翻倍秘
如何从8K提至20K月薪,你要掌握学习那些技能