Share this page : facebooktwitterlinkedinmailfacebooktwitterlinkedinmail
Apache

The apache is installed on the MAC OSX by default.

To start httpd:

sudo /usr/sbin/apachectl start

To stop httpd:

sudo /usr/sbin/apachectl stop

To restart httpd:

sudo /usr/sbin/apachectl restart

 

The pre-installed version of PHP in Mac OS 10.12 (Sierra) is still only PHP 5.6.

Installing PHP

First, choose the version of PHP you want to install. In this example, I will install PHP 7 as that is the latest stable version of PHP.

curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0
Configuring Apache

Provided you are using the pre-installed version of Apache, PHP OSX will automatically configure Apache to use the new PHP module.

The default module loaded by apache is php5, as follow:

LoadModule php5_module /usr/local/php5/libphp5.so

After browsing the folder local and php5, we should add a new line similar to following:

LoadModule php7_module /usr/local/php5-7.0.12-20161101-102255/libphp7.so

Update PATH

If you don’t want to run the command above every time you open a new command line, you can update the PATH in your .bash_profile.

vi ~/.bash_profile
export PATH=/usr/local/php5/bin:$PATH
Configure PHP

Configure the parameters of PHP, navigate to

/usr/local/php5-7.0.12-20161101-102255/php.d/99-liip-developer.ini

You can tune the php according to your need, eg.

I cannot upload big dump files (memory, HTTP or timeout problems).

Starting with version 2.7.0, the import engine has been re–written and these problems should not occur. If possible, upgrade your phpMyAdmin to the latest version to take advantage of the new import features.

The first things to check (or ask your host provider to check) are the values of upload_max_filesizememory_limit and post_max_size in the php.ini configuration file. All of these three settings limit the maximum size of data that can be submitted and handled by PHP. One user also said that post_max_size and memory_limit need to be larger than upload_max_filesize. There exist several workarounds if your upload is too big or your hosting provider is unwilling to change the settings:

  • Look at the $cfg['UploadDir'] feature. This allows one to upload a file to the server via scp, ftp, or your favorite file transfer method. PhpMyAdmin is then able to import the files from the temporary directory. More information is available in the Configuration of this document.

  • Using a utility (such as BigDump) to split the files before uploading. We cannot support this or any third party applications, but are aware of users having success with it.

  • If you have shell (command line) access, use MySQL to import the files directly. You can do this by issuing the “source” command from within MySQL:

    source filename.sql;
test PHP

create a file called phpinfo.php, and add following to the content:

<?php

phpinfo();

?>

open a browser, type http://localhost/phpinfo.php

All the php info will pop up.

 

Mysql

 

Download and install the latest MySQL generally available release DMG for Mac OS X.

you can update your path to include /usr/local/mysql/bin.

export PATH=/usr/local/mysql/bin:$PATH

Note: You will need to open a new Terminal window or run the command above for your path to update.

If you are so inclined, the start/stop commands have changed for MySQL 5.7 on OSX

To start

sudo launchctl load -F  /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

To stop

sudo launchctl unload -F  /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

To find the MySQL version from the terminal, type at the prompt:

/usr/local/mysql/bin/mysql -v -u root -p

Finally, you should run mysql_secure_installation. While this isn’t necessary, it’s good practice to secure your database:

sudo mysql_secure_installation -u root

 

Connect PHP and MYSQL

For some reason mysql on OS X gets the locations of the required socket file a bit wrong, but thankfully the solution is as simple as setting up a symbolic link.

You may have a socket (appearing as a zero length file) as /tmp/mysql.sock or /var/mysql/mysql.sock but 1 or more apps is looking in the other location for it.

Rather than move the socket and have to edit config files and remember to keep edited files local and away from servers where the paths are correct, simply create a symbolic link so your mac finds the required socket, even when it’s looking in the wrong place!

If you have /tmp/mysql.sock but no /var/mysql/mysql.sock then…

cd /var 
sudo mkdir mysql
sudo chmod 755 mysql
cd mysql
sudo ln -s /tmp/mysql.sock mysql.sock

If you have /var/mysql/mysql.sock but no /tmp/mysql.sock then

cd /tmp
ln -s /var/mysql/mysql.sock mysql.sock

You will need permissions to create the directory and link, so just prefix the commands above with sudo if necessary.