Note: This technique also works for other versions, just change the version number. For example, if you want to to install PHP5.6 or PHP7.3. Just change the version number wherever it appears, such as php56-apache2handler or php73-mysql.
Another tut that I found helpful, https://trac.macports.org/wiki/howto/MAMP
Xcode
- Install XCode from the Apple App Store - http://itunes.apple.com/us/app/xcode/id497799835. This is a large download, so kick this off sometime before you decide to start this process.
- Open up the XCode app to finish installation.
- In Xcode, go to Xcode -> Open Developer Tool -> More Developer Tools. This will launch a web browser taking you to a list of available downloads (you'll need to login with your Apple ID - it will take you through a registration process if it is your first time logging in to the Apple development site).
- Download and install the latest version of "Command Line Tools (OS X Mavericks)".
Note: OS X Mavericks is the 10.9.X version.
MacPorts
Install MacPorts.
Configuring
Open a terminal and execute the following commands: (must restart terminal)
sudo port selfupdate
sudo port upgrade outdated
sudo port install php53 +mysql55 +mcrypt +tidy +pear mysql55-server phpmyadmin memcached
sudo port install php53-apache2handler php53-mysql php53-soap php53-curl php53-ldap php53-intl php53-gd php53-mbstring php53-uploadprogress php53-sockets php53-xdebug php53-xhprof
sudo port load apache2
sudo port load memcached
sudo /opt/local/apache2/bin/apachectl start
sudo /opt/local/apache2/bin/apxs -a -e -n "php5" mod_php53.so
sudo nano /opt/local/apache2/conf/httpd.conf
Go to line 119 (In Nano: CTRL+w then CTRL+t and write 119), and enter the following lines:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Why? Well, now we told apache to associate .php file with PHP and .phps files with PHP-Source.
Now go to line 234 containing “DirectoryIndex index.html” and change it to:
DirectoryIndex index.php index.html
Save the file (In Nano CTRL+O) and close it (In Nano CTRL+X). Now lets also restart Apache:
sudo /opt/local/apache2/bin/apachectl restart
sudo cp /opt/local/etc/php53/php.ini-development /opt/local/etc/php53/php.ini
When done, go to http://localhost in your browser. You should now see “It works” on your screen. We have no files yet for PHP, but we’ll get to that.
Configure Apache
sudo nano /opt/local/apache2/conf/httpd.conf
First off, search (In Nano CTRL+W) for ServerName and change it to:
ServerName localhost
Remove the '#' from the following line to enable virtual hosts.
#Include conf/extra/httpd-vhosts.conf
Save the file (In Nano CTRL+O) and close it (In Nano CTRL+X).
Open the virtual hosts file:
sudo nano /opt/local/apache2/conf/extra/httpd-vhosts.conf
Remove the default vhost configs and replace with:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/opt/local/apache2/htdocs"
ServerName localhost
ErrorLog "logs/error_log"
CustomLog "access_log" common
</VirtualHost>
Save the file (In Nano CTRL+O) and close it (In Nano CTRL+X).
Restart Apache.
sudo /opt/local/apache2/bin/apachectl restart
Now we should be fine and dandy… your localhost should work now. Lets have a try, type the following command in your terminal:
sudo -s 'echo "<?php phpinfo() ?>" >> /opt/local/apache2/htdocs/index.php'
Now open the following URL: http://localhost/index.php
If all went well, you should now be able see the PHP info screen.
Configure PHP
sudo nano /opt/local/etc/php5/php.ini
Set the correct location for MySQL's socket by finding "pdo_mysql.default_socket", "mysql.default_socket", and "mysqli.default_socket" and changing their value.
pdo_mysql.default_socket=/opt/local/var/run/mysql55/mysqld.sock
mysql.default_socket = /opt/local/var/run/mysql55/mysqld.sock
mysqli.default_socket = /opt/local/var/run/mysql55/mysqld.sock
Increase the memory limit.
memory_limit = 512M
Set the date.timezone to your timezone.
date.timezone = America/Chicago
Save the file (In Nano CTRL+O) and close it (In Nano CTRL+X).
Restart Apache.
sudo /opt/local/apache2/bin/apachectl restart
PHP CLI
Make sure the PHP CLI and Apache are running the same version of PHP by removing the default PHP binary and creating a symlink to the PHP 5.3 binary.
sudo rm /usr/bin/php
sudo ln -s /opt/local/bin/php53 /usr/bin/php
Configure MySQL
sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db
Add the path to the mysql executables to your $PATH variable.
nano ~/.profile
Add the following:
export PATH=/opt/local/lib/mysql55/bin:$PATH
If you want to use the commands, mysql, mysqld_safe, mysql_secure_installation, etc., then close and restart your terminal.
Add mysql as a startup item.
sudo port load mysql55-server
At this point, it is easiest to reboot. Alternatively, you can start the MySQL daemon manually via the following command:
sudo /opt/local/lib/mysql55/bin/mysqld_safe &
Secure the MySQL server and set a new admin password.
sudo /opt/local/lib/mysql55/bin/mysql_secure_installation
Other items in secure installation:
- Remove anonymous users? y
- Disallow root login remotely? y
- Remove test database and access to it? y
- Reload privilege tables now? y
Create a MySQL configuration file.
sudo cp /opt/local/share/mysql55/support-files/my-large.cnf /etc/my.cnf
Open the configuration file for editing.
sudo nano /etc/my.cnf
Change the maximum packet size to 16M.
max_allowed_packet = 16M
Enable network access by ensuring that "skip-networking" is commented out. If you want extra security, you can add a "bind-address" to limit access to the localhost. However, adding this will prevent you from connecting to your DB from another IP, which will be a problem if you connect to your DB from a VM or Parallels instance.
#skip-networking
bind-address = 127.0.0.1 # OPTIONAL - WILL PREVENT CONNECTIVITY FROM VM OR PARALLELS
Save the file (In Nano CTRL+O) and close it (In Nano CTRL+X).
Restart MySQL for the changes to take effect.
sudo port unload mysql55-server
sudo port load mysql55-server
Configure phpMyAdmin
Open the Apache configuration file.
sudo nano /opt/local/apache2/conf/httpd.conf
Add the following lines to the end of the file:
# Local access to phpmyadmin installation
Include conf/extra/httpd-phpmyadmin.conf
Save the file (In Nano CTRL+O) and close it (In Nano CTRL+X).
Create a vhosts file.
sudo nano /opt/local/apache2/conf/extra/httpd-phpmyadmin.conf
Add the following:
AliasMatch ^/phpmyadmin(?:/)?(/.*)?$ "/opt/local/www/phpmyadmin$1"
<Directory "/opt/local/www/phpmyadmin">
Options -Indexes
AllowOverride None
Order allow,deny
Allow from all
LanguagePriority en de es fr ja ko pt-br ru
ForceLanguagePriority Prefer Fallback
</Directory>
Save the file (In Nano CTRL+O) and close it (In Nano CTRL+X).
Restart Apache so that your changes take effect.
sudo /opt/local/apache2/bin/apachectl -k restart
Note: Make sure to use the full path as shown here, as apachectl in your PATH refers to the system provided Apache!
Finally, you need to set up the phpMyAdmin configuration to access MySQL. First, set up the config file:
cd /opt/local/www/phpmyadmin/
sudo cp config.sample.inc.php config.inc.php
sudo nano config.inc.php
Make phpmyadmin connect to your database using a socket connection, and define your socket location.
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['socket'] = '/opt/local/var/run/mysql55/mysqld.sock';
Save the file (In Nano CTRL+O) and close it (In Nano CTRL+X).
To check your phpMyAdmin installation, point your browser to http://localhost/phpmyadmin and verify that phpMyAdmin loads and can access your database (use the MySQL root username and password you setup earlier).
Keep up the good work!
Hello, I check your blog on a regular basis. Your humoristic
style is witty, keep up the good work!