本文主要是介绍CentOS6.5 PHP5.4.0+Apache2.4.1+MySQL5.5.21 编译安装,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、准备(把所有的源文件放在‘/usr/local/upload’目录下)
下载:http://pan.baidu.com/s/1gdh2zzP
修改防火墙规则:
# vi /etc/sysconfig/iptables
添加:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重启防火墙服务:
# service iptables restart
二、安装 && 测试
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
# cd /usr/local
# chmod -R 777 upload
# cd ./upload
# tar -zvxf apr.tar.gz
# cd apr-1.4.6/
# ./configure --prefix=/usr/local/apr
# make && make install
2.1.2安装 apr-util
# cd /usr/local/upload
# tar -zvxf apr-util.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 /usr/local/upload
# unzip pcre.zip
# cd ./pcre-8.30
# ./configure --prefix=/usr/local/pcre
# make && make install
2.1.4安装 apache
# cd /usr/local/upload
# tar zxf httpd.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
# vi /usr/local/apache2/conf/httpd.conf
修改 #ServerName www.example.com:80
为 ServerName localhost:80
然后
# service httpd start
访问下主机地址 : It works!
2.2 安装 mysql
2.2.1安装 cmake
# cd /usr/local/upload
# tar -zvxf cmake.tar.gz
# cd ./cmake-2.8.3
# ./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 /usr/local/upload
# tar -zvxf mysql.tar.gz
# cd mysql-5.5.21
# yum -y install ncurses-devel
# yum -y 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
把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 start
测试一下:
# mysql -u root -p
然后输入密码,如果能够进入就说明安装好了
2.3 安装 php
2.3.1 安装libxml2
#yum install libxml2
#yum install libxml2-devel -y
2.3.2 安装libmcrypt
# cd /usr/local/upload
# tar -zvxf libmcrypt-2.5.8.tar.gz
# cd ./libmcrypt-2.5.8
# ./configure --prefix=/usr/local/libmcrypt
# make && make install
2.3.3 安装mhash
# cd /usr/local/upload
# tar -zvxf mhash-0.9.9.9.tar.gz
# cd ./mhash-0.9.9.9
# ./configure --prefix=/usr/local/mhash
# make && make install
2.3.4 安装openssl,bzip2,libcurl
# yum -y install openssl openssl-devel bzip2 bzip2-devel curl curl-devel
2.3.5 安装php
# cd /usr/local/upload
# tar -zvxf php-5.4.0.tar.gz
# cd php-5.4.0
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --enable-fpm --with-mcrypt=/usr/local/libmcrypt --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --enable-pdo --with-pdo-mysql --with-gettext --with-curl=/usr/share/doc/curl-7.19.7 --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip
# 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.6 测试php
# vi /usr/local/apache2/htdocs/index.php
加入“<?php phpinfo();?>”,保存退出
在浏览器中输入"http://localhost/index.php",查看是否有phpinfo的消息。
2.3.7 测试php-mysql
# vi /usr/local/apache2/htdocs/php_mysql.php
输入
<?php
$link=mysql_connect('localhost','root','111111');
if(!$link) echo "connect error!";
else echo "connected!";
mysql_close();
?>
在浏览器输入“http://localhost/php_mysql.php”,若显示“connected!”,说明成功了
2.3.8 添加mysql和php环境变量
修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码:
PATH=$PATH:/usr/local/php/bin:/usr/local/mysql/bin
export PATH
最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。
End.
文章来源于:
这篇关于CentOS6.5 PHP5.4.0+Apache2.4.1+MySQL5.5.21 编译安装的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!