简体   繁体   English

如何使用多个 xampp 像 xampp php 版本 5、xampp php 版本 7、版本 8。我也安装它但问题新 laravel 项目 npm 未安装

[英]How to use Multiple xampp Like xampp php version 5, xampp php version 7, version 8. I also install it but problem new laravel project npm not install

when i run xampp php version 7 all are good but when i run xampp php version 8 but my current project not work this is my laravel 9 xampp php version 8 current project当我运行 xampp php 版本 7 时一切都很好但是当我运行 xampp php 版本 8 但我当前的项目不起作用这是我的 laravel 9 xampp php 版本 8 当前项目

and another problem when i run new project and install npm install && npm run dev but it's not work npm install and when I run npm run dev this result npm run dev还有另一个问题,当我运行新项目并安装 npm install && npm run dev 但它不起作用npm install并且当我运行 npm run dev 这个结果npm run dev

and when I run php artisan migrate and serve after then login url当我运行 php artisan migrate 并在登录 url之后服务

Why switch between PHP versions when you can use multiple PHP versions at the same time with a single xampp installation ?当您可以通过单个 xampp 安装同时使用多个 PHP 版本时,为什么要在 PHP 版本之间切换?

With a single xampp installation, you have 2 options:使用单个 xampp 安装,您有 2 个选项:

  1. Run an older PHP version for only the directory of your old project: This will serve the purpose most of the time.仅为旧项目的目录运行较旧的 PHP 版本:这将在大多数情况下达到目的。 You may have one or two old projects that you intend to run with an older PHP version.您可能有一个或两个旧项目打算使用较旧的 PHP 版本运行。 Just configure xampp to run an older PHP version for only those project directories.只需将 xampp 配置为仅针对这些项目目录运行较旧的 PHP 版本。

  2. Run an older PHP version on a separate port of xampp: Sometimes you may be upgrading an old project to the latest PHP version and at the same time you need to run the same project back and forth between the new PHP version and the old PHP version.在单独的 xampp 端口上运行较旧的 PHP 版本:有时您可能正在将旧项目升级到最新的 PHP 版本,同时您需要在新的 PHP 版本和旧的 PHP 版本之间来回运行相同的项目. To do this you can set an older PHP version on a different port (say 8056) so when you go to http://localhost/any_project/ , xampp runs PHP 7 and when you go to http://localhost:8056/any_project/ xampp runs PHP 5.6.为此,您可以在不同的端口(例如 8056)上设置较旧的 PHP 版本,因此当您访问http://localhost/any_project/时,xampp 运行 PHP 7,而当您访问http://localhost:8056/any_project/ xampp 运行 PHP 5.6。

  3. Run an older PHP version on a virtualhost: You can create a virtualhost like localhost56 to run PHP 5.6 while you can use PHP 7 on localhost.在虚拟主机上运行较旧的 PHP 版本:您可以创建一个像 localhost56 这样的虚拟主机来运行 PHP 5.6,而您可以在 localhost 上使用 PHP 7。

Lets set it up让我们设置它

Step 1: Download PHP第 1 步:下载 PHP

So you have PHP 7 running under xampp, you want to add an older PHP version to it (say PHP 5.6).所以你有 PHP 7 在 xampp 下运行,你想向它添加一个旧的 PHP 版本(比如 PHP 5.6)。 Download the nts (Non Thread Safe) version of the PHP zip archive from php.net (see archive for older versions) and extract the files under c:\xampp\php56 .php.net下载 nts(非线程安全)版本的 PHP zip 存档(请参阅旧版本的存档)并解压缩c:\xampp\php56下的文件。 The thread safe version does not include php-cgi.exe.线程安全版本不包括 php-cgi.exe。

Step 2: Configure php.ini第二步:配置php.ini

Open the file c:\xampp\php56\php.ini in notepad.在记事本中打开文件c:\xampp\php56\php.ini If the file does not exist, copy php.ini-development to php.ini and open it in notepad.如果该文件不存在,请将php.ini-development复制到php.ini并在记事本中打开。 Then uncomment the following line:然后取消注释以下行:

extension_dir = "ext"

Also if the following line exists in Apache config httpd-xampp.conf此外,如果 Apache config httpd-xampp.conf中存在以下行

SetEnv PHPRC "\\path\\to\\xampp\\php"

comment it out with with a leading # (hash character).使用前导 #(哈希字符)将其注释掉。

Step 3: Configure apache第 3 步:配置 Apache

Open xampp control panel, click the config button for apache, and click Apache (httpd-xampp.conf) .打开 xampp 控制面板,单击 apache 的配置按钮,然后单击Apache (httpd-xampp.conf) A text file will open.将打开一个文本文件。 Put the following settings at the bottom of the file:将以下设置放在文件底部:

ScriptAlias /php56 "C:/xampp/php56"
Action application/x-httpd-php56-cgi /php56/php-cgi.exe
<Directory "C:/xampp/php56">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
        Require all granted
    </Files>
</Directory>

Note: You can add more versions of PHP to your xampp installation following step 1 to 3 if you want.注意:如果需要,您可以按照步骤 1 到 3 将更多版本的 PHP 添加到您的 xampp 安装中。

Step 4 (option 1): [Add Directories to run a specific PHP version]第 4 步(选项 1): [添加目录以运行特定的 PHP 版本]

Now you can set directories that will run in PHP 5.6.现在您可以设置将在 PHP 5.6 中运行的目录。 Just add the following at the bottom of the config file ( httpd-xampp.conf from Step 3) to set directories.只需在配置文件(步骤 3 中的httpd-xampp.conf )底部添加以下内容即可设置目录。

<Directory "C:\xampp\htdocs\my_old_project1">
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</Directory>

<Directory "C:\xampp\htdocs\my_old_project2">
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</Directory>

Step 4 (option 2): [Run an older PHP version on a separate port]第 4 步(选项 2): [在单独的端口上运行较旧的 PHP 版本]

Now to to set PHP v5.6 on port 8056, add the following code to the bottom of the config file ( httpd-xampp.conf from Step 3).现在要在端口 8056 上设置 PHP v5.6,请将以下代码添加到配置文件的底部(步骤 3 中的httpd-xampp.conf )。

Listen 8056
<VirtualHost *:8056>
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</VirtualHost>

Step 4 (option 3): [Run an older PHP version on a virtualhost]第 4 步(选项 3): [在虚拟主机上运行较旧的 PHP 版本]

To create a virtualhost (localhost56) on a directory (htdocs56) to use PHP v5.6 on http://localhost56, create directory htdocs56 at your desired location and add localhost56 to your hosts file ( see how ), then add the following code to the bottom of the config file ( httpd-xampp.conf from Step 3).要在目录 (htdocs56) 上创建虚拟主机 (localhost56) 以在 http://localhost56 上使用 PHP v5.6,请在所需位置创建目录 htdocs56 并将 localhost56 添加到主机文件(请参阅如何),然后添加以下代码到配置文件的底部(步骤 3 中的httpd-xampp.conf )。

<VirtualHost localhost56:80>
    DocumentRoot "C:\xampp\htdocs56"
    ServerName localhost56
    <Directory "C:\xampp\htdocs56">
        Require all granted    
    </Directory>
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
</VirtualHost>

Finish: Save and Restart Apache完成:保存并重新启动 Apache

Save and close the config file.保存并关闭配置文件。 Restart apache from the xampp control panel.从 xampp 控制面板重新启动 apache。 If you went for option 2, you can see the additional port(8056) listed in your xampp control panel.如果您选择选项 2,您可以在 xampp 控制面板中看到额外的端口(8056)。

xampp 控制面板显示使用配置的端口运行的 apache

For more information, take a look at this thread: Is there way to use two PHP versions in XAMPP?有关更多信息,请查看此线程: Is there way to use two PHP versions in XAMPP?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM