[php] [xampp] xampp php 버전  폴더 (디렉토리) 별 설정 : Running multiple PHP versions on XAMPP

Running multiple PHP versions on XAMPP

So recently I had to reinstall XAMPP, which includes Apache, MySQL and PHP. In my case, I develop on a Windows 10 system using VS Code. If you’re new to web development, XAMPP is a handy little tool to set up a local web server (and database, etc.) for web development.

It’s very much a development server though, and not something that should be run for a production site. Possibly something I’ll cover in another blog post.

When I reinstalled XAMPP it came with PHP 8, the latest version in the PHP family. It has quite a few changes since PHP 7 which can cause some issues with existing sites. This is why it’s handy to have a few PHP versions running side-by-side. Although if my experience has taught me anything, it’s that it’s a pain in the backside to set up (took a bit of trial and error).

Some web hosts offer this with an easy to change setting. XAMPP, however, doesn’t have a setting for this, so it requires a bit of manual work. There’s also a small catch, which I’ll cover below.

We’re going to be working towards 2 versions of PHP installed, in my case PHP 8.0.3 and PHP 7.4.16 with XAMPP, which is configured on a per-directory basis.

Your folder structure

I’m going to assume you’ve already downloaded and installed XAMPP into the typical directory C:\xampp. Everything I’ll refer to will be in reference to this directory, but I’ll try and make it as straightforward as possible because I don’t believe in making life difficult!

So, your XAMPP folder should contain the default folders – apache, htdocs, php, tmp – and a load of other bits and pieces.

Setting up support for multiple PHP versions

Step 1 – Download your new version of PHP

As mentioned above, I use Windows 10. If you use something different, your files may need to be slightly different.

I’m going to install PHP 7.4.16 to go alongside my PHP 8.0, so I can still work on older sites and upgrade them bit by bit to support PHP 8. We’ll need the NTS version (non-thread safe), which can be downloaded from the PHP website, or the archive (if it’s an older version you’re after).

image.png

 

 

Step 2 – Extract the files to your XAMPP folder

Once your download is complete, we’ll need to extract all of the files to your XAMPP folder.

It would be good practice to put it in a folder matching the PHP version, so in my case, I’ll extract it to php74 in C:\xampp\

image-1.png

 

 

Step 3 – Download Fast CGI

The caveat I mentioned above… here it is.

Apache in itself can’t run multiple versions of PHP. So, what we’re going to do is update it to use Fast CGI. It has its advantages and disadvantages, but in this case, it’s needed. As we’re only using it for local development, the negatives shouldn’t be overly noticeable.

The one thing you need to know at this stage is what version of XAMPP you have – 32-bit or 64-bit. Most modern systems will be running 64-bit. If you don’t know, you need to run a simple PHP script, which will output all the info needed. In fact, it’s a good idea to do this, so we can check it all later on too.

<?php

phpinfo();

This will list everything about your PHP setup, including the “architecture” line, which will show x64 for 64-bit, or x86 for 32-bit.

Also note the Server API value. In my case, it’s Apache 2.0 Handler. This is the part we’re replacing with Fast CGI.

image-2.png

 

Now we have this information to hand, go to the Apache Lounge to download Fast CGI.

The files of interest are the mod_fcgid files, either the win64 or win32 version (which depends on the version of XAMPP you are running based on the architecture above). Based on my architecture above, I’m going to download mod_fcgid-2.3.10-win64-VS16.zip

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

image-3.png

 

Step 4- Install Fast CGI

Once you have this, copy of mod_fcgid.so file from the ZIP file to your Apache\modules directory, e.g. C:\xampp\apache\modules.

If Apache is running in XAMPP, you can stop it here, ready to make some changes to the configuration. This can be accessed by clicking on Config and selecting httpd-xampp.conf in the XAMPP control panel

image-4.png

 

 

We’ll need to find the lines similar to the below, which we’re going to replace.

#
# PHP-Module setup
#
LoadFile "C:/xampp/php/php8ts.dll"
LoadFile "C:/xampp/php/libpq.dll"
LoadModule php_module "C:/xampp/php/php8apache2_4.dll"

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

Replace this with:

#
# PHP-Module setup
#
LoadFile "C:/xampp/php/php7ts.dll"
LoadFile "C:/xampp/php/libpq.dll"

LoadModule fcgid_module modules/mod_fcgid.so

<IfModule fcgid_module>
	FcgidInitialEnv PATH "C:/xampp/php"
	FcgidInitialEnv SystemRoot "C:/Windows"
	FcgidInitialEnv SystemDrive "C:"
	FcgidInitialEnv TEMP "C:/xampp/tmp"
	FcgidInitialEnv TMP "C:/xampp/tmp"
	FcgidInitialEnv windir "C:/windows"
	FcgidIOTimeout 64
	FcgidConnectTimeout 16
	FcgidMaxRequestsPerProcess 1000 
	FcgidMaxProcesses 3
	FcgidMaxRequestLen 8131072
	# Location php.ini:
	FcgidInitialEnv PHPRC "C:/xampp/php"
	FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

	<Files ~ "\.php$">
		Options Indexes FollowSymLinks ExecCGI 
		AddHandler fcgid-script .php
		FcgidWrapper "C:/xampp/php/php-cgi.exe" .php
	</Files>
</IfModule>

We’ll also need to update the PHPMyAdmin section to prevent any issues later on.

    Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
    <Directory "C:/xampp/phpMyAdmin">

        # add this option allow FastCGI
        Options ExecCGI

        AllowOverride AuthConfig
        Require local
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </Directory>

Re-run the phpinfo() script we created earlier, and you should now see a small change. The Server API should now show FastCGI.

image-5.png

 

Don’t close this config file just yet…

Step 5 – Updating XAMPP Config

Now that’s installed, we can run multiple PHP versions! ???? We’re not done yet though. We may have 2 versions of PHP installed, but nothing says what we want to use and where.

Our next step is to set this up. Using the config file we just edited above (if you’ve closed it, it’s the httpd-xampp.conf file), add the below lines to bottom of the file:

# PHP 7.4
ScriptAlias /php74 "C:/xampp/php74"
Action application/x-httpd-php74-cgi /php74/php-cgi.exe
SetEnv PHPRC "\xampp\php74"
<Directory "C:/xampp/php74">
    AllowOverride None
    Options None
    Require all denied
    <Files "php-cgi.exe">
        Require all granted
    </Files>
</Directory>

This now adds support for PHP 7.4 in my case. And while this enables it, it still doesn’t set up a project to use it. So one last thing…

Step 6 – Change the PHP version of a project

If you have a set up like me, you have various projects set up in your vhosts file. This can be found by going to Config Browse apache from your XAMPP control panel, and then going to conf extra > httpd-vhosts.conf.

You may already have some data here, but if not, you can add a blanket cover, or tweak it, to work with your set up.

<VirtualHost mywebsite.local:8080>

    DocumentRoot "C:\websites\mywebsite\public_html"

    <Directory "C:\websites\mywebsite\public_html">
        #Allow from all
        Require all granted
        #Options Indexes
        AllowOverride All
		<FilesMatch "\.php$">
			SetHandler application/x-httpd-php74-cgi
		</FilesMatch>
    </Directory>

</VirtualHost>

What this does, is directs any traffic to the website mywebsite.local on port 8080 (which is the port my XAMPP runs on, it’s set to 80 by default), to the files in C:\websites\mywebsite\public_html.

But the key line here in this case is the one matching any PHP files, and saying “use PHP74”, which we set before.

Finally…

And finally, restart Apache in the XAMPP control panel, if you haven’t already done so.

You can try accessing the same phpinfo() file we created earlier on if you want to give it a test, and this should now reflect the new PHP version.

[출처] https://mathewparker.co.uk/2021/04/running-multiple-php-versions-on-xampp/

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
158 [php 응용개발] XE 템플릿 문법 file 졸리운_곰 2025.05.16 90
157 [php] PHP 보안강화 하기 졸리운_곰 2025.04.27 58
156 [php] php 와 javascript 차이 & 상호 간의 호출 방법 file 졸리운_곰 2024.08.13 99
155 [php] html 파일안의 php 코드 실행하기 : Apache 2 server on ubuntu can't parse php code inside html file 졸리운_곰 2024.08.13 86
154 [php] 리눅스 (유닉스 ) 계열에서 php로 마이크로소프트 MS SQL 서버 접속 : Microsoft Drivers for PHP for SQL Server의 Linux 및 macOS 설치 자습서 졸리운_곰 2024.08.07 89
153 PHP 실행 지연(delay) 시키기 졸리운_곰 2024.07.07 86
152 [PHP] 문자열 비교하기 - ===, strcmp(), strcasecmp(), strncmp() 졸리운_곰 2024.07.07 117
151 [PHP] 외부 URL의 내용 얻어오기(cURL, file_get_contents) 졸리운_곰 2024.07.07 278
150 [PHP] CURL를 활용하여 POST방식으로 JSON데이터 주고 받기 졸리운_곰 2024.06.21 138
149 [MySQL+PHP] MySQL 접속후 데이터 가져오기 졸리운_곰 2024.04.18 109
» [php] [xampp] xampp php 버전 폴더 (디렉토리) 별 설정 : Running multiple PHP versions on XAMPP file 졸리운_곰 2024.03.21 1067
147 [php] [PHP] Laravel - PayPal 결제 모듈 연동하기 (2) - 백엔드 처리 file 졸리운_곰 2024.03.17 102
146 [php] [PHP] Laravel - PayPal 결제 모듈 연동하기 (1) file 졸리운_곰 2024.03.17 199
145 [php] PHP - Show JSON array in html table 졸리운_곰 2024.02.18 81
144 [php] php / string을 json으로 변환 한 뒤 값 가져오기 졸리운_곰 2024.02.18 107
143 [php] Low Code Web Content Server: Making Marks on the Digital Shore. An Anecdotal View. : 로우 코드 웹 콘텐츠 서버: 디지털 해안에 흔적을 남기다. 일화적인 견해. file 졸리운_곰 2024.02.18 90
142 [php] [xampp] [php] php의 mail() 함수로 구글 이메일 보내기 / XAMPP 서버 및 aws의 EC2 / php mail function to send Gmail at XAMPP and AWS EC2 not working / Username and Password not accepted. file 졸리운_곰 2023.09.12 154
141 [php] PHP / MariaDB / 데이터베이스 값 가져와서 출력하기 졸리운_곰 2023.06.22 91
140 [php] Start Using HTML5 WebSockets Today With a PHP Server 지금 PHP 서버에서 HTML5 WebSocket 사용 시작 졸리운_곰 2023.05.09 143
139 [php] json_encode 유니코드 한글 깨짐 해결방법 졸리운_곰 2023.02.04 157
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED