• Skip to main content
  • Skip to primary sidebar

CarlosOnWeb.com

Code, Console, Content

  • Home
  • Services
  • Contact

Installing Apache, PHP, and MariaDB (instead of MySQL) in Mac OS X

August 5, 2014 by carlosonweb Leave a Comment

I have to admit, the first time I got my hands into Mac OS X, I fell in love with it. It was a beauty to behold. No wonder folks who own a Machitosh like to say, “I love my Mac.” Truly, Apple is one of those software companies that really knows what a good design is.

But the real reason why I got a Mac was to learn how to develop an iOS App. This is really a development machine, not just another piece of gadget to show off and impress my friends who are stuck in Windows. Mind you, I still keep my Windows 8 laptop.

As a PHP Web Developer ( and soon an iOS App Developer ), I can’t help but wish I can install all the development tools I get to enjoy in my Ubuntu Linux Box and have them all ported into this Mac machine. Surprisingly, Mac OS X makes the transition a snap and a painless experience.

Underneath its beautiful User Interface, Mac OS X is a power-house — it’s an operating system based on UNIX. It’s got most of the things I need for Web Development work. Here is a sampling of the things that comes pre-installed into a fresh Mac OS X: Python, Ruby, PHP, Apache and many more. So under the hood, I feel comfortable already.

This article shows you how to setup a PHP Web Development environment within Mac OS X (Mavericks) containing the following software components: Apache 2, PHP (of course), and MariaDB Server. Note that I picked MariaDB in favour of MySQL, but the two have a lot of things in common. And in fact, most commands that you issue against the database server are similar and compatible.

So enough talk, let’s get going with the setup.

How to Install Apache 2 in Mac OS X

This one is pretty quick and easy since Apache 2 is really installed Mac OS X. You just need to run Apache to see it in action. And that’s exactly what we will do here.

From the Terminal, issue this command:

 
  $ sudo apachectl start

Naturally, the sudo command will ask you for an administrative password, so go just type it in.

That’s it. No sweat.

You can test it out to see if Apache is really running by firing up Safari or any Web Browser that you installed in you system and typing this in the address bar: http://localhost/

You should be able to see a Welcome Message.

In case you’re wondering where Apache is looking up the file to serve from the localhost, it’s located here:

/Library/WebServer/Documents/

In Apache-speak, that’s called the DocumentRoot. The welcome message is contained in the file named index.html.en.

Later in this article, you will learn how to create an Apache Virtual Host and map it into any directory that you wish to use. But for now, let’s configure Apache so that it is able to serve PHP Scripts from the document root.


Configuring Apache 2 to use PHP

Doing this is very simple. You just need to tweak a single line from the Apache Configuration file, httpd.conf. Okay, follow along with me.

First, be paranoid. Make a backup copy of the current Apache Configuration file by issuing these from the command line:


  $ cd /etc/apache2/
sudo cp httpd.conf httpd.conf.BAK 

Next edit the httpd.conf file with a text editor. For this example, we’ll use the nano text editor. So from the command line, type the following then hit RETURN:

  $ sudo nano httpd.conf 

Locate the line that says "LoadModule php5_module libexec/apache2/libphp5.so"

If you notice the pound sign (#) it means that line is commented out and therefore disabled.

To enable, simply delete the pound sign.

Save the changes by pressing Control + O. If you are asked to confirm, just hit Y for YES.

Then exit nano with Control + X.

You don’t have to install PHP anymore since it is already there in your machine. But there is one more thing you have to do – make sure that you have a PHP configuration file called php.ini. Apache will be looking for that file.

The php.ini file should be located in directory /private/etc/. Now let’s check if there is that file already by looking it up with ls command:

  $ ls php* 

If your machine is like mine, you won’t be able to find php.ini in there, but instead, you’ll see the php.ini.default file. That’s good for two reasons, we have something to copy, which makes life easier a little bit, and then in case something went wrong while we are tweaking the file, we have something to fallback to. As Apache will be needing the php.ini file, we can simply copy from the existing php.ini.default, by typing:

  $ sudo cp php.ini.default php.ini 

From here, we are now in the position to test out if Apache can execute some PHP Scripts served from the document root.

Now let’s see if this works. Let’s put a PHP File under the document root and see if Apache can execute that file. To do that, you may do the following:

Fire up Terminal and navigate to the default Document Root which is /Library/WebServer/Documents/

From the Command Line, type

  $ cat > test.php

The cursor should be waiting at the next line waiting for your input. This is one just one of the ways you can create a file very quickly.

Type the following then press RETURN at the end: <?php echo 'Welcome to PHP!';

Press Ctrl + C to end the cat command and allow UNIX to finally create the file with the text you just entered.

Now, using the Web Browser, navigate to http://localhost/test.php to try to execute the PHP file you just created.

You should be able to see the string “Welcome to PHP” displayed on the screen.

Congratulations you are now ready to develop in PHP under Mac OS X!

How about a self-pat at the back?

But wait? Did I say, we’ll be installing MariaDB? Of course!

Next paragraphs please.

Installing MariaDB into Mac OS X

Unlike Apache and PHP, MariaDB doesn’t come pre-installed with Mac OS X. To do that we’ll be using another cool tool: HomeBrew which claims to be the missing package manager for OS X.


Let’s see it in action and then proceed right away with the MariaDB installation.

Install HomeBrew from the command line:


  ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

As you can see, we are using ruby to run the installation. It should take a while and you know it’s done when you see this message:



  ==> Installation successful!
  ==> Next steps
  Run 'brew doctor' before you install anything
  Run 'brew help' to get started
  Type brew doctor from the Command Line and you’ll see this message
  Your system is ready to brew.
  Now comes the thing that we’re really after – installing MariaDB. Go and type in:

  brew install mariadb

Again it will take a while to download and install, but the nice thing is you don’t have to much after that. After a successful installation, you will be offered a mug of freshly brewed beer like the one shown in the screenshot below.



Screenshot of successful MariaDB installation
MariaDB Installation using Homebrew

From here, you can now experiment with MariaDB. 

In the next couple of articles, we’ll try to use MariaDB more and more starting with the installation of phpMyAdmin (my favorite MySQL / MariaDB Client), setup WordPress development box. And finally as I am exploring the Laravel PHP Framework, I’ll touch that as well.

Meanwhile, if you have some questions about the installation process shown here or you encounter some sort of problems following this article, please feel free to get in touch with me or leave your comment from the Comment Box below.

Share this:

  • Facebook
  • Twitter
  • LinkedIn
  • Email
  • Print
  • More
  • Pinterest
  • Tumblr

Filed Under: Code, Console Tagged With: Apache, Mac OS X, MariaDB, PHP

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar


Get In Touch

I love to hear from you. Don't be shy!

Use the Contact Form to send me a message.




Write-Ups

  • Installing Apache, PHP, and MariaDB (instead of MySQL) in Mac OS X
  • Using WordPress — The Good, The Bad, and The Overkill
  • Domain Name: The Beginning Of Your Online Empire
  • 3 Easy Ways To Make Money Online
  • Is Your Lack of Technical Know-How Preventing You From Running An Online Business?
  • Must-Have Tools For The Budding Online Entrepreneur
  • Seven Basic Jargons Every Newbie Should Know Before Building A Website
  • Making Money Without Trading Time For It
  • Time and Money Trap
  • Small Businesses Still Don’t Get It — Part 2
[footer_backtotop text="Top" href="#content"] Carlos On Web :: PHP Developer and WordPress Back-end Specialist based in the Philippines © 2005–2021
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.