Site menu:

Tags

Links:

Meta

Site search

Recent Posts

RSS Reading

RSS Netflix Q

Setup a PHP.net mirror on OSX

Many of us PHP developers use php.net often. The mirrors available are pretty good, but what if you don’t have a net connection. Ah, OSX already has Apache and PHP installed. This combined with the handy way php.net allows anyone to have a mirror can save your life.

  1. We need to get a copy of the website. Run this to synchronize you computer with the current site.
    rsync -avzC --timeout=600 --delete --delete-after  \
    --include='manual/en/' --include='manual/en/**'  \
    --exclude='manual/**' --exclude='distributions/manual/**'  \
    --exclude='distributions/**' --exclude='extra/**' \
    rsync.php.net::phpweb /Library/WebServer/Documents/php
    
  2. Add SQLite support if necessary. pear install SQLite
  3. Setup the Apache VirtualHost:
    Save this in a file called /etc/httpd/users/php.conf

    NameVirtualHost *:80
    <VirtualHost *:80>
    </VirtualHost>
    <VirtualHost *:80>
         ServerName php
         ServerAdmin webmaster@domainname.com                                                                  
    
         # Webroot of PHP mirror site
         DocumentRoot /Library/WebServer/Documents/php                                                       
    
         # These PHP settings are necessary to run a mirror
         php_value include_path .:/Library/WebServer/Documents/php/include
         php_flag register_globals on                                                                        
    
         # Log server activity
         ErrorLog /var/log/httpd/php-error_log
         TransferLog /var/log/httpd/php-access_log                                                           
    
         # Set directory index
         DirectoryIndex index.php index.html                                                                 
    
         # Do not display directory listings if index is not present,
         # and do not try to match filenames if extension is omitted
         Options -Indexes -MultiViews                                                                        
    
         # Handle errors with local error handler script
         ErrorDocument 401 /error.php
         ErrorDocument 403 /error.php
         ErrorDocument 404 /error.php                                                                        
    
         # Add types not specified by Apache by default
         AddType application/octet-stream .chm .bz2 .tgz
         AddType application/x-pilot .prc .pdb                                                               
    
         # Set mirror's preferred language here
         SetEnv MIRROR_LANGUAGE "en"
         # Turn spelling support off (which would break URL shortcuts)
         <IfModule mod_speling.c>
           CheckSpelling Off
         </IfModule>
    </VirtualHost>
    
  4. run sudo apachectl graceful
  5. Add a php alias to you hosts file. Edit /etc/hosts. Add “php” to the end of the line that starts with “127.0.0.1″
  6. In order to get updates you can run the first command any time you want, or if you are running Tiger you can copy this file into ~/Library/LaunchAgents/net.php.mirror.plist. This will cause it to be updated daily.

Write a comment