Tag Archive: Apache


It’s something to do with using PHP FPM / Fast CGI, and auth headers being disable for that.

So we add this to the directory entry of the .htaccess:

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

You now have your missing header back!

Advertisements

As you readers probably know, I can’t stand XAMPP and MAMP, being two steaming piles of crap, and have long advocated that you set up VirtualBox & Vagrant, then head over to http://www.puphpet.com, fill in the forms to configure your VM,  generate the config.yaml, and then unzip it and run ‘vagrant up’ to install it. Brilliant so far.

Yesterday I had a total downer of a day, trying to run an old legacy PHP 5.3 app. PuPHPet doesn’t have the EOL PHP 5.3, so at first I settled as a one off for MAMP, but it was slow and horrible.

Then I thought, wait! If I don’t configure Apache or PHP in puphpet, I could get a box up and install 5.3 myself. That’s when I discovered the awesomeness of the puphpet/files folder.

The only thing I used in there was the ssh keys. But there are empty folders waiting for .sh files (shell scripts) to be dropped in.

So for this box, I created exec-once/install-stuff.sh which contained the following:

#!/bin/bash
yum -y install httpd php
yum -y install php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml

Then upon running vagrant provision, it not only looked for changes in config.yaml, but it checks for changes in these files too!

I then made set-vhosts.sh, and import-database.sh, which look like these:

#!/bin/bash
echo "
===========================================
Adding vhosts to /etc/httpd/conf/httpd.conf
===========================================
"
echo "
<VirtualHost *:80>

   DocumentRoot /var/www/fife/web
   ServerName fife
   ErrorLog /var/www/fife/log/error.log

   <Directory "/var/www/fife">
      Options -Indexes +FollowSymLinks
      Order allow,deny
      Allow from all
      AllowOverride All
  </Directory>

</VirtualHost>
" >> /etc/httpd/conf/httpd.conf

And …

#!/bin/bash
mysql -u root --password=123 --database=fortdev < /var/www/fife/data/sql_scripts/symf_fortdev.sql

I take it by now you get the idea! So now you can totally destroy your VM, and put any customisations in these shell scripts, so your full setup can be back up in 5 minutes flat with a vagrant up and vagrant provision!!!

You can then also start thinking about using puPHPet for deploying your setup to your production server 🙂 There’s a vagrant plugin called Vagrant Managed Servers, which will take care of that for you. https://github.com/tknerr/vagrant-managed-servers . I haven’t looked at it yet, but of course you can expect a blog post on it here when I figure it all out!!

If you’ve ever used a self signed SSL certificate, you’ll know that although the connection is secure, you don’t get the full green padlock in the browser. You’re about to fix that, and speed your website up at the same time.

The secret is to pump your DNS through Cloudflare! http://www.cloudflare.com. If you visit there and sign up, you can add your domain names and point them to your server. By setting up Cloudflare, your site will improve in speed due to cacheing, and be more secure from DDOS attacks.

The first step is to create your SSL certificate. Log in to your server, and run the following commands as the root user:

➜ mcleandigital openssl genrsa -out "/home/mcleandigital/ssl.key" 2048 
Generating RSA private key, 2048 bit long modulus
................................................................+++
...............................................+++
e is 65537 (0x10001)
➜ mcleandigital openssl req -new -key "/home/mcleandigital/ssl.key" -out "/home/mcleandigital/ssl.csr" 
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:GB
State or Province Name (full name) [Some-State]:Scotland
Locality Name (eg, city) []:Glasgow
Organization Name (eg, company) [Internet Widgits Pty Ltd]:McLean Digital Limited
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:*.mcleandigital.co.uk
Email Address []:derek@mcleandigital.co.uk

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:McLean Digital Limited
➜ mcleandigital openssl x509 -req -days 1095 -in "/home/mcleandigital/ssl.csr" -signkey "/home/mcleandigital/ssl.key" -out "/home/mcleandigital/ssl.crt" 
Signature ok
subject=/C=GB/ST=Scotland/L=Glasgow/O=McLean Digital Limited/CN=*.mcleandigital.co.uk/emailAddress=derek@mcleandigital.co.uk
Getting Private key

The above output has generated the SSL certificate. Next step is to set your virtual hosts:

<VirtualHost *:80>
    ServerName mcleandigital.co.uk
    RedirectPermanent / https://mcleandigital.co.uk
</VirtualHost>

<VirtualHost *:443>
        ServerName mcleandigital.co.uk

        ServerAdmin webmaster@mcleandigital.co.uk
        DocumentRoot /var/www/mcleandigital.co.uk/public

        SSLEngine on
        SSLCertificateKeyFile /home/mcleandigital/ssl.key
        SSLCertificateFile /home/mcleandigital/ssl.crt

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory "/var/www/mcleandigital.co.uk/">
                Options -Indexes +FollowSymLinks
                Order allow,deny
                Allow from all
                AllowOverride All
                Require all granted
        </Directory>
</VirtualHost>

The above configuration redirects all port 80 traffic to port 443. Now if you restart the server, you will be able to access your website securely, however, the green padlock is not showing. This is expected as usually you would pay for a certificate from a certificate authority (CA) .

Now the fun part. Sign in to cloudflare.com, and add your website.They give you instructions, and it’s pretty easy to setup.

If your site is hosted on a different server than your hosting company, you need to change the DNS on the domain name hosting provider to point to cloudflare, and not directly to your server. So a request will hit the domain company, which DNS sends to cloudflare, and the DNS on cloudflare points to the IP of your server.

Lastly, in cloudflare, click on the crypto tab, and set SSL to full. The great thing is, you get the cloudflare certificate presented to the end user, and our self signed certificate is hidden away behind cloudflare!

It turns out domain validated SSL’s will be free from December 3rd anyway (checkout https://letsencrypt.org/), however, this may still be the better option due to all the nice free features cloudflare offers! As always, have fun!

I’m making some Apache redirects from an old domain to a new domain. I need the old domains blog posts to redirect to the new domain. So I need the WordPress permalinks.

In MySQL, you can say the following to get your permalinks.

SELECT wpp.post_title, wpp.guid,wpp.post_date,
CONCAT(wpo_su.option_value,
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
    wpo.option_value,'%year%', date_format(wpp.post_date,'%Y'))
    ,'%monthnum%',date_format(wpp.post_date,'%m'))
    ,'%day%',date_format(wpp.post_date,'%d'))
    ,'%postname%',wpp.post_name )
    ,'%category%',wpc.slug )
    ,'%post_id%', wpp.id)
) as permalink
FROM wp_posts wpp
INNER JOIN wp_options wpo ON wpo.option_name='permalink_structure'
INNER JOIN wp_options wpo_su ON wpo_su.option_name='siteurl'
INNER JOIN (
    SELECT wtr.object_id ID, max(wpt.slug) slug
    FROM wp_term_relationships wtr
    INNER JOIN wp_term_taxonomy wtt ON wtt.term_taxonomy_id=wtr.term_taxonomy_id AND wtt.taxonomy='category'
    INNER JOIN wp_terms wpt on wpt.term_id=wtt.term_id
    GROUP BY  wtr.object_id
) wpc ON wpc.ID=wpp.ID
WHERE wpp.post_type = 'post'
AND wpp.post_status = 'publish'
ORDER BY wpp.post_date DESC

If you aren’t using the built in php server for development, and like me you are using a vagrant box configured by puPHPet, this will save you a lot of wasted time wondering why you get 401s and 403s when you aren’t expecting them.

In your vhost section , under the setenv option, we add a new setenvif option:

setenvif:           
     - 'Authorization "(.*)" HTTP_AUTHORIZATION=$1'

Without this option, the Authorization header is being stripped! Run vagrant provision, and suddenly everything should be working correctly. Now get on with building that API!

Yay! Free OS upgrade! But oh! Something’s bound to be affected, my apache or php or something. And you’d be right. So here are my list of issues I had, and how I overcame them.

First up, Mavericks looks really cool, and seems to zip along a lot faster than lion did. Nice one! A few other nice looking things, I’ll get into those later, but are my sites loading? I open Safari, type in one of my vhosts, and then it displays a white web page with a times new roman bold h1 tag claiming ‘It works!’. Yes, Apache is working, but not a lot else! :-s

When I finally realised a while back that all-in-one things like XAMPP are actually no good for serious development, I got my PHP running with the built in Apache, and the same tweaks apply here. Edit /etc/apache2/httpd.conf :

#LoadModule php5_module libexec/apache2/libphp5.so
to
LoadModule php5_module libexec/apache2/libphp5.so

And allow use of .htaccess to override:

AllowOverride All

That should bring you back up. I wasn’t getting any db connection, so I checked to see if my MySQL server was still running. It reported so, so I fired up SequelPro and was able to get access to my data. Hmm.

My next thought that possibly more modules for apache were needing installed or something. I checked a phpinfo();  It was running v5.4.17, with no debug or anything installed, so I guessed it was the Mavericks installed PHP. I thought, well, if I’m updating, we might as well have PHP 5.5 installed, so I went to work on that.

The terminal command ‘port’ experienced difficulties, and I quickly realised that I would need to update Xcode, and Xcode Developer Command Line Tools. Once you have done that, open Xcode up, and agree to the terms and conditions, then close it. If you don’t do this some of the terminal commands will fail.  Then you can run :

sudo port self update
sudo port upgrade outdated

I came across a hanging point when it was trying to build a thing called ‘boost’. Apparently other people on the net were complaining about the same thing but no one had an answer. After failing a few times I decided I would concentrate on just upgrading packages that I needed, so I typed this to see what was already installed: (results listed to give you an idea of what i have running)

$ port -qv installed
  apache2 @2.2.22_2+preforkmpm platform='darwin 11' archs='x86_64'
  apache2 @2.2.25_0+preforkmpm (active) platform='darwin 13' archs='x86_64'
  apr @1.4.6_1 platform='darwin 11' archs='x86_64'
  apr @1.4.8_0 (active) platform='darwin 13' archs='x86_64'
  apr-util @1.4.1_0 platform='darwin 11' archs='x86_64'
  apr-util @1.5.2_1 (active) platform='darwin 13' archs='x86_64'
  autoconf @2.69_0 platform='darwin 11' archs='noarch'
  autoconf @2.69_2 (active) platform='darwin 13' archs='noarch'
  automake @1.12_0 platform='darwin 11' archs='noarch'
  automake @1.14_0 (active) platform='darwin 13' archs='noarch'
  boost @1.50.0_0+no_single+no_static (active) platform='darwin 11' archs='x86_64'
  bzip2 @1.0.6_0 (active) platform='darwin 13' archs='x86_64'
  corkscrew @2.0_0 (active) platform='darwin 11' archs='x86_64'
  cppunit @1.12.1_0 (active) platform='darwin 11' archs='x86_64'
  curl @7.27.0_1+ssl (active) platform='darwin 11' archs='x86_64'
  curl-ca-bundle @7.27.0_0 (active) platform='darwin 11' archs='noarch'
  db46 @4.6.21_6 platform='darwin 11' archs='x86_64'
  db46 @4.6.21_8 (active) platform='darwin 13' archs='x86_64'
  db_select @0.1_2 (active) platform='darwin 13' archs='noarch'
  dirac @1.0.2_1 (active) platform='darwin 11' archs='x86_64'
  docbook-xml @5.0_0 (active) platform='darwin 11' archs='noarch'
  docbook-xml-4.1.2 @4.1.2_1 (active) platform='darwin 11' archs='noarch'
  docbook-xml-4.2 @4.2_0 (active) platform='darwin 11' archs='noarch'
  docbook-xml-4.3 @4.3_0 (active) platform='darwin 11' archs='noarch'
  docbook-xml-4.4 @4.4_0 (active) platform='darwin 11' archs='noarch'
  docbook-xml-4.5 @4.5_0 (active) platform='darwin 11' archs='noarch'
  docbook-xml-5.0 @5.0_0 (active) platform='darwin 11' archs='noarch'
  docbook-xsl @1.76.1_1 (active) platform='darwin 11' archs='noarch'
  dyld-headers @239.3_0 (active) platform='darwin 13' archs='noarch'
  expat @2.1.0_0 (active) platform='darwin 13' archs='x86_64'
  ffmpeg @0.7.13_2+gpl2+mmx (active) platform='darwin 11' archs='x86_64'
  fftw-3 @3.3.2_0 (active) platform='darwin 11' archs='x86_64'
  fontconfig @2.9.0_1 (active) platform='darwin 11' archs='x86_64'
  freetype @2.4.10_0 (active) platform='darwin 11' archs='x86_64'
  gdbm @1.10_1 platform='darwin 11' archs='x86_64'
  gdbm @1.10_2 (active) platform='darwin 13' archs='x86_64'
  gettext @0.18.1.1_2 platform='darwin 11' archs='x86_64'
  gettext @0.18.3.1_1 (active) platform='darwin 13' archs='x86_64'
  ghostscript @9.05_3 (active) platform='darwin 11' archs='x86_64'
  glib2 @2.32.4_0 (active) platform='darwin 11' archs='x86_64'
  gperf @3.0.4_2 (active) platform='darwin 13' archs='x86_64'
  gsed @4.2.1_2 (active) platform='darwin 11' archs='x86_64'
  help2man @1.40.5_3 platform='darwin 11' archs='x86_64'
  help2man @1.40.10_0 (active) platform='darwin 11' archs='x86_64'
  htop @0.8.2.1_0 (active) platform='darwin 11' archs='x86_64'
  icu @4.8.1_0 platform='darwin 11' archs='x86_64'
  icu @51.2_1 (active) platform='darwin 13' archs='x86_64'
  ImageMagick @6.7.9-0_1+q16 (active) platform='darwin 11' archs='x86_64'
  ircii @20111115_0 (active) platform='darwin 11' archs='x86_64'
  jbig2dec @0.11_1 (active) platform='darwin 11' archs='x86_64'
  jbigkit @2.0_2 (active) platform='darwin 11' archs='x86_64'
  jpeg @8d_0 (active) platform='darwin 11' archs='x86_64'
  lame @3.99.5_0 (active) platform='darwin 11' archs='x86_64'
  lcms2 @2.3_0 (active) platform='darwin 11' archs='x86_64'
  libedit @20120601-3.0_0 platform='darwin 11' archs='x86_64'
  libedit @20121213-3.0_0 (active) platform='darwin 13' archs='x86_64'
  libffi @3.0.11_0 (active) platform='darwin 11' archs='x86_64'
  libiconv @1.14_0 (active) platform='darwin 13' archs='x86_64'
  libidn @1.25_0 (active) platform='darwin 11' archs='x86_64'
  libmcrypt @2.5.8_1 (active) platform='darwin 11' archs='x86_64'
  libogg @1.3.0_1 (active) platform='darwin 11' archs='x86_64'
  libpaper @1.1.24_0 (active) platform='darwin 11' archs='x86_64'
  libpcap @1.2.1_0 (active) platform='darwin 11' archs='x86_64'
  libpng @1.5.12_0 (active) platform='darwin 11' archs='x86_64'
  libsdl @1.2.15_0+x11 (active) platform='darwin 11' archs='x86_64'
  libtheora @1.1.1_1 (active) platform='darwin 11' archs='x86_64'
  libtool @2.4.2_0 platform='darwin 11' archs='x86_64'
  libtool @2.4.2_2 platform='darwin 11' archs='x86_64'
  libtool @2.4.2_3 (active) platform='darwin 13' archs='x86_64'
  libunwind-headers @35.1_1 (active) platform='darwin 13' archs='noarch'
  libvorbis @1.3.3_0 (active) platform='darwin 11' archs='x86_64'
  libvpx @1.1.0_0 (active) platform='darwin 11' archs='x86_64'
  libxml2 @2.8.0_0 (active) platform='darwin 11' archs='x86_64'
  libxslt @1.1.26_0 (active) platform='darwin 11' archs='x86_64'
  lynx @2.8.7rel.1_1+ssl (active) platform='darwin 11' archs='x86_64'
  lzo2 @2.05_1 (active) platform='darwin 11' archs='x86_64'
  m4 @1.4.16_0 (active) platform='darwin 13' archs='x86_64'
  mhash @0.9.9.9_0 (active) platform='darwin 11' archs='x86_64'
  ncurses @5.9_1 platform='darwin 11' archs='x86_64'
  ncurses @5.9_2 (active) platform='darwin 13' archs='x86_64'
  nspr @4.8.9_0 (active) platform='darwin 11' archs='x86_64'
  openjpeg @1.5.0_3 (active) platform='darwin 11' archs='x86_64'
  openssl @1.0.1b_0 platform='darwin 11' archs='x86_64'
  openssl @1.0.1c_0 platform='darwin 11' archs='x86_64'
  openssl @1.0.1e_1 (active) platform='darwin 13' archs='x86_64'
  orc @0.4.16_0 (active) platform='darwin 11' archs='x86_64'
  p5.12-locale-gettext @1.50.0_6 platform='darwin 11' archs='x86_64'
  p5.12-locale-gettext @1.50.0_7 (active) platform='darwin 11' archs='x86_64'
  pcre @8.31_0 platform='darwin 11' archs='x86_64'
  pcre @8.33_0 (active) platform='darwin 13' archs='x86_64'
  perl5 @5.12.3_1+perl5_12 platform='darwin 11' archs='noarch'
  perl5 @5.12.4_0+perl5_12 (active) platform='darwin 13' archs='noarch'
  perl5.12 @5.12.4_0 platform='darwin 11' archs='x86_64'
  perl5.12 @5.12.4_1 platform='darwin 11' archs='x86_64'
  perl5.12 @5.12.4_2 (active) platform='darwin 13' archs='x86_64'
  php53 @5.3.16_1+libedit (active) platform='darwin 11' archs='x86_64'
  php53-curl @5.3.16_1 (active) platform='darwin 11' archs='x86_64'
  php53-ftp @5.3.16_1 (active) platform='darwin 11' archs='x86_64'
  php53-iconv @5.3.16_1 (active) platform='darwin 11' archs='x86_64'
  php53-mbstring @5.3.16_1 (active) platform='darwin 11' archs='x86_64'
  php53-mcrypt @5.3.16_1 (active) platform='darwin 11' archs='x86_64'
  php53-mongo @1.2.12_0 (active) platform='darwin 11' archs='x86_64'
  php53-mysql @5.3.16_1+mysqlnd (active) platform='darwin 11' archs='x86_64'
  php53-openssl @5.3.16_1 (active) platform='darwin 11' archs='x86_64'
  php53-soap @5.3.16_1 (active) platform='darwin 11' archs='x86_64'
  php53-sqlite @5.3.16_1 (active) platform='darwin 11' archs='x86_64'
  php53-xdebug @2.2.1_0 (active) platform='darwin 11' archs='x86_64'
  php53-xsl @5.3.16_1 (active) platform='darwin 11' archs='x86_64'
  php53-zip @5.3.16_1 (active) platform='darwin 11' archs='x86_64'
  php54 @5.4.6_1+libedit (active) platform='darwin 11' archs='x86_64'
  php54-apache2handler @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php54-curl @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php54-ftp @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php54-gd @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php54-iconv @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php54-mbstring @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php54-mcrypt @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php54-mongo @1.2.12_0 (active) platform='darwin 11' archs='x86_64'
  php54-mysql @5.4.6_1+mysqlnd (active) platform='darwin 11' archs='x86_64'
  php54-openssl @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php54-soap @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php54-sqlite @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php54-xdebug @2.2.1_0 (active) platform='darwin 11' archs='x86_64'
  php54-xsl @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php54-zip @5.4.6_1 (active) platform='darwin 11' archs='x86_64'
  php_select @1.0_0 (active) platform='darwin 11' archs='noarch'
  pkgconfig @0.27_0 (active) platform='darwin 11' archs='x86_64'
  python27 @2.7.3_0 platform='darwin 11' archs='x86_64'
  python27 @2.7.6_0 (active) platform='darwin 13' archs='x86_64'
  python_select @0.3_1 platform='darwin 11' archs='noarch'
  python_select @0.3_3 (active) platform='darwin 13' archs='noarch'
  re2c @0.13.5_0 (active) platform='darwin 11' archs='x86_64'
  readline @6.2.000_0 (active) platform='darwin 11' archs='x86_64'
  schroedinger @1.0.11_0 (active) platform='darwin 11' archs='x86_64'
  scons @2.2.0_0 (active) platform='darwin 11' archs='noarch'
  snappy @1.0.5_0 (active) platform='darwin 11' archs='x86_64'
  speex @1.2rc1_0 (active) platform='darwin 11' archs='x86_64'
  spidermonkey @1.7.0_5 (active) platform='darwin 11' archs='x86_64'
  sqlite3 @3.7.14_1 platform='darwin 11' archs='x86_64'
  sqlite3 @3.8.0.2_0 (active) platform='darwin 13' archs='x86_64'
  tiff @3.9.5_0 (active) platform='darwin 11' archs='x86_64'
  urw-fonts @1.0.7pre44_0 (active) platform='darwin 11' archs='noarch'
  webp @0.2.0_1 (active) platform='darwin 11' archs='x86_64'
  x264 @20111210_0 (active) platform='darwin 11' archs='x86_64'
  xmlcatmgr @2.2_1 (active) platform='darwin 11' archs='x86_64'
  xorg-kbproto @1.0.6_0 (active) platform='darwin 11' archs='noarch'
  xorg-libice @1.0.8_0 (active) platform='darwin 11' archs='x86_64'
  xorg-libpthread-stubs @0.3_0 (active) platform='darwin 11' archs='noarch'
  xorg-libsm @1.2.1_0 (active) platform='darwin 11' archs='x86_64'
  xorg-libX11 @1.5.0_0 (active) platform='darwin 11' archs='x86_64'
  xorg-libXau @1.0.7_0 (active) platform='darwin 11' archs='x86_64'
  xorg-libxcb @1.8.1_2+python27 (active) platform='darwin 11' archs='x86_64'
  xorg-libXdmcp @1.1.1_0 (active) platform='darwin 11' archs='x86_64'
  xorg-libXext @1.3.1_0 (active) platform='darwin 11' archs='x86_64'
  xorg-libXrandr @1.3.2_0 (active) platform='darwin 11' archs='x86_64'
  xorg-libXt @1.1.3_0 (active) platform='darwin 11' archs='x86_64'
  xorg-randrproto @1.4.0_0 (active) platform='darwin 11' archs='noarch'
  xorg-renderproto @0.11.1_0 (active) platform='darwin 11' archs='noarch'
  xorg-xcb-proto @1.7.1_0+python27 (active) platform='darwin 11' archs='noarch'
  xorg-xextproto @7.2.1_0 (active) platform='darwin 11' archs='noarch'
  xorg-xproto @7.0.23_0 (active) platform='darwin 11' archs='noarch'
  xrender @0.9.7_0 (active) platform='darwin 11' archs='x86_64'
  XviD @1.3.2_3 (active) platform='darwin 11' archs='x86_64'
  xz @5.0.3_0 platform='darwin 11' archs='x86_64'
  xz @5.0.4_0 platform='darwin 11' archs='x86_64'
  xz @5.0.5_0 (active) platform='darwin 13' archs='x86_64'
  zlib @1.2.6_0 platform='darwin 11' archs='x86_64'
  zlib @1.2.7_0 platform='darwin 11' archs='x86_64'
  zlib @1.2.8_0 (active) platform='darwin 13' archs='x86_64'

As you can see I have quite a few! But I was incredibly lucky, I typed in :

sudo port upgrade curl

And it installed, also fixing the boost problem, allowing me to continue with ‘sudo port upgrade outdated’ without the error happening!

Be prepared to wait a while for all of this compiling to go on! Once you are bang up to date we can install PHP 5.5. First lets get rid of all the old stuff compiled for your old OS (actually this works when if you put a -u flag on the sudo port -u upgrade outdated):

sudo port uninstall inactive

Now for 5.5! Feel free to add more PHP modules, full list available at the macports website.

sudo port install php55 php55-curl php55-ftp php55-iconv php55-mbstring php55-mcrypt php55-mongo php55-mysql php55-openssl php55-soap php55-sqlite php55-xdebug php55xsl php55-zip php55-apache2handler

cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n php5 mod_php55.so

Now edit your httpd.conf to load 5.5:

LoadModule php5_module /opt/local/apache2/modules/mod_php55.so

sudo apachectl restart

Job done. My thoughts on all this? First you had all in one nonsense like MAMP and XAMPP. No good. Then we have the option of using a package manager such as MacPorts or Homebrew (macports in my case), but in all honesty I really think manually compiling and configuring everything is a much better idea, as per my other posts regarding the Ubuntu server in my work.

Sick of having to recompile everything after an OS upgrade? Think about setting up a Ubuntu Server Virtual Machine using VirtualBox! And then your server can run on any machine with any configuration, and the pain will be a lot less in the future!

Feel free to comment on anything you may have come across during the process! Everyone’s set up is different!

This look familiar?

PHP Warning:  PHP Startup: memcached: Unable to initialize module
Module compiled with module API=20090626
PHP    compiled with module API=20100525
These options need to match

I don’t know about you, but i like to be up to date! My PHP is on 5.5, and I had to install some modules. But sometimes, old versions can rear their ugly head, and cause all manner of grief. Package managers do a good job to take care of all this for you, but sometimes they just don’t work. Leaving you to compile yourself! So lets do it! I’m going to install memcached, and then the imagick libraries (now i know what i’m doing!)

I’m doing this on a CentOS 6 server, but as we are doing the old skool way of compiling etc, this should work on any other flavour of Linux, or indeed Mac OS X.

First step is to download your .tar.gz  then unzip it with tar -zxvf file.tar.gz and change into the folder.
Bring up a web page displaying your servers php.ini. You are looking for the version of PHP API, and the extension_dir.
In your terminal, cd into the module source code folder, and type phpize.

If when you check the API versions , they are different from your php.ini, then an old version of php is being used in the terminal, and your module will not work! In this case, you need to get it to use the correct phpize.

type 'which phpize' to find out where the offending file is. (mine was /usr/bin/phpize)

My PHP appeared to be in /usr/local, so I tried running /usr/local/phpize. The API’s matched. So then I did the following:

mv /usr/bin/phpize /usr/bin/phpize-old
 ln -s /usr/local/bin/phpize /usr/bin/phpize

Half way there! We need to do the same for php-config

mv /usr/bin/php-config /usr/bin/php-config-old
 ln -s /usr/local/bin/php-config /usr/bin/php-config

Now you have done that, installation should be trivial, and work as per loads of tutorial/instrruction pages on the web.

./configure
 make
 make install

Finally edit your php.ini and add ‘extension = memcached.so’ (or whatever module you compiled), and restart your apache server!

EDIT : you may need to run ‘phpize –clean’ if it is still compiling with the older stuff from within the modules source folder

The PHP that ships with Mac is getting rusty. Time to get PHP 5.4!

I tried several methods, and several fail failed. This one (https://gist.github.com/2721719) didn’t.

sudo port selfupdate
sudo port -u upgrade outdated

sudo port install php54 php54-apache2handler
cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n php5 mod_php54.so
sudo port install php54-curl php54-ftp php54-iconv php54-mbstring php54-mcrypt php54-mysql php54-openssl php54-soap php54-sqlite php54-xsl php54-zip php54-xdebug php54-mongo

sudo port install php53 php53-apache2handler
sudo port install php53-curl php53-ftp php53-iconv php53-mbstring php53-mcrypt php53-mysql php53-openssl php53-soap php53-sqlite php53-xsl php53-zip php53-xdebug php53-mongo

cd #
curl http://pear.php.net/go-pear.phar -o go-pear.phar
sudo php go-pear.phar

And then we can select which php the system uses by saying either of these:

sudo port select php php54
sudo port select php php53

When installing Pear:
Option 1. Installation base ($prefix) : /opt/local/lib/php54
4. Binaries directory : /opt/local/bin
Then get PHPUnit

pear info pear && rm go-pear.phar
sudo pear config-set auto_discover 1; sudo pear install pear.phpunit.de/PHPUnit

Lastly we nano /etc/apache2/httpd.conf and ctrl-w to look where php is. Comment the 5.3 one, and add the line:

#LoadModule php5_module libexec/apache2/lib_php5.so
LoadModule php5_module /opt/local/apache2/modules/mod_php54.so

So we can switch between the two by moving the comment. Finally restart apache!

sudo apachectl restart

phpinfo() and php -v both showing 5.4! Fantastico! Remember to set your default timezone now!

Want a completely insecure password protected folder using htpasswd?  Great!
A pointless exercise unless it’s in a setup at your work and you have no say in the matter, htpasswd’s are sent in unencrypted plain text, so anyone hanging around packet sniffing will pick up the password easily enough! Anyway, thats besides the point, how is it done?

First up we put this in the .htaccess for the directory we wish to protect (ha):

<Directory "/home/user/username/www/folder/to/protect">
AuthType Basic
AuthName "My Private Directory"
AuthUserFile "/path/to/htpasswd"
Require valid-user
</Directory>

Then we generate the htpasswd file like this:

 htpasswd -c /path/to/htpasswd username

Hooray! The illusion of ‘security’! At least it keeps non geeks out 😉

No sooner did I say that I was happy with XAMPP, when suddenly it was useless and no good to me. Yes it was nice and easy to install, but heres the catch – all that goodness turns rotten when you want to upgrade a part of it.

If you’ve been reading along then you’ll know that I was in the process of preparing to install Doctrine, however, it wants at the very least, PHP 5.2, and lo and behold, along came sod and his law. XAMPP runs 5.1!

I tried swapping out the libphp5.so file with the one from the Mac’s built in Apache (5.3.10) to no avail, although someone on the internet claimed it was possible.

This left me with the choice. What now? Mamp? Zend Server Community Edition? Built in Mac Apache? The correct choice of course is the shipped with Mac Apache, as the other two are once again complete PHP stack solutions, like XAMPP, and we don’t want caught out like that again! Time to get serious and install and configure all of our server components ourselves.

It’s actually remarkably easy to move your Apache and PHP across from XAMPP. I’m guessing your htdocs are kept in the Mac’s ‘Site’ folder, like they should be. If not go into your xampp htdocs and move them across.

Next you copy your virtual host entries and put them in /etc/apache2/extra/http-vhosts.conf

Then we edit /etc/apache2/httpd.conf, uncommenting the php library module by deleting the # at the start of the line:

#LoadModule php5_module libexec/apache2/libphp5.so
to
LoadModule php5_module libexec/apache2/libphp5.so

In the <Directory “/Library/WebServer/Documents”>, we enable the use of .htaccess by having:

AllowOverride All

A little gotcha which had me stumped was that the .htaccess files in my sites still weren’t being used. It turns out you have a specific file for that:

sudo nano /private/etc/apache2/users/delboy1978uk.conf
<Directory "/Users/delboy1978uk/Sites/">
 Options Indexes MultiViews
 Options +Indexes +FollowSymLinks +ExecCGI
 AllowOverride All
 Order allow,deny
 Allow from all
</Directory>

And thats Apache sorted! We can start, stop, and restart Apache with the following commands (You can also tick a button in Apple > Preferences > Sharing > Web Sharing):

apachectl start
apachectl restart
apachectl stop

Having done that if you phpinfo(), you’ll see that there is no php.ini file! (which freaked me out a little), so I had to make one.

cd /etc
ls

There I discovered that we have php.ini.default, so I made a copy and then edited it:

cp php.ini.default php.ini
nano php.ini

In there I set the following:

error_reporting  =  E_ALL | E_STRICT
display_errors = On
html_errors = On
include_path = ".:/usr/lib/php:/usr/lib/php/Zend:/usr/lib/php/ZendX

Lastly need the zend libraries in their new home:

sudo cp -R /Application/XAMPP/xamppfiles/library/Zend /usr/lib/php/Zend
sudo cp -R /Application/XAMPP/xamppfiles/library/ZendX /usr/lib/php/ZendX

Part 2 and we’ll kill XAMPP once and for all, leaving us with a system which will be far more powerful and customisable, and then maybe I can get on with what I was trying to do, i.e.. program!