Home  >  Article  >  Backend Development  >  Configure Apache2.2+PHP5+CakePHP1.2+MySQL5 operating environment_PHP tutorial

Configure Apache2.2+PHP5+CakePHP1.2+MySQL5 operating environment_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:47:15813browse

1. 安装配置Apahce

  安装配置Apache是比较简单的, 跟着安装向导一步步往下走就能搞定。最多就是在配置端口的地方需要注意一下,如果已经安装了其它Web服务器占用了80端口,那记得配置的时候选一个别的端口。向导中忘了设置,在Apache的conf/httpd.conf中修改下面这句就好:

Listen 127.0.0.1:80

2. 安装配置PHP5

  PHP5也是一路安装就完了。要让Apache能解释PHP页面,继续修改Apache的conf/httpd.conf文件。 首先,假设PHP5是安装在D:\php5目录。

  首先是要在Apache中载入PHP5的模块,加下面这句:

LoadModule php5_module d:/php5/php5apache2_2.dll

  然后是让Apache认识PHP页面的Mime,找到块,在这个块里加一句AddType语句:

mime_module>
    ...
    AddType application/x-httpd-php .php
    ...

  最后还要把index.php设置成默认页面,这样在浏览时没指定页面的情况下会自动找到index.php。找到块,修改里面的DirectoryIndex配置:

dir_module>
    DirectoryIndex index.html index.htm index.php

  这里要注意默认页面的顺序,按上面的配置,如果一个目录下同时存在index.html和index.php的情况下,会优先找到并打开index.html。

  最后还要让Apache能找到PHP的配置。一般说法是把php.ini拷贝到Windows目录下,但是我宁愿在Apache中配置这个位置: 

php5_module>
    PHPIniDir d:/php5/php.ini

  好了,现在PHP应该配置完了,写个最简单的PHP试试看——启动或重启Apache服务器,在Apache的htdocs目录下去新建个phpinfo.php文件(如果修改了DocumentRoot,就根据修改后的DocumentRoot决定位置),内容如下:


phpinfo();
?>

  现在打开浏览器看看http://localhost/phpinfo.php(非默认端口记得写端口号),看看效果。

3. 安装配置CakePHP

  所谓安装,其实就是解压而已。先把CakePHP解压到D:\cakephp,那么CakePHP解压出来的目录结构大概是这个样子:

D:\CakePHP
│  .htaccess
│  index.php
│  README
├──app
│  └──webroot
├──cake
└──vendors

  从Google上的各种资料来查看,Web应用的大概有三种配置方式,连介绍的顺序都没变过。其中第二种,也就是不改变CakePHP的目录结构,也有一定安全性的一种,我觉得还不错,采用了。

  先要把CakePHP下面的app/webroot目录设置成Apache的DocumentRoot;然后要打开rewrite模块(去掉注释符号);还要配置DocumentRoot目录的AllowOverride属性改为All。那么要修改Apache的配置文件的下面这些内容:

...
LoadModule rewrite_module modules/mod_rewrite.so
...
DocumentRoot "D:/cakephp/app/webroot"
...
"D:/cakephp/app/webroot">
    AllowOverride All   

...

  然后再次重启Apache,访问http://localhost/试试,这时候应该能显示CakePHP的一些信息了。

  如果配置CakePHP的时候采用的高级配置,在试运行的时候可能会遇到页面上有如下这样的警告:

Warning (512): Cache not configured properly. ...
Warning (2): array_merge() [function.array-merge]: ...
Warning (2): array_merge() [function.array-merge]: ...

  遇到这个问题我真是头大,查了半天资料,结果在几乎绝望的时候,不知道在哪里看到一则信息,说是要让APP下的tmp/cache/persistent目录有写权限。查看了一下,原来tmp并不存在cache目录,所以自己创建了cache/persistent目录。如果在在Linux目录下,还要给这个目录777权限。

4. 安装配置MySQL

  MySQL的安装也很简单,安装完之后也有向导配置一些东西。这些都是数据库上的事情,根据向导一步步操作就好。关键是要让PHP和CakePHP能使用MySQL数据库。

  关于PHP中的配置,直接修改php.ini,把extension=php_mysql.dll前面的注释符号去掉,也就是

...
extension=php_mysql.dll
...

Then copy the phpinfo.php you just wrote to CakePHP’s app/webroot, and browse http://localhost/phpinfo.php again to see if there is any MySQL configuration on the page. Information—probably none. Because I haven't done enough things - I'm very depressed, and it took me half a day here.

There are a lot of DLLs in the PHP5 directory. Copy these DLLs directly to Apache's bin directory (if your PHP5 directory is in PATH, you may not need to bother so much). Take a look now. There should be MySQL configuration information on the page.

The configuration of CakePHP is in config/database.php in the app directory. Didn't you find this file? Did you see a database.php.default? Just make a copy of it and rename it database.php. Then of course you have to change something.

There is only one DATABASE_CONFIG class in this configuration, which has a $default variable, which saves the configuration information of the default database. The configuration is almost like this:

var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'your-username',
'password' => 'your-password',
'database' => 'your-database',
'prefix' => '',
);

Note that login, password and database are configured according to the actual situation. After the configuration is completed, browse http://localhost/. There should be a sentence "Your database configuration file is present." on this page. If your database is ready, you will see "Cake is able to connect to the database."; if not, you may see some warning or error messages.

Summary

This configuration is really tiring. Who is interested in making a complete installation package? It will be automatically configured according to the installation location. How great! Or it would be good to make a GUI or Web interface configuration program.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319978.htmlTechArticle1. Install and configure Apache. Installing and configuring Apache is relatively simple. Just follow the installation wizard step by step and you can get it done. . The most you need to pay attention to is where you configure the port. If you have...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn