linux 安装 apache,php,mysql

安装APACHE

首先安装apache,

这个我是直接使用yum来进行安装的

yum install httpd  


配置文件(满足最基本的配置)
     编辑 /usr/local/apache2/conf/httpd.conf 文件     
     找到:
    AddType  application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    在后面添加:
    AddType application/x-httpd-php .php(使Apcche支持PHP)
    AddType application/x-httpd-php-source .php5   
    找到:
    <IfModule dir_module>
    DirectoryIndex index.html
    </IfModule>
    添加:
    <IfModule dir_module>
    DirectoryIndex index.html index.php
    </IfModule>    
    找到:
    #ServerName www.example.com:80
    修改为:
    ServerName 127.0.0.1:80或者ServerName localhost:80
    记得要去掉前面的“#” 


安装对应的httpd插件,否则无法把php集成起来 

yum install httpd-devel

这个里面有apxs

出处https://www.howtoforge.com/community/threads/cannot-compile-new-php-with-apxs.5/   内容如下

Cannot compile new PHP with apxs


  1. Hi,

    I have a dedicated server, it currently has Apache 2 and PHP 4.2.x installed on it. I'm trying to install PHP 4.3.11 on it.

    I have compiled PHP 4.3.11 on the machine, but Apache is still using the old version. I think this is because I didn't specify --with-apxs2=/path/to/apxs. I didn't do it, because I don't know the path to apxs. I can't find it anywhere on the server.

    I still have an httpd.conf file and everything.... and a directory for modules.... but I can't for the life of me find the path to apxs so that PHP ./configure can create the libphp4.so file.....

    Don't know what to do now...  :( Please help!

    Olli
     
  2. falko

    falkoSuper ModeratorISPConfig Developer

    Run

    Code:
    updatedb
    locate apxs
    to find apxs.
     
  3. olli

    olliNew Member

    updatedb and locate don't seem to be installed on my system...  :( Any hints?

    Olli
     
  4. falko

    falkoSuper ModeratorISPConfig Developer

    Run  yast and install the package  findutils-locate. Afterwards, updatedb and locate will be on your system.
     
  5. olli

    olliNew Member

    Run yast and install the package findutils-locate. Afterwards, updatedb and locate will be on your system.
    That did the trick.  :)  :) 

    Thanks!

    Olli
     
  6. areamike

    areamikeNew Member

    I did the above information to find path to apxs. All I get is path to

    /var/www/manual/programs/apxs.html.ko.euc-kr
    /var/www/manual/programs/apxs.html.en
    /var/www/manual/programs/apxs.html

    I cannot find th epath to apxs.

    I am running Redhat Enterprise 4 ES
     
  7. falko

    falkoSuper ModeratorISPConfig Developer

    You must install the apache-devel package.
    I'm not quite sure if RHEL uses yum or up2date as package manager. If it's yum, you can run
    Code:
    yum search apache
    to find the apache-devel package, and you can install it with
    Code:
    yum install <package_name>
    I don't know the syntax for up2date, so you better check with
    Code:
    man up2date
     
  8. areamike

    areamikeNew Member

    Thanks for the reply.
    It looks like RHEL4 uses up2date.
    However, there is no apache-devel package available for RHEL4.

    Looks like I will be compiling Apache manually myself...and just not use the default apache package that installs with Redhat.

    thanks.
     
  9. falko

    falkoSuper ModeratorISPConfig Developer

    areamike said:
    Thanks for the reply.
    It looks like RHEL4 uses up2date.
    However, there is no apache-devel package available for RHEL4.
    I can't imagine that... Are you sure? You should search again. Its name might not be apache-devel, but something with  apache in it.
     
  10. areamike

    areamikeNew Member

    falko said:
    I can't imagine that... Are you sure? You should search again. Its name might not be apache-devel, but something with  apachein it.
    I know. I was surprised too.
    I did an extensive search, but no luck.
    I'll check again.
     
  11. radical

    radicalNew Member

    areamike said:
    I know. I was surprised too.
    I did an extensive search, but no luck.
    I'll check again.
    It is included in RHEL4 or at least it's in CentOS 4. Install the package package "httpd-devel".
     
  12. areamike

    areamikeNew Member

    Sorry FALKO, After searching around and after radical's comment. I was able to find httpd-devel rpm on DISC4 for RHEL4.

    Thanks~!

    Now off to try and install PHP again...


即使wget安装  apache,也需要安装对应的   devel插件才行



安装PHP


1、 下载
    http://www.php.net/downloads.php
2、解压
    tar -zxvf php-5.6.3.tar.gz
3、建立目标文件夹
    mkdir /usr/local/php
    也就是说等下安装的php要安装到这个文件夹里面
4、配置
    回到原来解压后的文件夹
    ./configure --prefix=/usr/local/php  --with-apxs2=/usr/local/apache/bin/apxs

    注意这里有一个-with-apxs2=/usr/local/apache/bin/apxs选项,其中apxs是在安装Apache时产生的,apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具,使之可以用由mod_so提供的LoadModule指令在运行时加载到Apache服务器中。我的理解是通过这个工具把PHP模块动态加载到Apache中

出现错误:configure: error: xml2-config not found. Please check your libxml2 installation.

运行yum install libxml2,然后再运行yum install libxml2-devel安装完毕后,重新运行上面的./configure命令。

5、编译
    make   
6、测试编译
    make test   
7、安装
    make install

8、配置文件

    cp /usr/local/src/php-5.3.16/php.ini-development  /usr/local/php/lib/php.ini
    把原来位于源代码里面的php.ini-development拷贝到/usr/local/php/lib/php.ini下,并且重命名为php.ini

9.重启apache
10、测试
    在apache的htdocs下建立一个php文件test.php,里面的内容如下:
    <?php
    phpinfo();
    ?>
    然后在浏览器里输入http://127.0.0.1/test.php
    如果出现php的相关配置,成功,如果什么都没有输入,说明失败,重新以上步骤或者查找原因

如果决定在安装后改变配置选项,只需重复最后的三步configure, make, 以及 make install,然后需要重新启动 Apache 使新模块生效。Apache不需要重新编译。

测试结果如下图:


安装MYSQL

一     首选安装方法(rpm安装)


此处安装mysql,见我的另一篇关于MYSQL安装的文章  主要是RPM安装,最方便了


二   次选安装方法(源码包安装) 会有很多问题,不推荐


1、下载
    到官网下载mysql-5.1.65.tar.gz(注意是源码包)
2、解压
    tar -zxvf mysql-5.1.65.tar.gz
3、建立目标文件夹
    mkdir /usr/local/mysql
    也就是说等下安装的mysql要安装到这个文件夹里面
4、配置
    ./configure --prefix=/usr/local/mysql/ 

在./configure时出现错误:error: No curses/termcap library found

下载安装相应软件包

yum list|grep ncurses

yum -y install ncurses-devel

yum install ncurses-devel

5、编译
    make
6、安装
    make install

7、启动
    MySQL服务并不会自动启动,还需要先初始化MySQL数据库,操作如下:
    cd /usr/local/mysql/bin
    sudo ./mysql_install_db --user=root
    注意,这里最后的root是指可以操作数据库的用户,可以是当前用户,也可以新建用户,与linux上的root用户是两回事,可以自己取一个名字
    ./mysqld_safe --user=root & 这条命令负责启动mysql服务的守护进程,此外最后的&时必须的,因为希望守护进程在后台运行
    这里的root就是刚才的那个
8、为根用户创建密码
        ./mysqladmin -u root password ‘123456’
        如果root已经设置过密码,采用如下方法
        ./mysqladmin -u root password oldpass ‘123456’         
9、测试
    mysql -u root -p
    会提示输入密码,就用刚才设置的密码
    123456
    如果出现mysql>,说明连接成功了,下面通过命令 创建一个数据库、建一个表,增加一条记录,为后面的测试准备

   mysql> create database gywtest;
   mysql> use gywtest;

   mysql> create table student(id int(4) not null primary key auto_increment,stuname char(20));

   mysql> insert into student(stuname) values('Tom');

   注意每条命令后面有个分号,如果上面的都成功,后面就可以用这个测试。


四、将PHP与MySql结合起来

 1、重新配置PHP,改变配置选项,只需重复PHP安装时的最后的三步configure, make, 以及 make install,然后需要重新启动 Apache 使新模块生效,Apache不需要重新编译。

 2、配置

./configure --prefix=/usr/local/php  --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqli=/usr/local/mysql/bin/mysql_config  注意mysql_config 的路径
3、编译 make

4、安装 make installe

5、测试 写一个页面test.php,放在apache的web目录下,测试上面用命令创建的数据库

     <?php 
  $mysqli=new mysqli();
  $mysqli->connect('localhost','root','123456','gywtest');
   // 创建查询
   $sqlstr='select * from student';
  //发送查询给MySql
   $result=$mysqli->query($sqlstr);
    while($row=$result->fetch_object())
    { 
      $name=$row->stuname;
       echo $name;
    }
?>

Fatal error: Class 'mysqli' not found in /home/lufangtao/Project/DB.php on line 3

解决方法:

/usr/local/php/bin/phpize 这里回车运行

出错:

Cannot find config.m4. 
Make sure that you run './phpize' in the top level source directory of the module

解决方法:

PHP源码包文件夹下的EXT文件夹就是放置着目前版本的可用扩展,CD进去看看都有哪些你需要的?应该看到mysqli文件夹了吧~~~

在当前目录下执行phpize

[root@localhost mysqli]#/usr/local/php/bin/phpize

Configuring for:

PHP Api Version:                     20090626

Zend Modeule Api No:             20090626

Zend Extension Api No:           220090626

Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

解决方法:

yum install autoconf再次运行上面的命令即可。

[root@localhost mysqli]#./configure –prefix=/opt/mysqli –with-php-config=/opt/php/bin/php-config –with-mysqli=/opt/mysql/bin/mysql_config

[root@localhost mysqli]#make

[root@localhost mysqli]#make install

安装完成后会有提示扩展所在目录路径,如:

/opt/php/lib/php/extensions/no-debug-zts-20090626php

所需的mysqli.so便会在此目录下,接下来修改/opt/php/etc/下的php.ini文件,加入mysqli扩展,即加入如下一行:

extension=/opt/php/lib/php/extensions/no-debug-zts-20090626/mysqli.so

这里还是回出现错误:

参考博客http://www.cnblogs.com/wangtao_20/archive/2011/03/07/1973621.html

解决不用扩展连接MySQL的方法。

最终还是没有解决MySQLi连接的问题,但是可以使用MySQL数据库了,下面是测试程序

复制代码
<?php

$link=mysql_connect('localhost','root','123456');

if(!$link) echo "F!";

else echo "S!";

mysql_select_db("students") or die("Could not select database");
$query="SELECT * FROM student;";
$result=mysql_query($query) or die("Query failed");
print "<table>\n";

 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {        
print "\t<tr>\n";      
  foreach ($line as $col_value) {    
        print "\t\t<td>$col_value</td>\n";       
 }       
 print "\t</tr>\n";    }   
 print "</table>\n";



    /* 释放资源 */



mysql_free_result($result);
mysql_close();

?>
~       
复制代码

 






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值