Linux下Apache+PHP+MySQL搭建

一、Apache

安装路径:/opt

(一)解决编译时apache出现的问题:configure: error: APR not found . Please read the documentation

安装依赖包:

[root@sohu opt]wget www.apache.org/dist/apr/apr-1.4.5.tar.gz

[root@sohu opt]wget www.apache.org/dist/apr/apr-util-1.3.12.tar.gz

[root@sohu opt]wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.tar.gz

编译安装:

[root@sohu opt]# mkdirapr

[root@sohu opt]# tar -zxvf apr-1.4.5.tar.gz

[root@sohu opt]# cd apr-1.4.5
[root@sohu apr-1.4.5]# ./configure --prefix=/opt/apr

[root@sohu apr-1.4.5]# make && make install


[root@sohu opt]# mkdir apr-util

[root@sohu opt]# tar -zxvf apr-util-1.3.12.tar.gz

[root@sohu opt]# cd apr-util

[root@sohu apr-util-1.3.12]# ./configure --prefix=/opt/apr-util -with-apr=/opt/apr/bin/apr-1-config

[root@sohu apr-util-1.3.12]# make && make install


[root@sohu opt]# mkdir pcre

[root@sohu opt]# tar -zxvf pcre-8.10.tar.gz

[root@sohu opt]# cd pcre-8.10
[root@sohu pcre-8.10]# ./configure ./configure --disable-shared --with-pic --prefix=/opt/pcre --prefix=/opt/pcre

[root@sohu pcre-8.10]# make && make install

(二)安装Apache

[root@sohu opt]# wget www.apache.org/dist/httpd/httpd-2.2.29.tar.gz

[root@sohu opt]# tar -zxvf httpd-2.2.14.tar.gz

[root@sohu opt]# cd httpd-2.2.14

[root@sohu httpd-2.2.14]# ./configure --prefix=/opt/apache --with-apr=/opt/apr --with-apr-util=/opt/apr-util/ --with-pcre=/opt/pcre
[root@sohu httpd-2.2.14]# make && make install
[root@sohu httpd-2.2.14]# /opt/apache/bin/apachectl -t(检查Apache配置文件语法是否正确)

[root@sohu httpd-2.2.14]# /opt/apache/bin/apachectl start

[root@sohu bin]# export PATH=$PATH:/opt/apache/bin(修改环境变量)
[root@sohu bin]# source /etc/profile
[root@sohu bin]# apachectl restart

问题:httpd: apr_sockaddr_info_get() failed for sohu.rose
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

解决办法:

vi /apache/conf/httpd.conf

去掉ServerName前面的注解,并修改为localhost:80(80为listen端口号)或者Linux虚拟机IP:80

问题:启动后在window浏览器输入IP:80后无法访问

解决办法:

iptables -I INPUT -p TCP --dport 80 -j ACCEPT,使用iptables命令将80端口设置成运行任何IP都可以访问

问题:configure: error: no acceptable C compiler found in $PATH错误解决

原因是没装gcc,直接yum install gcc安装完以后继续./configure即可正常运行;

问题:安装pcre install时

make[1]: *** [pcrecpp.lo] Error 1
make[1]: Leaving directory `/opt/pcre-8.10'
make: *** [all] Error 2

解决办法:

这个错误是缺少gcc安转包,运行如下命令:

[root@localhost pcre-8.30]# yum -y install gcc-c++

问题:.libs/pcrecpp.o:could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [libpcrecpp.la] 错误 1
make[1]: Leaving directory `/usr/app/pcre-8.00'
make: *** [all] 错误 2

解决办法:./configure --disable-shared --with-pic

二、Mysql

(一)安装

首先安装cmake,从mysql-5.5起,mysql源码安装开始使用cmake了

[root@sohu opt]# wget www.cmake.org/files/v2.8/cmake-2.8.0.tar.gz

[root@sohu opt]# tar -zxvf www.cmake.org/files/v2.8/cmake-2.8.0.tar.gz

[root@sohu opt]# cd cmake-2.8.0

[root@sohu cmake-2.8.0]# ./configure --prefix=/opt/cmake

[root@sohu cmake-2.8.0]# make && make install

[root@sohu opt]# wget mysql.mirror.kangaroot.net/Downloads/MySQL-5.5/mysql-5.5.42.tar.gz

[root@sohu opt]# tar -zxvf mysql-5.5.42.tar.gz

[root@sohu opt]# cdmysql-5.5.42

[oot@sohu mysql-5.5.42]#cmake  -DCMAKE_INSTALL_PREFIX=/opt/mysql

此处可能会提示-bash: cmake: command not found执行下面命令

[root@sohumysql-5.5.42]# export PATH=/opt/cmake/bin:$PATH

问题:

-- Could NOT find Curses  (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)

CMake Error at cmake/readline.cmake:83 (MESSAGE):
  Curses library not found.  Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:127 (FIND_CURSES)
  cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)
  CMakeLists.txt:257 (MYSQL_CHECK_READLINE) 
-- Configuring incomplete, errors occurred!
解决办法:

该报错原因是未安装ncurses-devel,运行下面命令

第一步:安装#yum -y install ncurses-devel
第二步:删除CMakeCache.txt
通过find命令找到所有CMakeCache.txt文档的位置

# find / -name CMakeCache.txtrm -rf /opt/mysql/mysql-5.5.42/CMakeCache.txt /opt/cmake-2.8.0/Tests/ComplexOneConfig/Cache/CMakeCache.txt /opt/cmake-2.8.0/Tests/ComplexRelativePaths/Cache/CMakeCache.txt /opt/cmake-2.8.0/Tests/Complex/Cache/CMakeCache.txt /opt/cmake-2.8.0/CMakeCache.txt

第三步:重新cmake就可以了

[root@sohumysql-5.5.42]#make && make install

(二)配置

>创建一个mysql用户

[root@sohu ~]# useradd mysql
[root@sohu ~]# su mysql

[mysql@sohu ~]$ cd /opt/mysql/scripts/

>安装默认数据库

[mysql@sohu scripts]$ sudo ./mysql_install_db --basedir=/opt/mysql --datadir=/opt/mysql/data/ --user=mysql

问题:执行sudo需要输入密码,但是我输入之后它提示我说mysql用户不在sudoers文件夹中:

解决办法:

[mysql@sohu scripts]$ su root
[root@sohu scripts]# visudo

在root    ALL=(ALL)       ALL下面加上一行 mysql   ALL=(ALL)       ALL

[root@sohu scripts]# sudo ./mysql_install_db --basedir=/opt/mysql --datadir=/opt/mysql/data/ --user=mysql

>将mysql的配置文件和服务文件复制到系统配置路径下面

[root@sohu support-files]# cp my-medium.cnf /etc/my.cnf

[root@sohu support-files]# cp mysql.server /etc/init.d/mysqld

>启动服务

[root@sohu support-files]# service  mysqld  start

>将mysql命令映射到bin目录下

[root@sohu ~]# ln -s /opt/mysql/bin/mysql /usr/bin

>远程登录数据库

[root@sohu ~]# mysql -uusername -hhostaddress -ppassword


三、PHP

(一)安装

>安装依赖包

[root@sohu php]# wget sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

[root@sohu php]# tar -zxvf libmcrypt-2.5.8.tar.gz

[root@sohu php]# cd libmcrypt-2.5.8
[root@sohu libmcrypt-2.5.8]# ./configure

[root@sohu libmcrypt-2.5.8]# make && make install

>mhash依赖重复libmcrypt的安装操作

[root@sohu php]# wget sourceforge.net/projects/mhash/files/mhash/0.9.9/mhash-0.9.9.tar.gz

>安装php

[root@sohu opt]# wget mirrors.sohu.com/php/php-5.5.11.tar.gz

[root@sohu opt]# tar -zxvf php-5.5.11.tar.gz

[root@sohu php-5.5.11]# ./configure --prefix=/opt/php --with-apxs2=/opt/apache/bin/apxs --with-config-file-path=/opt/php/etc --with-config-file-path=/opt/php/etc --with-mysql=/opt/mysql --with-png-dir=/usr --with-jpeg-dir=/usr --with-xml --enable-track-vars --enable-mbstring=all --enable-gd-native-ttf --enable-calendar

[root@sohu php-5.5.11]#make && make install

>复制配置文件

[root@sohu php-5.5.11]# cp php.ini-production /opt/php/etc/php.inc

>修改Apache配置支持php

修改DirectoryIndex index.html 为DirectoryIndex index.html index.php
并添加AddType application/x-httpd-php .php

创建测试php页面test.php,并存放在网站主目录下,
<?php
phpinfo();
?>
重启apache服务后,访问http://ip:port/test.php

若看到info页面表示成功


若看到mysql配置页面表示php+mysql配置成功

或者用以下代码来进行mysql测试

<span style="font-size:18px;"><?php
$link=mysql_connect("localhost","root","123");
if(!$link) echo "failed";
else echo "success";
?> </span>
到此为止,Linux下Apache+Mysql+PHP配置完成


参考网址:

http://www.jb51.net/article/39190.htm

http://blog.csdn.net/yincg/article/details/8782364





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值