SlideShare a Scribd company logo
1 of 62
Download to read offline
&
                     PHP&Apache
             Why httpd.conf is your new BFF!

        Why httpd.conf is your new BFF!




PHP & Apache
Jeff Jones
AtlantaPHP
February 5th, 2009

                                               Jump by reebs*
Web “Solutions Stacks”
                    (Thanks Wikipedia!)

LAMP
 Linux Apache MySQL PHP

WAMP
 Windows Apache MySQL PHP

WIMP
 Windows IIS MySQL PHP

LAPP
 Linux Apache PostgreSQL PHP

FAPP
 FreeBSD Apache PostgreSQL PHP

     Common denominator? Apache.          “yellow lamp“
Apache Background



Since April 1996 Apache has been the most
popular HTTP server on the World Wide Web.
 As of December 2008 Apache served over
            51% of all websites.




                                  “Fort Apache by PhillipC”
Apache Software Foundation
      From ApacheCon 2007, Atlanta, GA

                                         “ASF by Ted Leung”
Apache HTTP Server




                 “Geronimo's Camp”
“a patchy server”




                Skydiving
          “Needs more duct tape”
Full-Featured Web Server
                     Some Features...
  Authentication, Authorization,        Environment Variables
                                  

        & Access Control                      Log Files

 CGI: Dynamic Content w/ CGI           Server Side Includes

       Configuration Files                 URL Mapping

      Content negotiation                 URL Rewriting




                                                    “Server” by existentist
Apache Configuration
                                                     By handjes




                       Contexts
Server config: Server wide httpd.conf and included files.
VirtualHost: <VirtualHost></VirtualHost>
Directory: Directory,DirectoryMatch,Files,FilesMatch
.htaccess: Per directory config files.
“PCI Slot” by Ryan




Apache Modules
httpd.conf
#httpd.conf
#Comment

#Directive
Include /usr/local/apache/conf/ssl.conf
Include /usr/local/apache/conf/vhosts/
Include /usr/local/apache/conf/a/*.conf

#Block Directive
<IfModule mod_rewrite.c>
  RewriteEngine on
</IfModule>                    “Floppy” by Marcin Wichary
.htaccess




            “Apple I & Altair” by Shiny Things
Scope Directives
       VirtualHost
       Directory / DirectoryMatch
       Files / FilesMatch
       Location/LocationMatch




                        “Radiance” by jurvetson
Virtual Host

<VirtualHost 10.1.2.3>
 ServerAdmin admin@example.com
 DocumentRoot /www/example.com
 ServerName example.com
 ErrorLog exlogs/error_log
 TransferLog exlogs/access_log
</VirtualHost>




                             “CNN Hologram” by Hard Seat Sleeper
Directory


<Directory />
</Directory>

<Directory /home/*>
</Directory>



                        “Dewey” by emdot
DirectoryMatch

<DirectoryMatch quot;^/www/.*/[0-9]{3}quot;>

</DirectoryMatch>
Files




<Files admin.cgi>
  Require group admin
</Files>
                        “Filed away..” by tpholland
FilesMatch




<FilesMatch quot;.(gif|jpe?g|png)$quot;>

</FilesMatch>
                                    “Alphabetical”
Location




           “Lost” by w00kie
LocationMatch




                “Little Blue Pins”
mod_core




           “Earth Core”
ErrorDocument             “Coat Check Fail”




#Output a customized message.
ErrorDocument 403 quot;No Access”

#Redirect to a local URL-path.
ErrorDocument 404 /errors/404.php

#Redirect to an external URL.
ErrorDocument 500 http://example.com/5.php
404 for pretty urls: Bad Idea!
           (Hello mod_rewrite!)




ErrorDocument 404 index.php       “Irony”
KeepAlive        “Zombie Jeff”




KeepAlive on
KeepAliveTimeout 2
MaxKeepAliveRequests 100
TimeOut




TimeOut 300
                    “Hang up.” by Robert Brook
UseCanonicalName




         ServerName example.com
         UseCanonicalName On

         Request: www.example.com/secure
         Redirects to: example.com/secure/


By Greyhorn
mod_php




    php_value / php_flag
●


    php_admin_value / php_admin_flag
●


    Contexts: All, Perdir, System.
●

                                       “php is cool” by Sara Golemon
PHP Config Contexts


    PHP_INI_ALL
●


    PHP_INI_PERDIR
●


    PHP_INI_SYSTEM
●
php_value




            “Gratuitous Bacon”




php_value name value
php_flag




php_flag name off|on      “Wave the flags”
php_admin_(flag|value)




php_admin_flag safe_mode on
                         “The Flag”
How is this useful?




                                         “Mixer Detail”



Set PHP Configuration per directory, uri, or file.
Prepend & Append

auto_prepend_file header.php
auto_append_file footer.php

auto_prepend_file none




                               “My Stapler”
include_path




          include_path=quot;.;/php/includesquot;

          include_path=quot;.;C:/php/includesquot;
“Gahuti Trail” by Jeff Jones
Turn that crap off!




php_flag magic_quotes_gpc off

php_flag register_globals off   “Sausage King”
Output Buffering




php_flag output_buffering on
php_value output_handler ob_tidyhandler
php_flag implicit_flushoff
                                 “AOL Coasters”
PHP Error Logging




log_errors stderr

php_value error_log /path/to/error.log
                                   “Telex Machine”
Display Errors




display_errors off
                     “Don't you feel secure?”
mod_env
                             “Capitol Reef National Park” by W. Staudt




    Access via $_ENV[] or getenv();
●
SetEnv




SetEnv webenv production
SetEnv webenv testing

SetEnv scriptdebug true
                           “Programmable Thermostat”
mod_mime




           “Mime Typing...”
AddType/Handler
AddType image/gif .gif

AddHandler php-script .php

#Not the best way:
AddType application/x-httpd-php .html

#better
AddHandler php-script .html

                                “Juggling Practice”
ForceType/SetHandler
ForceType application/x-httpd-php

<Files *.php>
SetHandler php-script
</Files>

<Location /images>
 ForceType image/jpeg
</Location>
mod_negotiation
URI: foo

URI: foo.jpeg
Content-type: image/jpeg; qs=0.8

URI: foo.gif
Content-type: image/gif; qs=0.5

URI: foo.txt
Content-type: text/plain; qs=0.01
                         “Tough Negotiations”
MultiViews
         Set as part of directory options
       MultiViews tracks down the best file.




<Directory /usr/local/www>
 Options Indexes MultiViews
</Directory>

foo
foo.html.es
foo.html.en.gz                                 “Sniffin'”
mod_rewrite




http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

The Definitive Guide to Apache mod_rewrite
 by Rich Bowen
 http://apress.com/book/view/9781590595619      “The Vortex”
Rewrite Rules

RewriteEngine On
RewriteBase /
RewriteCond /home/www/$1.php -f
RewriteRule ^(/?[^/.]+)/$ /$1.php




                               “Tapping a pencil”
RewriteRule Flags
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*website2.com
RewriteRule ^/?$ /website2.php [QSA, E=thedomain:website2,NC,L]

QSA = Query String Append

E = Set Environment Variables

NC=No Case

L=Last
Rewrites & Redirects



RewriteCond %{HTTP_HOST} !=www.domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Front Controller

The Front Controller Pattern is a
software design pattern listed in
several pattern catalogs. The pattern
relates to the design of web
applications. It quot;provides a
centralized entry point for handling
requests.quot;

        Source: Wikipedia
mod_auth
                   Other Auth & Related Modules

    mod_access
●


        Access control based on client hostname or IP address
    ●



    mod_auth_dbm
●


        User authentication using DBM files
    ●



    mod_auth_db
●


        User authentication using Berkeley DB files
    ●



    mod_auth_anon Apache 1.1 and up
●


        Anonymous user access to authenticated areas
    ●



    mod_digest
●


        MD5 authentication
    ●
Basic Auth
      .htpasswd                  .htgroups
username:md5(password)     phpers: Tetraboy bdole
Tetraboy:crypt(password)
bramsey:md5(WildGarlic)
bdole:crypt(lbp)




 AuthType Basic
 AuthName quot;Apache Loginsquot;
 AuthUserFile /usr/apasswd/.htpasswd
 AuthGroupFile /usr/apasswd/.htgroups

 #Examples
 Require user Tetraboy bramsey bdole
 Require group phpers
 Require valid-user
PHP HTTP Auth
$_SERVER['PHP_AUTH_USER'] & $_SERVER['PHP_AUTH_PW']


<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
   header('WWW-Authenticate: Basic realm=quot;My Realmquot;');
    header('HTTP/1.0 401 Unauthorized');
   echo 'Text to send if user hits Cancel button';
   exit;
} else {
   echo quot;<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>quot;;
   echo quot;<p>Your pass:{$_SERVER['PHP_AUTH_PW']}.</p>quot;;
}
?>
mod_headers

Header set|append|add header value
Header unset header

ErrorHeader
Setting Headers

<Files *.css>
SetHandler php-script
Header Set Content-type “text/css”
</Files>
PHP's Apache Extension
    apache_child_terminate — Terminate apache process after this request
●



    apache_get_modules — Get a list of loaded Apache modules
●



    apache_get_version — Fetch Apache version
●



    apache_getenv — Get an Apache subprocess_env variable
●



    apache_lookup_uri — Perform a partial request on a URI, returns info.
●



    apache_note — Get and set apache request notes
●



    apache_request_headers — Fetch all HTTP request headers
●



    apache_reset_timeout — Reset the Apache write timer
●



    apache_response_headers — Fetch all HTTP response headers
●



    apache_setenv — Set an Apache subprocess_env variable
●



    ascii2ebcdic — Translate string from ASCII to EBCDIC
●



    ebcdic2ascii — Translate string from EBCDIC to ASCII
●



    getallheaders — Fetch all HTTP request headers
●


                                                              “Trilions Served”
    virtual — Perform an Apache sub-request
●
apache_child_terminate();




                       “Terminator
apache_lookup_uri
<?php
  info = apache_lookup_uri('index.php?var=value');
  var_dump($info);
?>                     stdClass Object
                       (
                           [status] => 200
                           [the_request] => GET /dir/file.php HTTP/1.1
                           [method] => GET
                           [mtime] => 0
                           [clength] => 0
                           [chunked] => 0
                           [content_type] => application/x-httpd-php
                           [no_cache] => 0
                           [no_local_copy] => 1
                           [unparsed_uri] => /dir/index.php?var=value
                           [uri] => /dir/index.php
                           [filename] => /home/htdocs/dir/index.php
                           [args] => var=value
                           [allowed] => 0
                           [sent_bodyct] => 0
                           [bytes_sent] => 0
                           [request_time] => 1074282764
                       )
Apache HTTP Headers

<?php


apache_request_headers();


apache_response_headers();


?>
Tip of Iceberg
     There are around 100 modules for Apache 1.3.x
●




     There are about 300 modules for Apache 2.x
●




     mod_rewrite can do amazing stuff with URIs
●




     Apache can be expanded with custom modules!
●




    “Ice Breaker”
“Books by Bowen”




         Apache is a Web Server.




    Don't rewrite a web server in PHP.
●



         Unless you really have to.
     ●
More info?
    http://httpd.apache.org/
●


    irc.freenode.net #apache
●


    http://planetapache.org/
●


    http://apache-cookbook.com/
●




                                  “Theo Thinks”
Questions?

    Why is the sky blue?
●


    Why is the moon white?
●


    Why is the grass green?
●


    Where do babies come from?
●




                                 “Downtown ATL”

More Related Content

What's hot

A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webWallace Reis
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance毅 吕
 
Introduction to Web Programming with Perl
Introduction to Web Programming with PerlIntroduction to Web Programming with Perl
Introduction to Web Programming with PerlDave Cross
 
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in PerlNaveen Gupta
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparisonHiroshi Nakamura
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHPJonathan Klein
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversTatsuhiko Miyagawa
 
Making the Most of HTTP In Your Apps
Making the Most of HTTP In Your AppsMaking the Most of HTTP In Your Apps
Making the Most of HTTP In Your AppsBen Ramsey
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Building a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQueryBuilding a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
PHP language presentation
PHP language presentationPHP language presentation
PHP language presentationAnnujj Agrawaal
 

What's hot (20)

A reviravolta do desenvolvimento web
A reviravolta do desenvolvimento webA reviravolta do desenvolvimento web
A reviravolta do desenvolvimento web
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 
Introduction to Web Programming with Perl
Introduction to Web Programming with PerlIntroduction to Web Programming with Perl
Introduction to Web Programming with Perl
 
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in Perl
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
Api Design
Api DesignApi Design
Api Design
 
Php on Windows
Php on WindowsPhp on Windows
Php on Windows
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparison
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
 
Making the Most of HTTP In Your Apps
Making the Most of HTTP In Your AppsMaking the Most of HTTP In Your Apps
Making the Most of HTTP In Your Apps
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Os Bunce
Os BunceOs Bunce
Os Bunce
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Building a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQueryBuilding a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Introduction to Flask Micro Framework
Introduction to Flask Micro FrameworkIntroduction to Flask Micro Framework
Introduction to Flask Micro Framework
 
PHP language presentation
PHP language presentationPHP language presentation
PHP language presentation
 

Viewers also liked

httpd — Apache Web Server
httpd — Apache Web Serverhttpd — Apache Web Server
httpd — Apache Web Serverwebhostingguy
 
Apache Web Server Administration
Apache Web Server AdministrationApache Web Server Administration
Apache Web Server Administrationwebhostingguy
 
Apache HTTPd Server 2.2 Presentation
Apache HTTPd Server 2.2 PresentationApache HTTPd Server 2.2 Presentation
Apache HTTPd Server 2.2 Presentationultimatetux
 
Learn how to develop for Android, beyond the Hello World android app - Cape T...
Learn how to develop for Android, beyond the Hello World android app - Cape T...Learn how to develop for Android, beyond the Hello World android app - Cape T...
Learn how to develop for Android, beyond the Hello World android app - Cape T...Joseph Kandi
 
Apache httpd 2.4 Reverse Proxy: The Hidden Gem
Apache httpd 2.4 Reverse Proxy: The Hidden GemApache httpd 2.4 Reverse Proxy: The Hidden Gem
Apache httpd 2.4 Reverse Proxy: The Hidden GemJim Jagielski
 
ApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
ApacheConNA 2015: Apache httpd 2.4 Reverse ProxyApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
ApacheConNA 2015: Apache httpd 2.4 Reverse ProxyJim Jagielski
 
Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014bryan_call
 

Viewers also liked (10)

httpd — Apache Web Server
httpd — Apache Web Serverhttpd — Apache Web Server
httpd — Apache Web Server
 
Apache Web Server Administration
Apache Web Server AdministrationApache Web Server Administration
Apache Web Server Administration
 
Apache HTTPd Server 2.2 Presentation
Apache HTTPd Server 2.2 PresentationApache HTTPd Server 2.2 Presentation
Apache HTTPd Server 2.2 Presentation
 
Learn how to develop for Android, beyond the Hello World android app - Cape T...
Learn how to develop for Android, beyond the Hello World android app - Cape T...Learn how to develop for Android, beyond the Hello World android app - Cape T...
Learn how to develop for Android, beyond the Hello World android app - Cape T...
 
Apache
ApacheApache
Apache
 
Apache httpd 2.4 Reverse Proxy: The Hidden Gem
Apache httpd 2.4 Reverse Proxy: The Hidden GemApache httpd 2.4 Reverse Proxy: The Hidden Gem
Apache httpd 2.4 Reverse Proxy: The Hidden Gem
 
Apache HTTP Server
Apache HTTP ServerApache HTTP Server
Apache HTTP Server
 
Chap 19 web
Chap 19 webChap 19 web
Chap 19 web
 
ApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
ApacheConNA 2015: Apache httpd 2.4 Reverse ProxyApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
ApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
 
Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014Choosing A Proxy Server - Apachecon 2014
Choosing A Proxy Server - Apachecon 2014
 

Similar to Apache and PHP: Why httpd.conf is your new BFF!

Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by CapistranoTasawr Interactive
 
Running PHP on a Java container
Running PHP on a Java containerRunning PHP on a Java container
Running PHP on a Java containernetinhoteixeira
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009Helgi Þormar Þorbjörnsson
 
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019Viktor Todorov
 
ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4Jim Jagielski
 
Heavy Web Optimization: Backend
Heavy Web Optimization: BackendHeavy Web Optimization: Backend
Heavy Web Optimization: BackendVõ Duy Tuấn
 
WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011Alfred Ayache
 
Systems Automation with Puppet
Systems Automation with PuppetSystems Automation with Puppet
Systems Automation with Puppetelliando dias
 
Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Hyun-Mook Choi
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp HamiltonPaul Bearne
 
Tips
TipsTips
Tipsmclee
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & ScalabilityJoseph Scott
 
Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Dana Luther
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.catPablo Godel
 
Converting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - CascadiaConverting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - CascadiaDana Luther
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment Evaldo Felipe
 

Similar to Apache and PHP: Why httpd.conf is your new BFF! (20)

Deploy Rails Application by Capistrano
Deploy Rails Application by CapistranoDeploy Rails Application by Capistrano
Deploy Rails Application by Capistrano
 
Running PHP on a Java container
Running PHP on a Java containerRunning PHP on a Java container
Running PHP on a Java container
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009Website releases made easy with the PEAR installer, OSCON 2009
Website releases made easy with the PEAR installer, OSCON 2009
 
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
 
ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4ApacheCon 2014 - What's New in Apache httpd 2.4
ApacheCon 2014 - What's New in Apache httpd 2.4
 
Heavy Web Optimization: Backend
Heavy Web Optimization: BackendHeavy Web Optimization: Backend
Heavy Web Optimization: Backend
 
WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011
 
Systems Automation with Puppet
Systems Automation with PuppetSystems Automation with Puppet
Systems Automation with Puppet
 
Nginx + PHP
Nginx + PHPNginx + PHP
Nginx + PHP
 
Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp Hamilton
 
Lumen
LumenLumen
Lumen
 
Tips
TipsTips
Tips
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & Scalability
 
Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Converting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - CascadiaConverting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - Cascadia
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment
 

Recently uploaded

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Recently uploaded (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

Apache and PHP: Why httpd.conf is your new BFF!

  • 1. & PHP&Apache Why httpd.conf is your new BFF! Why httpd.conf is your new BFF! PHP & Apache Jeff Jones AtlantaPHP February 5th, 2009 Jump by reebs*
  • 2. Web “Solutions Stacks” (Thanks Wikipedia!) LAMP Linux Apache MySQL PHP WAMP Windows Apache MySQL PHP WIMP Windows IIS MySQL PHP LAPP Linux Apache PostgreSQL PHP FAPP FreeBSD Apache PostgreSQL PHP Common denominator? Apache. “yellow lamp“
  • 3. Apache Background Since April 1996 Apache has been the most popular HTTP server on the World Wide Web. As of December 2008 Apache served over 51% of all websites. “Fort Apache by PhillipC”
  • 4. Apache Software Foundation From ApacheCon 2007, Atlanta, GA “ASF by Ted Leung”
  • 5. Apache HTTP Server “Geronimo's Camp”
  • 6. “a patchy server” Skydiving “Needs more duct tape”
  • 7. Full-Featured Web Server Some Features... Authentication, Authorization, Environment Variables   & Access Control Log Files  CGI: Dynamic Content w/ CGI  Server Side Includes  Configuration Files  URL Mapping  Content negotiation  URL Rewriting “Server” by existentist
  • 8. Apache Configuration By handjes Contexts Server config: Server wide httpd.conf and included files. VirtualHost: <VirtualHost></VirtualHost> Directory: Directory,DirectoryMatch,Files,FilesMatch .htaccess: Per directory config files.
  • 9. “PCI Slot” by Ryan Apache Modules
  • 10. httpd.conf #httpd.conf #Comment #Directive Include /usr/local/apache/conf/ssl.conf Include /usr/local/apache/conf/vhosts/ Include /usr/local/apache/conf/a/*.conf #Block Directive <IfModule mod_rewrite.c> RewriteEngine on </IfModule> “Floppy” by Marcin Wichary
  • 11. .htaccess “Apple I & Altair” by Shiny Things
  • 12. Scope Directives VirtualHost Directory / DirectoryMatch Files / FilesMatch Location/LocationMatch “Radiance” by jurvetson
  • 13. Virtual Host <VirtualHost 10.1.2.3> ServerAdmin admin@example.com DocumentRoot /www/example.com ServerName example.com ErrorLog exlogs/error_log TransferLog exlogs/access_log </VirtualHost> “CNN Hologram” by Hard Seat Sleeper
  • 16. Files <Files admin.cgi> Require group admin </Files> “Filed away..” by tpholland
  • 18. Location “Lost” by w00kie
  • 19. LocationMatch “Little Blue Pins”
  • 20. mod_core “Earth Core”
  • 21. ErrorDocument “Coat Check Fail” #Output a customized message. ErrorDocument 403 quot;No Access” #Redirect to a local URL-path. ErrorDocument 404 /errors/404.php #Redirect to an external URL. ErrorDocument 500 http://example.com/5.php
  • 22. 404 for pretty urls: Bad Idea! (Hello mod_rewrite!) ErrorDocument 404 index.php “Irony”
  • 23. KeepAlive “Zombie Jeff” KeepAlive on KeepAliveTimeout 2 MaxKeepAliveRequests 100
  • 24. TimeOut TimeOut 300 “Hang up.” by Robert Brook
  • 25. UseCanonicalName ServerName example.com UseCanonicalName On Request: www.example.com/secure Redirects to: example.com/secure/ By Greyhorn
  • 26. mod_php php_value / php_flag ● php_admin_value / php_admin_flag ● Contexts: All, Perdir, System. ● “php is cool” by Sara Golemon
  • 27. PHP Config Contexts PHP_INI_ALL ● PHP_INI_PERDIR ● PHP_INI_SYSTEM ●
  • 28. php_value “Gratuitous Bacon” php_value name value
  • 29. php_flag php_flag name off|on “Wave the flags”
  • 31. How is this useful? “Mixer Detail” Set PHP Configuration per directory, uri, or file.
  • 32. Prepend & Append auto_prepend_file header.php auto_append_file footer.php auto_prepend_file none “My Stapler”
  • 33. include_path include_path=quot;.;/php/includesquot; include_path=quot;.;C:/php/includesquot; “Gahuti Trail” by Jeff Jones
  • 34. Turn that crap off! php_flag magic_quotes_gpc off php_flag register_globals off “Sausage King”
  • 35. Output Buffering php_flag output_buffering on php_value output_handler ob_tidyhandler php_flag implicit_flushoff “AOL Coasters”
  • 36. PHP Error Logging log_errors stderr php_value error_log /path/to/error.log “Telex Machine”
  • 37. Display Errors display_errors off “Don't you feel secure?”
  • 38. mod_env “Capitol Reef National Park” by W. Staudt Access via $_ENV[] or getenv(); ●
  • 39. SetEnv SetEnv webenv production SetEnv webenv testing SetEnv scriptdebug true “Programmable Thermostat”
  • 40. mod_mime “Mime Typing...”
  • 41. AddType/Handler AddType image/gif .gif AddHandler php-script .php #Not the best way: AddType application/x-httpd-php .html #better AddHandler php-script .html “Juggling Practice”
  • 42. ForceType/SetHandler ForceType application/x-httpd-php <Files *.php> SetHandler php-script </Files> <Location /images> ForceType image/jpeg </Location>
  • 43. mod_negotiation URI: foo URI: foo.jpeg Content-type: image/jpeg; qs=0.8 URI: foo.gif Content-type: image/gif; qs=0.5 URI: foo.txt Content-type: text/plain; qs=0.01 “Tough Negotiations”
  • 44. MultiViews Set as part of directory options MultiViews tracks down the best file. <Directory /usr/local/www> Options Indexes MultiViews </Directory> foo foo.html.es foo.html.en.gz “Sniffin'”
  • 45. mod_rewrite http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html http://httpd.apache.org/docs/1.3/misc/rewriteguide.html The Definitive Guide to Apache mod_rewrite by Rich Bowen http://apress.com/book/view/9781590595619 “The Vortex”
  • 46. Rewrite Rules RewriteEngine On RewriteBase / RewriteCond /home/www/$1.php -f RewriteRule ^(/?[^/.]+)/$ /$1.php “Tapping a pencil”
  • 47. RewriteRule Flags RewriteEngine On RewriteCond %{HTTP_HOST} ^.*website2.com RewriteRule ^/?$ /website2.php [QSA, E=thedomain:website2,NC,L] QSA = Query String Append E = Set Environment Variables NC=No Case L=Last
  • 48. Rewrites & Redirects RewriteCond %{HTTP_HOST} !=www.domain.com RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
  • 49. Front Controller The Front Controller Pattern is a software design pattern listed in several pattern catalogs. The pattern relates to the design of web applications. It quot;provides a centralized entry point for handling requests.quot; Source: Wikipedia
  • 50. mod_auth Other Auth & Related Modules mod_access ● Access control based on client hostname or IP address ● mod_auth_dbm ● User authentication using DBM files ● mod_auth_db ● User authentication using Berkeley DB files ● mod_auth_anon Apache 1.1 and up ● Anonymous user access to authenticated areas ● mod_digest ● MD5 authentication ●
  • 51. Basic Auth .htpasswd .htgroups username:md5(password) phpers: Tetraboy bdole Tetraboy:crypt(password) bramsey:md5(WildGarlic) bdole:crypt(lbp) AuthType Basic AuthName quot;Apache Loginsquot; AuthUserFile /usr/apasswd/.htpasswd AuthGroupFile /usr/apasswd/.htgroups #Examples Require user Tetraboy bramsey bdole Require group phpers Require valid-user
  • 52. PHP HTTP Auth $_SERVER['PHP_AUTH_USER'] & $_SERVER['PHP_AUTH_PW'] <?php if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm=quot;My Realmquot;'); header('HTTP/1.0 401 Unauthorized'); echo 'Text to send if user hits Cancel button'; exit; } else { echo quot;<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>quot;; echo quot;<p>Your pass:{$_SERVER['PHP_AUTH_PW']}.</p>quot;; } ?>
  • 53. mod_headers Header set|append|add header value Header unset header ErrorHeader
  • 54. Setting Headers <Files *.css> SetHandler php-script Header Set Content-type “text/css” </Files>
  • 55. PHP's Apache Extension apache_child_terminate — Terminate apache process after this request ● apache_get_modules — Get a list of loaded Apache modules ● apache_get_version — Fetch Apache version ● apache_getenv — Get an Apache subprocess_env variable ● apache_lookup_uri — Perform a partial request on a URI, returns info. ● apache_note — Get and set apache request notes ● apache_request_headers — Fetch all HTTP request headers ● apache_reset_timeout — Reset the Apache write timer ● apache_response_headers — Fetch all HTTP response headers ● apache_setenv — Set an Apache subprocess_env variable ● ascii2ebcdic — Translate string from ASCII to EBCDIC ● ebcdic2ascii — Translate string from EBCDIC to ASCII ● getallheaders — Fetch all HTTP request headers ● “Trilions Served” virtual — Perform an Apache sub-request ●
  • 56. apache_child_terminate(); “Terminator
  • 57. apache_lookup_uri <?php info = apache_lookup_uri('index.php?var=value'); var_dump($info); ?> stdClass Object ( [status] => 200 [the_request] => GET /dir/file.php HTTP/1.1 [method] => GET [mtime] => 0 [clength] => 0 [chunked] => 0 [content_type] => application/x-httpd-php [no_cache] => 0 [no_local_copy] => 1 [unparsed_uri] => /dir/index.php?var=value [uri] => /dir/index.php [filename] => /home/htdocs/dir/index.php [args] => var=value [allowed] => 0 [sent_bodyct] => 0 [bytes_sent] => 0 [request_time] => 1074282764 )
  • 59. Tip of Iceberg There are around 100 modules for Apache 1.3.x ● There are about 300 modules for Apache 2.x ● mod_rewrite can do amazing stuff with URIs ● Apache can be expanded with custom modules! ● “Ice Breaker”
  • 60. “Books by Bowen” Apache is a Web Server. Don't rewrite a web server in PHP. ● Unless you really have to. ●
  • 61. More info? http://httpd.apache.org/ ● irc.freenode.net #apache ● http://planetapache.org/ ● http://apache-cookbook.com/ ● “Theo Thinks”
  • 62. Questions? Why is the sky blue? ● Why is the moon white? ● Why is the grass green? ● Where do babies come from? ● “Downtown ATL”