[ACCEPTED]-Set up Apache for local development/testing?-apache

Accepted answer
Score: 28

Your Mac comes with both an Apache Web Server 51 and a build of PHP. It's one of the big 50 reasons the platform is well loved by web 49 developers.

Since you're using Code Igniter, you'll 48 want PHP 5, which is the default version 47 of PHP shipped with 10.5. If you're on 46 a previous version of the OS hop on over 45 to entropy.ch and install the provided PHP5 package.

Next, you'll 44 want to turn Apache on. In the sharing 43 preferences panel, turn on personal web 42 sharing. This will start up apache on your 41 local machine.

Next, you'll want to setup 40 some fake development URLs to use for your 39 sites. Long standing tradition was that 38 we'd use the fake TLD .dev for this (ex. stackoverflow.dev). However, .dev is 37 now an actual TLD so you probably don't 36 want to do this -- .localhost seems like an emerging 35 defacto standard. Edit your /etc/hosts file 34 and add the following lines    www.example.localhost    example.localhost

This points the 33 above URLs at your local machine. The last 32 step is configuring apache. Specifically, enabling 31 named virtual hosting, enabling PHP and 30 setting up a few virtual hosts. If you used 29 the entropy PHP package, enabling PHP will 28 already be done. If not, you'll need to 27 edit your http.conf file as described here. Basically, you're 26 uncommenting the lines that will load the 25 PHP module.

Whenever you make a change to 24 your apache config, you'll need to restart 23 apache for the changes to take effect. At 22 a terminal window, type the following command

sudo apachectl graceful

This 21 will gracefully restart apache. If you've 20 made a syntax error in the config file apache 19 won't restart. You can highlight config 18 problems with

sudo apachectl configtest

So,with PHP enabled, you'll 17 want to turn on NamedVirtualHosts. This 16 will let apache respond to multiple URLs. Look 15 for the following (or similar) line in your 14 http.conf file and uncomment it.

#NameVirtualHost *  

Finally, you'll 13 need to tell apache where it should look 12 for the files for your new virtual hosts. You 11 can do so by adding the following to your 10 http.conf file. NOTE: I find it's a good 9 best practice to break out config rules 8 like this into a separate file and use the 7 include directive to include your changes. This 6 will stop any automatic updates from wiping 5 out your changes.

<VirtualHost *>
    DocumentRoot /Users/username/Sites/example.localhost
    ServerName example.localhost
    ServerAlias www.example.localhost

You can specify any folder 4 as the DocumentRoot, but I find it convenient 3 to use your personal Sites folder, as it's 2 already been configured with the correct 1 permissions to include files.

Score: 6

Sorry Kyle, I don't have enough cred to 9 respond directly to your comment. But if 8 you want to have each project be served 7 on a different port, try setting up your 6 virtual host config exactly like Kelly's 5 above (minus the dns stuff) except instead 4 of 80, give each virtualhost its own port 3 number, assuming that you've added this 2 port to your ports.conf file.

NameVirtualHost *

<virtualhost *:80>
DocumentRoot /site1/documentroot

<virtualhost *:81>
DocumentRoot /site2/documentroot

<virtualhost *:82>
DocumentRoot /site3/documentroot

<virtualhost *:83>
DocumentRoot /site4/documentroot

Hope that helps 1 :/

Score: 2

I also download the latest binaries for 16 each and set them up manually. I've found 15 it to be a painless process, as long as 14 you know a little bit about configuring 13 Apache.

On my development machine, I have 12 apache setup with name-based virtual hosting. I also have a dyndns.org account 11 which maps my development domain to my local 10 machine. DynDNS provides a wildcard domain, and 9 therefore using name based virtual hosts 8 I can easily create as many sites (with 7 separate document roots) for as many development 6 domains as I want, all running off the one 5 Apache instance.

e.g. Apache config for 4 the virtual hosts might be something like

NameVirtualHost *:80

<virtualhost *:80>
ServerName site1.mydyndns.dyndns.org
DocumentRoot /site1/documentroot

<virtualhost *:80>
ServerName site2.mydyndns.dyndns.org
DocumentRoot /site2/documentroot

This 3 has been the quickest and easiest way for 2 me to easily maintain many development sites 1 on my local machine.

I hope that makes sense.

Cheers, Kelly.

Score: 1

I don't use Macos, but I do use Apache. In 7 my apache configuration file (on linux its 6 usually at /etc/apache2/apache2.conf), look 5 for a reference to a file called ports.conf. Find 4 this file and add the line

Listen 8080

Then 3 restart the apache process. After that you 2 should be in business. I apologize in advance 1 if this doesn't work on a mac :)

Score: 0

You could use a low up front setup package 2 such as XAMPP and run it as a separate instance. There 1 are many other similar projects as well.

Score: 0

For PHP you have several high-quality packages 11 for deploying Apache+Mysql+PHP, such as 10 WAMP and XAMPP. Personally, I download the latest 9 binaries of each and install manually to 8 have more fine grained control. There are 7 plenty of online tutorials on how to handle 6 that.

Database migrations should be straightforward 5 - dump the database on the server, either 4 at the command line or through an interface 3 such as PHPMyAdmin, and export it back in similar 2 ways (PHPMyAdmin is recommended if you have 1 no experience with the Mysql command line).

Score: 0

You can use MAMP pro but the free version 1 is a very good choice as well. Get it here: http://www.mamp.info/en/mamp.html

Score: 0

I might recommend using a separate LAMP 3 virtual appliance for each development environment 2 you wish to experiment with. Run them on 1 VMware Server or VirtualBox.

More Related questions