Installing Php For Mac Os X



Update: I updated the blogpost for PHP 7 instead of PHP 5. If you want to update your current PHP 5 installation to a PHP 7 installation, see this blogpost: Migrating/updating from PHP 5 to PHP 7 on OS X (MacPorts).

  • Note that this package will ONLY work on Mac OS 10.4, NOT 10.3! I installed it on 10.3 and the installation failed at the end, and then the Apache server would not restart because it could no longer load the php shared library. I can't find any precompiled version of PHP 5.2 available for Mac OS 10.3.
  • Before going into installation you need to download the version of dmg file which suits your system configuration. And before doing that you should have Mac OS X and you should log in as administrator in terminal. Now, prepare yourself for downloading and installing XAMPP properly on your system.
Php

To build on MacOS X 10.3.5 set the environment variable CFLAGS in the following way (depending on your shell) setenv CFLAGS '-DBIND8COMPAT=1 -DEAPI -O3'. I found good gist how to install PHP 5.4 and 5.3 side by side on Max OSX via MacPorts. Installing PHP on Mac OS X', which documents how to build PHP. Mac OS X comes with PHP prepackaged. So there isn't much you need to do to install PHP. Open a Terminal window and enter php -version to check which version you have installed. If you're running.

MacPorts is a BSD ports like package management system for OS X.

The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the OS X operating system.

The tool is very handy when it comes to installing command line tools for Mac. In this guide I will use it to install Apache, MariaDB and PHP. You could also install them using Homebrew, or use the packages that come with your Mac, but I prefer MacPorts… So if you don’t have MacPorts installed, follow the installation instruction on their website.

Before installing any ports, make sure you have the latest version of the ports tree:

Apache

If you have web sharing enabled on your Mac, you should disable it before continuing. Web sharing can be found under ‘System preferences’, ‘Sharing’, …

Time to install Apache:

Whenever your installation is completed, you can edit Apache’s configuration file: /opt/local/apache2/conf/httpd.conf. Probably you want to set DocumentRoot to your local Sites folder. To do this change /opt/local/apache2/htdocs to your local sites folder e.g. /Users/Mathias/Sites.

You must also allow traffic to go to your webserver otherwise you will get “Permission denied” errors. By default you have a block like this in your Apache config:

Replace it with the following directive:

Don’t forget to verify your changes after every modification you do to httpd.conf!

When everything is configured, you can start Apache using MacPorts services:

Stopping services can be done using the unload statement.

Apache should be functioning right now, more configuration details can be found everywhere on the internet, I’m not gonna explain the whole config file here…

MariaDB (MySQL)

Again, we use MacPorts:

Once MariaDB is installed, we need to create the main databases:

Time to start MariaDB:

Next we need to create a password for the root user, don’t forget to do this step! This procedure will interactively ask you some security details:

If you work a lot with sockets for MySQL/MariaDB, you can create a symbolic link from the default socket path to MacPort’s path:

You can also specify the socket path in your PHP config file: see below…

Installing php for mac os x 10.11

Mac Os Install Php

Note: MacPorts MariaDB has skip-networking enabled by default in /opt/local/etc/mariadb/macports-default.cnf. If you want to use 172.0.0.1 for your MySQL connections, you should comment out that line.

If you want to use mysql on the command line, you can link mysql to MariaDB:

PHP

Last step is installing PHP:

You might also need the following PHP extensions:

Mac Php Upgrade

Set up your PHP configuration files. For development purposes use:

Mac Os Php

For production use:

Enable the PHP module in Apache

in Apache’s config file /opt/local/apache2/conf/httpd.conf, add index.php to the DirectoryIndex:

Make sure that Apache includes the PHP config, check your httpd.conf file for the following lines:

Also verify that the .so shared object for PHP is included:

Before we can use MySQL in our PHP code, we must set the default socket path in /opt/local/etc/php70/php.ini. Search for mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket and assign the MariaDB socket to them: /opt/local/var/run/mariadb/mysqld.sock.

If you regularly use PHP from the command line, you also want to link the php command to the MacPorts PHP version:

If you want to have colored PHP CLI output, you must enable it by installing php posix.

Installing Php For Mac Os X64

Verify your Apache config, restart Apache, restart MariaDB and everything should work correctly!

You need to make sure you have the Apple Developer Tools, BSD Subsystem, and an installation of X before you try installing PHP-GTK 2. Although the BSD subsystem is installed by default on Mac OS X, you need select the Developer Tools and X Server manually. Although you can use any X server, the easiest would be to use the one Apple provides by default on it's Mac OS X installer.

Get MacPorts (previously knows as DarwinPorts) or Fink and install it. You can use either to install a version of X (if you decided not to use Apple's default distribution), and Gtk+ itself. Both Fink and MacPorts provide versions 2.6 and above of Gtk+. Also make sure you have a version of PHP that is atleast 5.2, MacPorts provides a package. Type php -v on your Terminal to find out your version. If you want to manually compile PHP you can do so: Although you may install it anywhere, /usr/local/ is usually considered a good place. MacPorts installs PHP into /opt/local/.

Now get the latest checkout of PHP-GTK and compile it: Remember to replace /usr/local/ with the actual directory in which you installed PHP. For example, if you installed PHP 5.2 using MacPorts, you would enter /opt/local/ instead.

Finally, copy over the php.ini-recommended file to /usr/local/lib/php.ini and change the value of extension_dir to the directory where php_gtk2.so resides. This is usually something like: /usr/local/lib/php/extensions/no-debug-non-zts-some-date. You may want to create a new symbolic link in /usr/bin/ that points to /usr/local/bin/php. Again, the directory may be /opt/local/ instead of /usr/local/ depending on where your installation of PHP resides.

Install Php Mac

Now continue with Testing your installation.