htaccess files to override the default settings. Within the same block change the AllowOverride setting to read: AllowOverride All You’ll also need to change the tag on the line below to the same path: Search for the term DocumentRoot and change the path so it reads: DocumentRoot "/Users/your_username/Sites"
In this example we’ll be pointing it to a new folder called Sites under our username. This is the directory where you’ll be serving your documents from, it’s entirely down to personal preference, traditionally it’s named public_html or htdocs. While Virtual Hosts allow you to run more than one website on a single machine, you can also point them to individual IP addresses or domain names of your choice which I’ll cover in more depth later on. Some applications require the mod_rewrite module which provides a rule-based rewriting engine to rewrite requested URLs on the fly. Search for the term Virtual hosts: Include /private/etc/apache2/extra/nf Search for the term php5_module: LoadModule php5_module libexec/apache2/libphp5.so Search for the term rewrite_module: LoadModule rewrite_module libexec/apache2/mod_rewrite.so Search for the term vhost_alias_module: LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so The first set of configuration will be to enable some modules and an include which I’ve listed out below, to enable them simply remove the # symbol from the beginning of the line: There will be multiple areas you need to change in this file but I’ll break it down into small chunks detailing what each part does. Now you have a backup you can go in and edit the file, I’ll be using the vim tool in my examples: vim /etc/apache2/nf Before you do though make a quick backup just in case you make an error you can always revert to the original: cp /etc/apache2/nf /etc/apache2/ To do this you need to open up the /etc/apache2/nf file in your favorite text editor. Now you have tested the server is working you need to configure it. Note: Throughout the rest of this article whenever you see the string your_username being used please change it to match the username on your Mac. Simply add 127.0.0.1 localhost on a new line and save. If your struggling to reach your site via this url you might need to add an alias in your /private/etc/hosts file, even though it should be there by default. To keep things simple I’ve listed out all the files you’ll need: /private/etc/hostsĪs Apache is already installed you can start getting familiar with its commands straight away by opening up the command prompt and entering the following.Īfter starting Apache you can test to see if the server is working in the browser by going to you should see the text “It works!”. This article is for experienced developers who have experience using the command prompt.
When using third party programs you depend on it to have the latest versions of the development stack, but it can become out of date. By not using third party software you have full control over your setup, today I’ll be giving you a deep dive on how to setup your environment with the ability to have multiple PHP versions and virtual hosts.
Note: This method is experimental only, when you upgrade the OS X you may loose your settings. It does however have it’s downfalls and with OS X 10.11 now coming bundled with Apache what better time to try a new setup.
There are multiple methods and tools for developing web applications locally, I’ve always been a big fan of MAMP Pro due to it’s simplicity and it’s UI, it’s pleasant to use, very easy to setup and you’ll get running in no time.