Apache Php Server For Mac



  1. Apache Php Server For Mac Windows 10
  2. Apache Php Server For Macos

Now it’s time to continue with setting up Apache and PHP. If you’re coming here through search engine then you probably want to check our previous posts on [intlink id=”how-to-create-a-wordpress-development-environment-on-mac-os-x-snow-leopard” type=”post”]how to install and configure WordPress on Mac OS X Snow Leopard[/intlink].

Fortunately Snow Leopard comes with the latest PHP version (version 5.3.0 at the time of this post) so that’s covered. Please note that PHP is not by default turned on in Snow Leopard. To make sure that you’re configuring everything correctly it’s best to make Web Sharing active (System Preferences » Sharing » Web Sharing). Once that’s done we’re free to go ahead and configure setup PHP and configure Apache.

Mac users have the opportunity to choose either a binary or a source installation. Actually, OS X may came up with Apache and PHP installed by default. This is more likely to be an old build, and in that case that may lack many of the less common extensions. The MAMP is a free, open source utility that enables Mac OS X users to install Apache server, MySQL, PHP, eAccelerator and PHPMyAdmin with ease. Now lets start (sudo apachectl start) or restart (sudo apachectl restart) the Apache web server and test if PHP is running by creating a file in your Web directory containing a call to the function phpinfo.

MAMP is a Mac utility that helps users install Apache, Nginx, PHP and MySQL on their machine and therefore have a personal web server. The name of the program is an acronym for Macintosh, Apache, MySQL and PHP. In this tutorial we will learn to install Apache, MySQL, PHP on macOS Mojave 10.14. Apple released the new macOS Mojave 10.14 on 24th September 2018 and it includes Apache and PHP.

Lets setup PHP first

In order to do so copy php.ini.default to php.ini cp /private/etc/php.ini.default /private/etc/php.ini. This way we’ll keep the original php.ini.default just in the right place for any future reference. If you know what you’re doing and need any special stuff then go ahead and modify the php.ini as you feel fit.

Apache Php Server For Mac

Configure Apache web server

If you have the default Apache installation (and I assume you do) then you find your httpd.conf under /private/etc/apache2/httpd.conf. I expect that you have the technical ability of a software developer familiar with Linux commands. Now edit the httpd.conf file using root access with the sudo command and your favorite text editor. I personally prefer vim if I need to get something done on Terminal but you can also use TextMate or any other text editor.

Enable PHP5 module

Search for the PHP module (/php5. Then it would be good idea to remove the comment from the following line in order to enable PHP to run with Apache: # LoadModule php5_module. The line should look like that after you’re done: LoadModule php5_module.

Enable mod_rewrite for permalinks

If you like beautiful URLs (permalinks) then make sure that you have mod_rewrite Apache module enabled. It should look something like that in your httpd.conf: LoadModule rewrite_module libexec/apache2/mod_rewrite.so

Change the user Apache runs as

I prefer not to use Mac OS X Snow Leopards default location for sites (the Sites folder in your Home folder). On my case I have a folder called “Development” in my Home folder that has all the development projects organized in there. So in this case it’s also good idea to run Apache under your own user in development environment (which your Snow Leopard installation most probably is). In your Apache configuration you’ll find that both user and group that Apache is run with is _www.

Find and change

to (replace Martin with your own users name)

Final check for virtual hosts

Make sure that you have these two lines at the end of your httpd.conf. Otherwise you’re most probably going to find out soon that your virtual hosts simply doesn’t work.

NameVirtualHost *:80
Include /private/etc/apache2/other/*.conf

Restart Apache

Now lets start (sudo apachectl start) or restart (sudo apachectl restart) the Apache web server and test if PHP is running by creating a file in your Web directory containing a call to the function phpinfo().

Apache

It works!

Mac

Final push – setup virtual hosts for your sites

At the time of writing this post I have 3 WordPress themes in development plus quite a few that I’m still maintaining. This kind of setup could easily become a mess and I really wouldn’t like that, now would I. Fortunately there’s a fix: create a virtual host for each WordPress installation.

Custom hostnames for your virtual server

I’m using a simple convention for my WordPress projects – projectname.wordpress.dev. Fortunately this keeps all WordPress installations in one clean convention which is also easy to deploy to production server (we’ll get to that later on).

To create your hostname just open up the hosts file with your text editor:

Write something like that at the end of the hosts file.

127.0.0.1 perfectline.wordpress.dev
127.0.0.1 www.perfectline.wordpress.dev

Done. You now have a hostname for your virtual host named perfectline.wordpress.dev which you can also access by www.perfectline.wordpress.dev if you like.

Configure a virtual host

Now that we are sure that we have PHP turned on, Apache working properly and even hostnames in place it’s time to create the actual virtual host that will be serving content for your WordPress installation.

First you need to create the necessary folders. In my case I’ve created Development folder where all my projects live plus one level to specify the type of the project (WordPress, Ruby, etc) and an actual WordPress project name:

Server
mkdir ~/Development
mkdir ~/Development/Wordpress
mkdir ~/Development/Wordpress/default

Create a new configuration file for your WordPress related virtual hosts:

Apache Php Server For Mac Windows 10

sudo vim /private/etc/apache2/other/wordpress.conf

Paste these lines into the newly created wordpress.conf. You need to change the file paths as you’ve set up the folders on your own system.

<virtualhost *:80>
ServerName wordpress.dev
ServerAlias www.wordpress.dev
DocumentRoot'/Volumes/Macintosh HD/Users/Martin/Development/Wordpress'
<directory'/Volumes/Macintosh HD/Users/Martin/Development/Wordpress'>
OptionsIndexesFollowSymLinks
AllowOverrideAll
Orderallow,deny
Allow from all
</directory>
</virtualhost>
<virtualhost *:80>
ServerName default.wordpress.dev
ServerAlias www.default.wordpress.dev
DocumentRoot'/Volumes/Macintosh HD/Users/Martin/Development/Wordpress/default'
<directory'/Volumes/Macintosh HD/Users/Martin/Development/Wordpress/default'>
OptionsIndexesFollowSymLinks
AllowOverrideAll
Orderallow,deny
Allow from all
</directory>
</virtualhost>

Apache Php Server For Macos

Now it’s time to restart Apache for one more time and we are set. Enjoy your newly installed WordPress development platform.