Home> PHP Framework> Laravel> body text

Detailed explanation of how to configure and run the Flarum forum system in the Mac development environment Laravel Valet

藏色散人
Release: 2020-04-28 15:03:50
forward
2008 people have browsed it

The following tutorial column will introduce you to the implementation method of configuring and running the Flarum forum system in the Mac development environment Laravel Valet. I hope it will be helpful to friends in need!

Laravel Valet is a minimalist development environment provided for Mac OS X. However, the configuration of Valet is somewhat different from traditional HTTP servers (Apache, Nginx, etc.). To rewrite URLs in configuration files, Valet defines URL handling in a modular way in PHP classes. Since the default directory structures of Flarum and Laravel are different, we need to define its access configuration in Valet.

Detailed explanation of how to configure and run the Flarum forum system in the Mac development environment Laravel ValetThere is a default configuration file SampleValetDriver.php in the ~/.valet/Drivers directory, which contains three methods: serves, isStaticFile and frontControllerPath. We now need to configure our own configuration file FlarumValetDriver.php, and follow these three methods to write our own driver extension:

cp SampleValetDriver.php FlarumValetDriver.php
Copy after login

Open FlarumValetDriver.php, first rewrite the serves method, in which we need to specify Valet Check whether the corresponding Flarum application directory under the Web root directory (mine here is flarum, if it is different, you need to change it to your own Flarum application directory) exists. This is somewhat similar to defining root in Nginx:

public function serves($sitePath, $siteName, $uri){ return is_dir($sitePath.'/vendor/flarum') && file_exists($sitePath.'/flarum'); }
Copy after login

Next, in The isStaticFile method determines whether the given URL points to a static file and the static file does exist. This is similar to how we define static file access in nginx:

public function isStaticFile($sitePath, $siteName, $uri){ if ($this->isActualFile($staticFilePath = $sitePath.$uri)) { return $staticFilePath; } return false; }
Copy after login

Finally rewrite the frontControllerPath method, which is similar to mod_rewrite in Apache And try_uri in Nginx, here we can rewrite the request access path:

public function frontControllerPath($sitePath, $siteName, $uri) { if (strpos($uri,'/admin') === 0) { return $sitePath.'/admin.php'; } if (strpos($uri,'/api') === 0) { return $sitePath.'/api.php'; } return $sitePath.'/index.php'; }
Copy after login

The final result is as follows, we save it under ~/.valet/Drivers:

isActualFile($staticFilePath = $sitePath.$uri)) { return $staticFilePath; } return false; } /** * Get the fully resolved path to the application's front controller. * * @param string $sitePath * @param string $siteName * @param string $uri * * @return string */ public function frontControllerPath($sitePath, $siteName, $uri) { if (strpos($uri,'/admin') === 0) { return $sitePath.'/admin.php'; } if (strpos($uri,'/api') === 0) { return $sitePath.'/api.php'; } return $sitePath.'/index.php'; } }
Copy after login

This way You can now access all Falrum routes normally. If an access error is reported:

Call to undefined method FlarumValetDriver::isActualFile() in /Users/sunqiang/.valet/Drivers/FlarumValetDriver.php on line 29
Copy after login

This is because Valet has not been upgraded to the latest version. Just execute the following command to upgrade Valet:

composer global update
Copy after login

Original address: https://xueyuanjun.com/ post/5679

The above is the detailed content of Detailed explanation of how to configure and run the Flarum forum system in the Mac development environment Laravel Valet. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:xueyuanjun.com
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!