Install php-cgi on Mac OS X Yosemite

Is it possible to install php-cgi on Mac OS X Yosemite while supporting the standard PHP provided by the OS?

Thanks, Alberto

+3


source to share


2 answers


You can easily install PHP using Homebrew:

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php

brew install php54

      

Homebrew does not change the PHP system version. The system and homebrew versions are in different directories. This is how it looks to me:

System /usr/bin/php

:



/usr/bin/php -v
PHP 5.4.30 (cli) (built: Jul 29 2014 23:43:29)

      

Homebrew /usr/local/bin/php

:

/usr/local/bin/php -v
PHP 5.6.2 (cli) (built: Nov 14 2014 10:30:28)

      

+11


source


If you want to use PHP CGI on Mac OS X, you need a PHP build with CGI enabled. By default PHP version 4.3 and higher is built with the "-enable-cli" option, so the default is CLI (Command Line Interface). You can check this by running "php -v" from the shell. The result will probably be something like this:

PHP 4.4.4 (cli) .... CLI does not output any headers, and by default it is plain text. You can read more about this here.

To use PHP with wxWebServer (or any other CGI application) you will need to create your own PHP binaries with the CGI SAPI. It's simple, it only takes 15 minutes, and you'll be proud of yourself for building PHP yourself. Here is the procedure, step by step:

Download the complete source code for the latest PHP version from php.net. The instructions here are for PHP 5.2.3, but should work for PHP 4. I also tested with 4.4.7.

Unpack the downloaded archive somewhere, for example ~ / Temp / php-5.2.3

Open a terminal window (shell) and navigate to the folder where you unpacked the files:

cd ~/Temp/php-5.2.3

      

Decide where you want to install this custom PHP assembly and create a folder. This document will read the custom folder under your home folder, for example if the username is webdev it / Users / webdev / custom / php5

Create this folder (in Finder or terminal with "mkdir ~ / custom; mkdir ~ / custom / php5") Return to this terminal window, you should still be in ~ / Temp / php-5.2.3. Run. / configure with the CLI disabled if you plan to use this private PHP build for CGI only. Change the paths and parameters to reflect your preference. You don't need the "--disable-cli" option, you can replace it with "--enable-cli" if you plan on using this PHP for something more. You will get both binaries, but you will need to use php-cgi in wxWebServer. Here is a complete command line for .configure that should generate PHP with all common options and CLI disabled:

./configure --prefix=/Users/webdev/custom/php5 --disable-cli --enable-cgi --enable-trans-sid
  --enable-mbstring --with-xml --enable-exif --enable-mbregex --enable-dbx --enable-sockets
  --with-iodbc=/usr --with-curl=/usr --with-config-file-path=/etc --sysconfdir=/private/etc
  --with-mysql=/usr/local/mysql --without-pear

      

When setup is complete, run

  make install

      

Modify your profile (~ / .profile) to add the new php path before the existing one. Add something like this to the end of your .profile:



PATH=~/custom/php5/bin:$PATH

export PATH

      

If you don't know how to edit a profile from the command line, just create a text file in TextEdit containing these two lines and save it in your home folder (~ / Users / webdev) as newpath.txt. Then open a terminal and enter the command:

cat newpath.txt >> .profile

      

The easiest way for the changes to take effect is to log out and log in (or you can use the source command). Congratulations, you now have a normal php installation! If you want to use other PHP, just comment out your changes in .profile

Make sure your new PHP is default:

# which php-cgi

      

/ Users / WebDev / custom / php5 / bin / PHP-CGI

php-cgi -v

PHP 5.2.3 (cgi) (built: Jul 11 ​​2007 00:48:59) Copyright (c) 1997-2007 PHP Zend Engine v2.2.0 Team, Copyright (c) 1998-2007 Zend Technologies

If you want, you can delete the source files in ~ / Temp / php-5.2.3. To uninstall custom PHP, just delete the target folder i.e.

"/Users/webdev/custom/php4".

      

Once you have a custom php installation installed, configure wxWebServer to use the new php binaries. Regardless of whether the CLI is enabled or disabled, you can use php-cgi (the output of "php-cgi", in this case "/ Users / WebDev / user / php5 / bin / PHP-CGI"). If you have disabled CLI build, you can also use the php binary as it will be a CGI build. To do this, enjoy your personal PHP build!

Found here

+4


source







All Articles