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

Linux下源码安装php环境,centos下安装phpcmsv9(apache2.4.3+mysql5.5+php5.4)

2013-01-13 13:58 741 查看
上次使用yum安装lamp环境,后来安装phpcmsV9发现php版本过低,汗....只得重新安装了,到系统以查看,好多版本都过低,唉,yum真是懒惰的家伙,好吧,自己动手丰衣足食。

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

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.3.tar.gz
php5.4 http://cn2.php.net/distributions/php-5.4.10.tar.gz
mysql http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.29.tar.gz

如果地址变动,请到官网下载。

升级一下必须的工具或者库

# yum install gcc gcc-c++ glibc glibc-devel gd gd-devel zlib zlib-devel libtool-ltdl-devel flex autoconf automake

二、安装apache
2.1 安装 apache
2.1.1安装 apr
# cd /home/17le
# 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/17le
# 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/17le
# unzip pcre-8.30.zip
# cd pcre-8.30/
# ./configure --prefix=/usr/local/pcre
# make
# make install
2.1.4安装 apache
# cd /home/17le
# 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

在浏览器中输入http://serverip/ 测试一下。

#若遇到以下问题

ap@ap-mint/lib$/usr/local/apache/bin/apachectl start

/usr/local/apache/bin/httpd:error whileloading shared libraries:libpcre.so.1:cannot open shared objectfile:No such fileordirectory

#可试试以下命令

ln-s/usr/local/lib/libpcre.so.1/lib

#若遇到问题

AH00558:httpd:Could notreliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName'directive globally tosuppress thismessage

#则需在http.conf中的ServerName行取消注释,可将值设为127.0.0.1或者localhost

即:
ServerName localhost:80 或者
ServerName 127.0.0.1:80 或者

2.1.6打开iptables
# iptables -F
# iptables -P INPUT ACCEPT
2.2 安装 mysql
2.2.1安装 cmake
# cd /home/17le
# 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

三、安装mysql

3.1、安装
# groupadd mysql
# useradd -r -g mysql mysql
# cd /home/17le
# 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 .

这里注意,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 &
# 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,数据有残余。下面给出一些方法

1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限 解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data” 然后重新启动mysqld!

2.可能进程里已经存在mysql进程 解决方法:用命令“ps -ef|grep mysqld”查看是否有mysqld进程,如果有使用“kill -9 进程号”杀死,然后重新启动mysqld!

3.可能是第二次在机器上安装mysql,有残余数据影响了服务的启动。 解决方法:去mysql的数据目录/data看看,如果存在mysql-bin.index,就赶快把它删除掉吧,它就是罪魁祸首了。本人就是使用第三条方法解决的 !http://blog.rekfan.com/?p=186

4.mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录(datadir)。 解决方法:请在[mysqld]下设置这一行:datadir = /usr/local/mysql/data

5.skip-federated字段问题 解决方法:检查一下/etc/my.cnf文件中有没有没被注释掉的skip-federated字段,如果有就立即注释掉吧。

6.错误日志目录不存在 解决方法:使用“chown” “chmod”命令赋予mysql所有者及权限

7.selinux惹的祸,如果是centos系统,默认会开启selinux 解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试。

3.2测试一下:
# mysql

3.3、设置初始密码,没有密码,直接输入mysql命令即可

[root@AY12122501352213a7156 ~]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.58 MySQL Community Server (GPL) by Utter Ramblings

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>USE mysql; #使用mysql数据库

mysql>UPDATE user SET Password=PASSWORD('新密码') WHERE user='root'; #更改数据库密码

mysql>FLUSH PRIVILEGES; #刷新刚才的操作,否则刚才的操作无效。

3.4、允许mysql远程登录

[root@AY12122501352213a7156 ~]# mysql -u root -p

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

mysql>GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION; #给‘用户名’授予所有权限,并且设置密码为‘密码’ 完成后就能用SQL-Front软件远程管理mysql了。

注意:为了防止sql出错,命令行失效,你可以在输入sql的结尾最好加上“;”,

3.5把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

四、 安装php

如果要支持更多扩展,如gd,ftp等支持,是的,phpcmsv9就是要这些库的支持,如果要安装phpcmsv9请看centos安装gd库扩展以及ftp扩展,phpcmsv9安装环境
4.1、安装
#cd /home/17le
#tar zxf php-5.4.10.tar.gz
#cd php-5.4.10
#./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

4.2、 测试php
# vi /usr/local/apache2/htdocs/index.php
加入“<?php phpinfo();?>”,保存退出
#service httpd restart
在浏览器中输入"http://servierip/index.php",查看是否有phpinfo的消息。

这里可能会遇到问题,apche启动不报错,就是php无法解析,html可以解析,在浏览器中查看 php的源文件是ph源代码,查了下。说是php要开启短标签 short_open_tag = On 默认为Off 在php.ini里面进行设置 设置。

#vi /usr/local/lib/php.ini

# service httpd restart

OK应该没有什么问题了。如果遇到什么问题,请先冷静,在百度和google定能搞定。

4.3 测试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://servierip/php_mysql.php”,若显示“connected!”,说明成功了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: