安装 CakePHP

Installing CakePHP

我想按每个项目在我的 xampp 服务器上安装 CakePHP。 root/project1 root/project2

我想通过 localhost/project1、localhost/project2 访问它。 Project1 将是我的测试站点,另一个将用于发布。 这是一条错误消息 "project1Controller could not be found"

<VirtualHost *:80>
   ServerName localhost
   ServerAlias localhost/project1
   ServerAdmin admin@yahoo.com
   DocumentRoot "C:/root/cakephp/project1/app/webroot"
   <Directory />
      Options FollowSymLinks
      AllowOverride FileInfo
      Require all granted
   </Directory>
</VirtualHost>

<VirtualHost *:80>
   ServerName localhost
   ServerAlias localhost/project2
   ServerAdmin admin@yahoo.com
   DocumentRoot "C:/root/cakephp/project2/app/webroot"
   <Directory />
      Options FollowSymLinks
      AllowOverride FileInfo
      Require all granted
   </Directory>
</VirtualHost>

请指教。 谢谢

您的 DocumentRoot 不应该是 webroot 文件夹,它需要是整个 Cake 项目的根目录。尝试将其更改为:

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost/project1
  ServerAdmin admin@yahoo.com
  DocumentRoot "C:/root/cakephp/project1"
  <Directory />
     Options FollowSymLinks
     AllowOverride FileInfo
     Require all granted
  </Directory>
</VirtualHost>

Cake 的 .htaccess 和前端控制器将为您处理路由。您无需尝试直接访问 webroot。

在我放弃并改用 Hiawatha 之前,我在配置 Apache 时遇到了同样的问题,它配置起来容易得多,而且根据一些基准测试,它比 Apache 更快。

这是我关于如何使用 Hiawatha-PHP-MariaDB:

设置服务器的收据
  1. 安装 MariaDB

    sudo yum -y install mariadb mariadb-server
    sudo systemctl start mariadb.service
    sudo systemctl enable mariadb.service
    
  2. 配置mysql:

    sudo mysql_secure_installation
    
  3. 安装 Hiawatha:

    sudo yum install yum-utils
    sudo yum-config-manager --add-repo http://repo.hiawatha.be 
    sudo rpm --import http://repo.hiawatha.be/pubkey 
    sudo yum install hiawatha
    sudo systemctl enable hiawatha.service
    
  4. 安装php5-fpm:

    sudo yum -y install php-fpm php-mysql php-cli
    sudo nano /etc/php.ini
    
  5. 设置这个参数:cgi.fix_pathinfo = 0

  6. 删除评论:

    #pm.min_spare_servers = 5 
    #pm.max_spare_servers = 35
    
  7. 重启php-fpm:

    systemctl restart php-fpm.service
    

这里是 /etc/hiawatha/hiawatha.conf 文件:

ServerId = www-data
ConnectionsTotal = 1000
ConnectionsPerIP = 25
SystemLogfile = /var/log/hiawatha/system.log
GarbageLogfile = /var/log/hiawatha/garbage.log
Binding {
        Port = 80
}
Binding {
        Port = 443
        SSLcertFile = /etc/hiawatha/serverkey.pem
}

CGIhandler = /usr/bin/php5-cgi:php,php5

FastCGIserver {
        FastCGIid = PHP5
        ConnectTo = 127.0.0.1:9000
        Extension = php
}

UrlToolkit {
   ToolkitID = cakephp
   RequestURI exists Return
   Match .* Rewrite /index.php
}

Hostname = serverIpAddress
WebsiteRoot = /var/www
StartFile = index.html
AccessLogfile = /var/log/hiawatha/access.log
ErrorLogfile = /var/log/hiawatha/error.log
UseFastCGI = PHP5

VirtualHost {
        Hostname = www.example.com
        WebsiteRoot = /var/www/example.com
        StartFile = index.php
        AccessLogfile = /var/www/example.com/access.log
        ErrorLogfile =  /var/www/example/error.log
        RequireSSL = yes
        TimeForCGI = 5
        UseFastCGI = PHP5
        UseToolkit = cakephp
}
VirtualHost {
        Hostname = host2.example.com
        WebsiteRoot = /var/www/anotherexample
        StartFile = index.php
        AccessLogfile = /var/www/anotherexample/logs/access.log
        ErrorLogfile =  /var/www/anotherexample/logs/error.log
        RequireSSL = yes
        TimeForCGI = 5
        UseFastCGI = PHP5
        UseToolkit = cakephp
}

对于新版本(Cakephp 3.x)你只能使用

打开命令提示符并转到您的项目目录。在这个 运行 这个命令之后

bin\cake server

当您的命令执行时,您的默认服务器将是 localhost:8765