Setting up XAMPP on Mac OS X

xampp on macos
image_pdfimage_print

Hello, dear readers of our blog! Many people work on Windows and use Denwer as a local server. On our web-site there is a little article for those who want to set up access to MySQL for Denwer from a local network. In this article we will talk about setting up XAMPP for the Mac OS X operational system. You will be able to avoid mistakes while setting up XAMPP and know how to change configuration of the local Apache web-server quickly and easily. You might know that XAMPP is a cross-platform building of a web-server containing Apache, MySQL, PHP script interpreter and so forth, which allows to launch a fully functional web-server. Let’s consider which settings you need to do to make your server properly work.

Content

Change of a Configuration File of Apacher Server

As we know, XAMPP consists of Apache web-server. A configuration file of Apache server is called httpd.conf. Let’s change it. usually it’s at /Applications/XAMPP/xamppfiles/etc/httpd.conf. We need to open it using Finder in the program TextEdit and edit it:

  1. The first thing we do is change the user which will start up the server. Let’s find the following lines:
          <IfModule unixd_module>
             User daemon
             Group daemon
         </IfModule>
    

    Now, we need to replace User daemon with User YourName. Replace YourName with a user name in the Mac OS X system. We’ll have the following:

          <IfModule unixd_module>
             User YourName
             Group daemon
         </IfModule>
    

    Unless we change the user, there will appear the following warning at the startup of our local website:

          Access forbidden!
        
          You don't have permission to access the requested directory. 
          There is either no index document or the directory is read-protected.
        
          If you think this is a server error, please contact the webmaster.
          Error 403
    
  2. We should delete # near the word Include.
            # Virtual hosts
            Include etc/extra/httpd-vhosts.conf
    

    This step is necessary to connect the configuration file httpd-vhosts.conf in which we will save our virtual hosts. That is there we will write paths that will indicate the location of our local websites.

  3. It is possible to write your e-mail, using the following directive:
            ServerAdmin [email protected]
    

    Instead of [email protected] indicate your electronic address. Should any errors occur users will write about them to this address. It will be shown on an error page.

  4. In the directive DocumentRoot we need to indicate the path which will contain folders with our local websites. The following path is used as a default:
          DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
    

    But we can write another one, for instance this:

          DocumentRoot "/Users/YourName/Dropbox/Public/sites"
    

    It is convinient to store all files in Dropbox, because in this way they can be accessible from other computers. Replace YourName with your username in the Mac OS X system.

  5. In the same manner we are changing the path in this directive:
          <Directory "/Users/YourName/Dropbox/Public/sites">
            Options Indexes Includes FollowSymLinks
            AllowOverride All
            order allow,deny
            allow from all
            Require all granted
          </Directory>
    

    Write all directives inside the tag Directory, in order to avoid errors at the operation of Apache server. We must replace directive AllowOverride None with AllowOverride All everwhere it appears in the file httpd.conf.

  6. In order we have an opportunity to work with file .htaccess in the mode mod_rewrite, we need to insert the following directive at the end of the file httpd.conf inside a folder of each individual virtual host:
          AccessFileName .htaccess
    

    If you wish to change .htaccess for example with htaccess.txt, you need to delete # near the word Include:

          # Various default settings
          Include etc/extra/httpd-default.conf
    

    Now, we need to write the following at the end of file httpd.conf:

          AccessFileName htaccess.txt
    

    This is especially convinient, if settings of your local website in the file .htaccess differ from the settings on a remote server. If you use both files .htaccess and htaccess.txt, there is no risk that your website will stop working as a result of accidental overwriting of a remote file with a local one.

Remember: you need to restart the local web-server Apache after each change of the file httpd.conf!

Adding Hosts into File httpd-vhosts.conf

In order to add virtual hosts, it is necessary to change file httpd-vhosts.conf. This configuration file is usually located at /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf. We need to open it using Finder in the program TextEdit and edit it:

  1. At first, let’s add the following directive:
          NameVirtualHost *:80
    

    This directive contains all IP (because * is used) and port 80, which is connected with named virtual hosts. Directive NameVirtualHost is used for arranging virtual hosts, based on names. In this case ip-address indicated in directive NameVirtualHost and in containers VirtualHost coincides.

  2. Now, we need to write our containers VirtualHost. At first, let’s fill in the container that keeps http://localhost operating:
      <virtualhost *:80>
      DocumentRoot "/Users/YourName/Dropbox/Public/sites"
      ServerName localhost
      <Directory "/Users/YourName/Dropbox/Public/sites">
              Options Indexes FollowSymLinks Includes execCGI
              AllowOverride All
              Order Allow,Deny
              Allow From All
      </Directory>
      </virtualhost>

Replace YourName with a user name in the Mac OS X system.

 

  • Now it’s time to add our virtual host. Let’s name it softmaker.kz:
          <virtualhost *:80>
            DocumentRoot "/Users/YourName/Dropbox/Public/sites/softmaker.kz"
            ServerName softmaker.kz
                  <Directory "/Users/YourName/Dropbox/Public/sites/softmaker.kz">
                      Options Indexes FollowSymLinks Includes execCGI
                      AllowOverride All 
                      Order Allow,Deny
                      Allow From All
                  </Directory>
                  ServerAdmin [email protected]
                  ErrorLog "logs/softmaker.kz-error_log"
                  CustomLog "logs/softmaker.kz-access_log" common
          </virtualhost>
    

    Also, change YourName with a user name in the Mac OS X system. We must replace directive AllowOverride None with AllowOverride All otherwise Apache server will not read file .htaccess and the following error will appear:

          Object not found!
          
          The requested URL was not found on this server. 
          The link on the referring page seems to be wrong or outdated. 
          Please inform the author of that page about the error.
          
          If you think this is a server error, please contact the webmaster.
          Error 404
    

    Restart your Apache server, and virtual hosts will be added.

 

Adding Hosts into File /etc/hosts/

For proper operation, it is necessary to indicate the Mac OS X system where these virtual hosts are located. We need to open file /etc/hosts in the terminal:

  sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts

Let’s add the following line at the end of file /etc/hosts:

127.0.0.1 softmaker.kz

In the same manner it is possible to add other virtual hosts.

PHP Code Debugging Setting in File php.ini

PHP configuration file is called php.ini. Usually it is located at /Applications/XAMPP/xamppfiles/etc/php.ini. We need to open it using Finder in the program TextEdit and edit it. If you can’t find a section [xdebug], you can write it at the end of the file:

  [xdebug]
   
  xdebug.default_enable=1
   
  xdebug.remote_enable=1
  xdebug.remote_handler=dbgp
  xdebug.remote_host=localhost
  xdebug.remote_port=9000
  xdebug.remote_autostart=1
  xdebug.max_nesting_level = 100
   
  zend_extension="/Applications/XAMPP/xamppfiles/lib/php/php5/xdebug.so"

In the very last line zend_extension we need to indicate path to the file xdebug.so. This file is not in the XAMPP distribution. It is necessary to download it and indicate in this line the path where it is located. In addition, there is an individual file for each version of PHP. Also you can read how to configure php.ini on Windows.

If you configure Apache server and PHP, that are already built in Mac OS X, configuring is the same, except for the need to edit these files in a terminal and the fact that they are located in other places.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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