Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

PHP

Does anyone know an easy way to upgrade my current PHP version run on Maco OS X Server 10.6.8 to the latest PHP version which I believe is 5.3.9 ?

Mac mini, Mac OS X (10.6.8), Mac OS X Server

Posted on Jan 22, 2012 6:06 AM

Reply
10 replies

Jan 23, 2012 2:04 PM in response to JohnsApple

This is simple using the freeBSD type ports system known as MacPorts


Install macports from here: http://www.macports.org/ it installs into the /opt directory which it will create and keep everything you install in that folder so it will not cross-contaminate any Apple default software.


macports will also create a .profile for your shell in your user home directory with the new shell paths you will need (almost all - see below about pear). These instructions assume you are using the terminal and logged in as an admin. If you use root on your server instead, you will not need to type sudo but you will need to copy the .profile file to your root home directory.


run the following commands in terminal:


sudo port selfupdate

sudo port upgrade outdated

(you will run these two commands every time you want to automatically upgrade installed packages. It will upgrade everything you installed at once so you don't need to do any line by line installation.)


Everyone will have different needs with their php. It is extremely simple to add php modules by using the below commands. You can visit the macports website and search for php5 to see all the packages you would want to install.


type

sudo port install package-name (for example: sudo port install php5-mysql)


type the name of the package you want to install (I use the following in my php)


php5-mysql

php5-gd

php5-curl

php5-iconv

php5-mcrypt

php5-ftp

php5-mbstring

pear-PEAR (NOTE about the pear install: you will need to append your .profile with /opt/local/lib/php/pear/bin) your .profile lives in the user home directory. The whole line should end up looking like this:


export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/lib/php/pear/bin:$PATH


You'll notice I didn't actually type in "sudo port install php5" this is because php5 is a dependency on all the other php5 modules so it gets installed automatically. This is the case for anything you install via macports. Visit the macports site for details.


IMPORTANT ABOUT MYSQL

If you want to use Apple's mysql install, you need to do the following:

edit the file located at: /opt/local/etc/php5/php.ini

the default mysql.sock should be changed to /var/mysql/mysql.sock for mysql and mysqli and any other mysql extension. You can do a text search for anything that has mysql. For example these lines should look like this as they are blank by default:


mysql.default_socket =/var/mysql/mysql.sock

mysqli.default_socket =/var/mysql/mysql.sock


then use pear to install any pear extensions (if you have any) like:


pear install db

pear install net_ftp

pear install xml_rss

etc…


Now to load the newly installed php module:


First, edit /etc/apache2/httpd.conf and comment out the apple default php5 module which looks like this: LoadModule php5_module libexec/apache2/libphp5.so (just put a # in front of this line). You will put this line into the custom.conf.


create a file called custom.conf and put it into /etc/apache2/sites/ and add the following 2 lines:


#LoadModule php5_module libexec/apache2/libphp5.so

LoadModule php5_module /opt/local/apache2/modules/libphp5.so


(you need to do this instead of doing it in /etc/apache2/httpd.conf because the Server Admin app will constantly re-edit this file and delete the new macports php module line while leaving the Apple version alone and commented out)


After all this, do sudo apachectl restart and you should be done. If something goes wrong, uncomment the apple php module and comment out the macports php module (in the /etc/apache2/sites/custom.conf file you created) restart apache and then troubleshoot.

Jan 23, 2012 4:46 PM in response to Nick Ferszt

Thanks Nick for such a complete solution. Maybe its me but it its all above my Command Line Terminal knowledge. I was hoping for some simple GUI where I can just download and click Intall Upgarde. A simple Apple approach. I didn't even know there were so many different PHP Packages. This all started when I was advise by GoDaddys Website Protection Scanner that my server uses a version of PHP that is affected by multiple vulnerabilities. Solution: Upgrade to PHP 5.3.7 or later.


Easier sad then done.


I'm going to have to study your solution to see if its posible for me to actually try it.


Thanks

Jan 23, 2012 10:04 PM in response to Nick Ferszt

Nick,


I've tried your recommendations and can get PHP 5.3.9 installed but can't get it to connect back to my mySQL default database from Apple.


I've opened my original php.ini file (the default file in /etc/) and have copied the mysql default settings from that file and created the php.ini file in /opt/local/etc/php5/ folder (from the php.ini-production file) and can't get it to connect back to my original mySQL database.


Any other ideas?

Jan 24, 2012 7:31 AM in response to jdb4mac

Ok, I forgot: I believe that by default in macports the php.ini file was named php.ini-production and php.ini-development.


You will need to copy and rename the php.ini-production to php.ini and change the mysql default connection settings in there, these lines at the very least (there are a couple other mysql type extenstions that all connect to mysql.sock)


mysql.default_socket =/var/mysql/mysql.sock

mysqli.default_socket =/var/mysql/mysql.sock


Don't use the apple /etc/php.ini file. Also remember if you added or changed anything to /etc/php.ini you will need to duplicate those in the /opt/local/etc/php5/php.ini file

Feb 20, 2012 4:36 PM in response to Nick Ferszt

Nick, this part of your comment help me get PHP 5.3.10 running as after installing it via MacPorts the older 5.3.8 was still running.

Your comment:


***********************************

Now to load the newly installed php module:


First, edit /etc/apache2/httpd.conf and comment out the apple default php5 module which looks like this: LoadModule php5_module libexec/apache2/libphp5.so (just put a # in front of this line). You will put this line into the custom.conf.


create a file called custom.conf and put it into /etc/apache2/sites/ and add the following 2 lines:


#LoadModule php5_module libexec/apache2/libphp5.so

LoadModule php5_module /opt/local/apache2/modules/libphp5.so


(you need to do this instead of doing it in /etc/apache2/httpd.conf because the Server Admin app will constantly re-edit this file and delete the new macports php module line while leaving the Apple version alone and commented out)


After all this, do sudo apachectl restart and you should be done. If something goes wrong, uncomment the apple php module and comment out the macports php module (in the /etc/apache2/sites/custom.conf file you created) restart apache and then troubleshoot.

***********************************


Worked perfect. I have 2 questions:


1. Should I leave both the custom.conf file and httpd.conf file as is indefinitely?


2. Now I want to use MacPorts to upgrade Apache 2.2.21 to 2.2.22. Will I be required to make any custom.conf file for that too? Is there any obvious issues I will run into? Any advise would be highly appreciated.


Message was edited by: JohnsApple

PHP

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.