{"id":1792,"date":"2015-02-25T21:56:09","date_gmt":"2015-02-25T20:56:09","guid":{"rendered":"http:\/\/denbeke.be\/blog\/?p=1792"},"modified":"2016-11-18T22:47:46","modified_gmt":"2016-11-18T21:47:46","slug":"installing-mamp-mac-os-x-apache-mariadb-php-using-macports","status":"publish","type":"post","link":"https:\/\/denbeke.be\/blog\/webdevelopment\/installing-mamp-mac-os-x-apache-mariadb-php-using-macports\/","title":{"rendered":"Installing MAMP (Mac OS X Apache MariaDB PHP) using MacPorts"},"content":{"rendered":"<p><span style=\"text-decoration: underline;\">Update<\/span>:\u00a0I 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:\u00a0<a href=\"http:\/\/denbeke.be\/blog\/servers\/migratingupdating-from-php-5-to-php-7-on-os-x-macports\/\">Migrating\/updating from PHP 5 to PHP 7 on OS X (MacPorts)<\/a>.<\/p>\n<p><a title=\"MacPorts\" href=\"https:\/\/www.macports.org\" target=\"_blank\">MacPorts<\/a> is a BSD ports like package management system for OS X.<\/p>\n<blockquote><p><em>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.<\/em><\/p><\/blockquote>\n<p>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 <a title=\"Homebrew\" href=\"http:\/\/brew.sh\" target=\"_blank\">Homebrew<\/a>, or use the packages that come with your Mac, but I prefer MacPorts&#8230; So if you don&#8217;t have MacPorts installed, follow the <a title=\"Install MacPorts\" href=\"https:\/\/www.macports.org\/install.php\" target=\"_blank\">installation instruction<\/a> on their website.<\/p>\n<p>Before installing any ports, make sure you have the latest version of the ports tree:<\/p>\n<pre><code>$ sudo port selfupdate<\/code><\/pre>\n<h2>Apache<\/h2>\n<p>If you have web sharing enabled on your Mac, you should disable it before continuing. Web sharing can be found under &#8216;System preferences&#8217;, &#8216;Sharing&#8217;, &#8230;<\/p>\n<p>Time to install Apache:<\/p>\n<pre><code>$ sudo port install apache2<\/code><\/pre>\n<p>Whenever your installation is completed, you can edit Apache&#8217;s configuration file: <code>\/opt\/local\/apache2\/conf\/httpd.conf<\/code>. Probably you want to set <code>DocumentRoot<\/code> to your local <code>Sites<\/code> folder. To do this change <code>\/opt\/local\/apache2\/htdocs<\/code> to your local sites folder e.g. <code>\/Users\/Mathias\/Sites<\/code>.<\/p>\n<p>You must also allow traffic to go to your webserver otherwise you will get &#8220;Permission denied&#8221; errors. By default you have a block like this in your Apache config:<\/p>\n<pre><code>&lt;Directory \/&gt;\r\n    Order deny,allow\r\n    Deny from all\r\n&lt;\/Directory&gt;<\/code><\/pre>\n<p>Replace it with the following directive:<\/p>\n<pre><code>&lt;Directory \/path\/to\/webroot&gt;\r\n    Order allow,deny\r\n    Allow from all\r\n&lt;\/Directory&gt;<\/code><\/pre>\n<p>Don&#8217;t forget to verify your changes after every modification you do to <code>httpd.conf<\/code>!<\/p>\n<pre><code>$ \/opt\/local\/apache2\/bin\/apachectl -t<\/code><\/pre>\n<p>When everything is configured, you can start Apache using MacPorts services:<\/p>\n<pre><code>$ sudo port load apache2<\/code><\/pre>\n<p>Stopping services can be done using the <code>unload<\/code> statement.<\/p>\n<p>Apache should be functioning right now, more configuration details can be found everywhere on the internet, I&#8217;m not gonna explain the whole config file here&#8230;<\/p>\n<h3>MariaDB (MySQL)<\/h3>\n<p>Again, we use MacPorts:<\/p>\n<pre><code>$ sudo port install mariadb-server<\/code><\/pre>\n<p>Once MariaDB is installed, we need to create the main databases:<\/p>\n<pre><code>$ sudo -u _mysql \/opt\/local\/lib\/mariadb\/bin\/mysql_install_db<\/code><\/pre>\n<p>Time to start MariaDB:<\/p>\n<pre><code>$ sudo port load mariadb-server<\/code><\/pre>\n<p>Next we need to create a password for the root user, don&#8217;t forget to do this step! This procedure will interactively ask you some security details:<\/p>\n<pre><code>$ \/opt\/local\/lib\/mariadb\/bin\/mysql_secure_installation<\/code><\/pre>\n<p>If you work a lot with sockets for MySQL\/MariaDB, you can create a symbolic link from the default socket path to MacPort&#8217;s path:<\/p>\n<pre><code>$ sudo ln -s \/opt\/local\/var\/run\/mariadb\/mysqld.sock \/tmp\/mysql.sock<\/code><\/pre>\n<p>You can also specify the socket path in your PHP config file: see below&#8230;<\/p>\n<p>Note: MacPorts MariaDB has <code>skip-networking<\/code> enabled by default in\u00a0<code>\/opt\/local\/etc\/mariadb\/macports-default.cnf<\/code>. If you want to use 172.0.0.1 for your MySQL connections, you should comment out that line.<\/p>\n<p>If you want to use <code>mysql<\/code> on the command line, you can link mysql to MariaDB:<\/p>\n<pre><code>$ sudo port select --set mysql mariadb<\/code><\/pre>\n<h2>PHP<\/h2>\n<p>Last step is installing PHP:<\/p>\n<pre><code>$ sudo port install php70-apache2handler\r\n$ sudo port install php70-mysql<\/code><\/pre>\n<p>You might also need the following PHP extensions:<\/p>\n<pre><code>$ sudo port install \\\r\n\tphp70-curl \\\r\n\tphp70-exif \\\r\n\tphp70-gd \\\r\n\tphp70-gettext \\\r\n\tphp70-iconv \\\r\n\tphp70-imap \\\r\n\tphp70-mbstring \\\r\n\tphp70-mcrypt \\\r\n\tphp70-openssl \\\r\n\tphp70-zip<\/code><\/pre>\n<p>Set up your PHP configuration files. For development purposes use:<\/p>\n<pre><code>$ cd \/opt\/local\/etc\/php70\r\n$ sudo cp php.ini-development php.ini<\/code><\/pre>\n<p>For production use:<\/p>\n<pre><code>$ cd \/opt\/local\/etc\/php70\r\n$ sudo cp php.ini-production php.ini<\/code><\/pre>\n<p>Enable the PHP module in Apache<\/p>\n<pre><code>$ cd \/opt\/local\/apache2\/modules\r\n$ sudo \/opt\/local\/apache2\/bin\/apxs -a -e -n \"php7\" mod_php70.so<\/code><\/pre>\n<p>in Apache&#8217;s config file <code>\/opt\/local\/apache2\/conf\/httpd.conf<\/code>, add index.php to the <code>DirectoryIndex<\/code>:<\/p>\n<pre><code>&lt;IfModule dir_module&gt;\r\n    DirectoryIndex index.php index.html\r\n&lt;\/IfModule&gt;<\/code><\/pre>\n<p>Make sure that Apache includes the PHP config, check your <code>httpd.conf<\/code> file for the following lines:<\/p>\n<pre><code># Include PHP configurations\r\nInclude conf\/extra\/mod_php70.conf<\/code><\/pre>\n<p>Also verify that the <code>.so<\/code> shared object for PHP is included:<\/p>\n<pre><code># Load the PHP module\r\nLoadModule php7_module modules\/mod_php70.so<\/code><\/pre>\n<p>Before we can use MySQL in our PHP code, we must set the default socket path in <code>\/opt\/local\/etc\/php70\/php.ini<\/code>. Search for <code>mysql.default_socket<\/code>, <code>mysqli.default_socket<\/code> and <code>pdo_mysql.default_socket<\/code> and assign the MariaDB socket to them: <code>\/opt\/local\/var\/run\/mariadb\/mysqld.sock<\/code>.<\/p>\n<p>If you regularly use PHP from the command line, you also want to link the <code>php<\/code> command to the MacPorts PHP version:<\/p>\n<pre><code>$ sudo port select --set php php70<\/code><\/pre>\n<p>If you want to have colored PHP CLI output, \u00a0you must enable it by installing <em>php posix<\/em>.<\/p>\n<pre><code>$ sudo port install php70-posix<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>Verify your Apache config, restart Apache, restart MariaDB and everything should work correctly!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update:\u00a0I 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:\u00a0Migrating\/updating from PHP 5 to PHP 7 on OS X (MacPorts). MacPorts is a BSD ports like package management system for OS X. The MacPorts Project is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[235,227,112],"tags":[213,251,250,249,240,215],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.6.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Installing MAMP (Mac OS X Apache MariaDB PHP) using MacPorts &ndash; DenBeke<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/denbeke.be\/blog\/webdevelopment\/installing-mamp-mac-os-x-apache-mariadb-php-using-macports\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Installing MAMP (Mac OS X Apache MariaDB PHP) using MacPorts &ndash; DenBeke\" \/>\n<meta property=\"og:description\" content=\"Update:\u00a0I 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:\u00a0Migrating\/updating from PHP 5 to PHP 7 on OS X (MacPorts). MacPorts is a BSD ports like package management system for OS X. The MacPorts Project is [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/denbeke.be\/blog\/webdevelopment\/installing-mamp-mac-os-x-apache-mariadb-php-using-macports\/\" \/>\n<meta property=\"og:site_name\" content=\"DenBeke\" \/>\n<meta property=\"article:published_time\" content=\"2015-02-25T20:56:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-11-18T21:47:46+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<meta name=\"twitter:creator\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:site\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"4 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/denbeke.be\/blog\/#website\",\"url\":\"https:\/\/denbeke.be\/blog\/\",\"name\":\"DenBeke\",\"description\":\"Mathias Beke\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/denbeke.be\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/denbeke.be\/blog\/webdevelopment\/installing-mamp-mac-os-x-apache-mariadb-php-using-macports\/#webpage\",\"url\":\"https:\/\/denbeke.be\/blog\/webdevelopment\/installing-mamp-mac-os-x-apache-mariadb-php-using-macports\/\",\"name\":\"Installing MAMP (Mac OS X Apache MariaDB PHP) using MacPorts &ndash; DenBeke\",\"isPartOf\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#website\"},\"datePublished\":\"2015-02-25T20:56:09+00:00\",\"dateModified\":\"2016-11-18T21:47:46+00:00\",\"author\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/denbeke.be\/blog\/webdevelopment\/installing-mamp-mac-os-x-apache-mariadb-php-using-macports\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\",\"name\":\"Mathias Beke\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/denbeke.be\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/015ba35e6ce4f5859e3888ca99807575?s=96&d=mm&r=g\",\"caption\":\"Mathias Beke\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1792"}],"collection":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/comments?post=1792"}],"version-history":[{"count":21,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1792\/revisions"}],"predecessor-version":[{"id":2193,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1792\/revisions\/2193"}],"wp:attachment":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/media?parent=1792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/categories?post=1792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/tags?post=1792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}