Skip to content

Commit

Permalink
Fixes #153: support for MeCab on Mac.
Browse files Browse the repository at this point in the history
Error documentation was also added.
  • Loading branch information
HugoFara committed Jan 2, 2024
1 parent b01b61b commit c2cb13b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 17 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ ones are marked like "v1.0.0-fork".

### Added

* Support for Japanese with MeCab on Mac! This was added thanks to
[quopquai](https://github.com/quopquai) on [#135](https://github.com/HugoFara/lwt/issues/135).
* `unloadformcheck.js` now declares a new object `lwt_form_check` that contains all the functions needed.
* New globals ([#163](https://github.com/HugoFara/lwt/issues/163)):
* On `inc/kernel_utility.php`: `LWT_APP_VERSION` and `LWT_RELEASE_DATE`.
Expand Down
40 changes: 34 additions & 6 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,61 @@ If you see "The webpage is not available", "We have trouble finding that site".

![Image](../img/prob1.png)

Answer: Your local webserver (Apache) is not running. Please start it via EasyPHP or MAMP control program/panel.
Answer: Your local webserver (Apache) is not running.
Please start it via EasyPHP or MAMP control program/panel.

## Blank page

You PHP version is probably too low. Try to use PHP 8 at least.

## URL not found (404)

![Image](../img/prob2.png)

Answer: The server is running, but the application is not found. Maybe the Uniform Resource Identifier (URI) is wrong or misspelled. Please check/correct it. Or the URI is correct, and the application is installed, but not in the correct directory _lwt_ below _htdocs_. Please install/copy/move it into the correct directory.
Answer: The server is running, but the application is not found.
Maybe the Uniform Resource Identifier (URI) is wrong or misspelled.
Please check/correct it. Or the URI is correct, and the application is installed,
but not in the correct directory _lwt_ below _htdocs_.
Please install/copy/move it into the correct directory.

## Database connection error

![Image](../img/prob3.png)

Answer: Either the database (MySQL) is not running, or the database connection parameters in _../htlwt/connect.inc.php_ are wrong. Please check/correct the database connection parameters and/or start MySQL via the MAMP or EasyPHP control program/panel.
Answer: Either the database (MySQL) is not running, or the database connection
parameters in _../htlwt/connect.inc.php_ are wrong.
Please check/correct the database connection parameters and/or start MySQL via the MAMP or EasyPHP control program/panel.

## Cannot find connect.inc.php

![Image](../img/prob4.png)

Answer: The Webserver and the database is running, but the database connection parameter file _../htlwt/connect.inc.php_ is not found. Please rename one of the connection files (according to your server) to _../htlwt/connect.inc.php_.
Answer: The Webserver and the database is running, but the database connection parameter file _../htlwt/connect.inc.php_ is not found.
Please rename one of the connection files (according to your server) to _../htlwt/connect.inc.php_.

## Do not run on Linux after installation/update

If LWT installed or updated LWT on Linux, but the application does not run as expected.

Answer 1: The Webserver does not have full access to all LWT files (insufficient rights). Open a terminal window, go to the directory where the directory "lwt" has been created with all LWT files, e. g.
Answer 1: The Webserver does not have full access to all LWT files (insufficient rights).
Open a terminal window, go to the directory where the directory "lwt" has been created with all LWT files, e. g.
**cd /var/www/html**
Now execute:
**sudo chmod -R 755 lwt**.

Answer 2: The PHP "mbstring" extension is not installed. Please install it: [see this article](https://askubuntu.com/questions/491629/how-to-install-php-mbstring-extension-in-ubuntu).
Answer 2: The PHP "mbstring" extension is not installed.
Please install it: [see this article](https://askubuntu.com/questions/491629/how-to-install-php-mbstring-extension-in-ubuntu).

## MeCab not detected!

LWT cannot find MeCab, you can do the following steps:


On Linux or Mac:
1. Open a terminal.
2. Type `mecab -v` to get the current MeCab version. If nothing is displayed MeCab is not installed.
3. If MeCab is already installed, the path may be missing. If you are using MAMP type

```bash
printf 'export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"' >> /Applications/MAMP/Library/bin/envvars
```
36 changes: 30 additions & 6 deletions docs/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -1166,23 +1166,45 @@ <h2 id="faq" name="faq">▶ Questions and Answers - <a href="#">[↑]</a></h2>
<h3>Site Unreachable</h3>
<p>If you see "The webpage is not available", "We have trouble finding that site".</p>
<p><img src="../img/prob1.png" alt="Image"></p>
<p>Answer: Your local webserver (Apache) is not running. Please start it via EasyPHP or MAMP control program/panel.</p>
<p>Answer: Your local webserver (Apache) is not running.
Please start it via EasyPHP or MAMP control program/panel.</p>
<h3>Blank page</h3>
<p>You PHP version is probably too low. Try to use PHP 8 at least.</p>
<h3>URL not found (404)</h3>
<p><img src="../img/prob2.png" alt="Image"></p>
<p>Answer: The server is running, but the application is not found. Maybe the Uniform Resource Identifier (URI) is wrong or misspelled. Please check/correct it. Or the URI is correct, and the application is installed, but not in the correct directory <em>lwt</em> below <em>htdocs</em>. Please install/copy/move it into the correct directory.</p>
<p>Answer: The server is running, but the application is not found.
Maybe the Uniform Resource Identifier (URI) is wrong or misspelled.
Please check/correct it. Or the URI is correct, and the application is installed,
but not in the correct directory <em>lwt</em> below <em>htdocs</em>.
Please install/copy/move it into the correct directory.</p>
<h3>Database connection error</h3>
<p><img src="../img/prob3.png" alt="Image"></p>
<p>Answer: Either the database (MySQL) is not running, or the database connection parameters in <em>../htlwt/connect.inc.php</em> are wrong. Please check/correct the database connection parameters and/or start MySQL via the MAMP or EasyPHP control program/panel.</p>
<p>Answer: Either the database (MySQL) is not running, or the database connection
parameters in <em>../htlwt/connect.inc.php</em> are wrong.
Please check/correct the database connection parameters and/or start MySQL via the MAMP or EasyPHP control program/panel.</p>
<h3>Cannot find connect.inc.php</h3>
<p><img src="../img/prob4.png" alt="Image"></p>
<p>Answer: The Webserver and the database is running, but the database connection parameter file <em>../htlwt/connect.inc.php</em> is not found. Please rename one of the connection files (according to your server) to <em>../htlwt/connect.inc.php</em>.</p>
<p>Answer: The Webserver and the database is running, but the database connection parameter file <em>../htlwt/connect.inc.php</em> is not found.
Please rename one of the connection files (according to your server) to <em>../htlwt/connect.inc.php</em>.</p>
<h3>Do not run on Linux after installation/update</h3>
<p>If LWT installed or updated LWT on Linux, but the application does not run as expected.</p>
<p>Answer 1: The Webserver does not have full access to all LWT files (insufficient rights). Open a terminal window, go to the directory where the directory "lwt" has been created with all LWT files, e. g.<br>
<p>Answer 1: The Webserver does not have full access to all LWT files (insufficient rights).
Open a terminal window, go to the directory where the directory "lwt" has been created with all LWT files, e. g.<br>
<strong>cd /var/www/html</strong><br>
Now execute:
<strong>sudo chmod -R 755 lwt</strong>.</p>
<p>Answer 2: The PHP "mbstring" extension is not installed. Please install it: <a href="https://askubuntu.com/questions/491629/how-to-install-php-mbstring-extension-in-ubuntu">see this article</a>.</p>
<p>Answer 2: The PHP "mbstring" extension is not installed.
Please install it: <a href="https://askubuntu.com/questions/491629/how-to-install-php-mbstring-extension-in-ubuntu">see this article</a>.</p>
<h3>MeCab not detected!</h3>
<p>LWT cannot find MeCab, you can do the following steps:</p>
<p>On Linux or Mac:</p>
<ol>
<li>Open a terminal.</li>
<li>Type <code>mecab -v</code> to get the current MeCab version. If nothing is displayed MeCab is not installed.</li>
<li>If MeCab is already installed, the path may be missing. If you are using MAMP type</li>
</ol>
<pre><code class="language-bash">printf 'export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"' &gt;&gt; /Applications/MAMP/Library/bin/envvars
</code></pre>

<h2 id="ipad" name="ipad">▶ Setup for Tablets - <a href="#">[↑]</a></h2>
<blockquote>
Expand Down Expand Up @@ -2197,6 +2219,8 @@ <h2 id="CHANGELOG" name="CHANGELOG">▶ Changelog - <a href="#">[↑]</a></h2>
<h3>[Unreleased]</h3>
<h4>Added</h4>
<ul>
<li>Support for Japanese with MeCab on Mac! This was added thanks to
<a href="https://github.com/quopquai">quopquai</a> on <a href="https://github.com/HugoFara/lwt/issues/135">#135</a>.</li>
<li>
<code>unloadformcheck.js</code> now declares a new object <code>lwt_form_check</code> that contains all the functions needed.</li>
<li>New globals (<a href="https://github.com/HugoFara/lwt/issues/163">#163</a>):
Expand Down
17 changes: 12 additions & 5 deletions inc/kernel_utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,22 @@ function remove_spaces($s, $remove)
* @return string OS-compatible command
*
* @since 2.3.1-fork Much more verifications added
* @since 2.10.0-fork Support for Mac OS added
*/
function get_mecab_path($mecab_args = ''): string
{
$os = strtoupper(substr(PHP_OS, 0, 3));
$os = strtoupper(PHP_OS);
$mecab_args = escapeshellcmd($mecab_args);
if ($os == 'LIN') {
if (str_starts_with($os, 'LIN') || str_starts_with($os, 'DAR')) {
if (shell_exec("command -v mecab")) {
return 'mecab' . $mecab_args;
}
my_die("MeCab not detected! Please install it and add it to your PATH.");
my_die(
"MeCab not detected! " .
"Please install it or add it to your PATH (see documentation)."
);
}
if ($os == 'WIN') {
if (str_starts_with($os, 'WIN')) {
if (shell_exec('where /R "%ProgramFiles%\\MeCab\\bin" mecab.exe')) {
return '"%ProgramFiles%\\MeCab\\bin\\mecab.exe"' . $mecab_args;
}
Expand All @@ -279,7 +283,10 @@ function get_mecab_path($mecab_args = ''): string
if (shell_exec('where mecab.exe')) {
return 'mecab.exe' . $mecab_args;
}
my_die("MeCab not detected! Install it or add it to the PATH.");
my_die(
"MeCab not detected! " .
"Install it or add it to the PATH (see documentation)."
);
}
my_die("Your OS '$os' cannot use MeCab with this version of LWT!");
}
Expand Down

0 comments on commit c2cb13b

Please sign in to comment.