How to run PHP with Apache in El Capitan

I’m assuming you like to install PHP 5.6 with MySQL and want something more than MAMP. Good news is that Mac OS X El Capitan comes with Apache so you simply have to configure it.

To begin, you will need Homebrew, if you don’t already have that, install it here.

Installing MySQL and PHP 5.6

After which, install the following packages:

Updating Apache httpd configuration

Next you will need to edit your Apache configuration. Open /private/etc/apache2/httpd.conf for that.

Search for rewrite_module and php5_module.

You have to uncomment them and change them to the following:

Notice that php5_module is referencing the Homebrew version.

Starting the servers

Start MySQL this way:

Start Apache this way (you will need sudo):

Using VirtualHost

If you’re using VirtualHost, you will need to uncomment the following line in /private/etc/apache2/httpd.conf. Search and uncomment this:

Next is to take a look at your VirtualHost file here /private/etc/apache2/extra/httpd-vhosts.conf.

To do that, you will have to do:

This is a sample of my VirtualHost:

Things to note in the above is the directory permissions. It may be different in your use case so be sure to set them properly. My project is using CakePHP is has the DocumentRoot in /Users/kahwee/projects/mcs-portal/web/

How to install Laravel to a subdirectory

Simple! Just need to change a setting in the .htaccess file. I am using Laravel 4, you might be using some other version but the method should apply nevertheless. I use an alias to point to this directory.

Add this line “RewriteBase /l4″ to your .htaccess where l4 is your sub directory or folder.

[code language=”php”]<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /l4
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Have fun!

How to install Composer in Windows

I wanted to install PHP Composer in Windows. And to begin, I already have a copy of XAMPP 1.8.1, I think if you have a different way to get your PHP that should not matter. I tested this to work for Windows 7 but it should work for all versions of Windows.

0. Download and install XAMPP

You can download XAMPP here. I got the 7zip version rather than the installer itself. The ZIP version is similar, just with a larger file size. I extract the xampp folder into my C: drive, i.e. to C:xampp. Then install it by opening the file C:xamppsetup_xampp.bat. That will set the paths in XAMPP’s configurations.

1. Setting up environment variables

Continue reading “How to install Composer in Windows”

How to install PHP 5.4 into OS X Mountain Lion

To do so, we are going to get most of the stuff from Jose Gozalez’s formulae. You will need a copy of homebrew installed, you can read about how to install homebrew here.

Let’s start by setting up the dependencies in homebrew.

[code language=”bash”]brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php[/code]

Now php54 is available for install through:

[code language=”bash”]brew install php54 –with-mysql[/code]

To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module /usr/local/Cellar/php54/5.4.5/libexec/apache2/

The php.ini file can be found in:

If pear complains about permissions, ‘Fix’ the default PEAR permissions and config:

[code language=”bash”] chmod -R ug+w /usr/local/Cellar/php54/5.4.5/lib/php
pear config-set php_ini /usr/local/etc/php/5.4/php.ini

After you enabled PHP in Apache, make sure you restart Apache too!

[code language=”bash”]sudo apachectl restart[/code]


If you get an error that looks like this:”

[code language=”bash”]configure: error: freetype.h not found.
Error: uncaught throw Failed executing: ./configure --prefix=/usr/local/Cellar/php54/5.4.5 --disable-debug --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/5.4 --with-config-file-path=/usr/local/etc/php/5.4 --with-config-file-scan-dir=/usr/local/etc/php/5.4/conf.d --with-iconv-dir=/usr --enable-dba --with-ndbm=/usr --enable-exif --enable-soap --enable-sqlite-utf8 --enable-wddx --enable-ftp --enable-sockets --enable-zip --enable-pcntl --enable-shmop --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-mbstring --enable-mbregex --enable-zend-signals --enable-dtrace --enable-bcmath --enable-calendar --with-zlib=/usr/local/Cellar/zlib/1.2.7 --with-bz2=/usr --with-ldap --with-ldap-sasl=/usr --with-xmlrpc --with-kerberos=/usr --with-libxml-dir=/usr/local/Cellar/libxml2/2.8.0 --with-xsl=/usr --with-curl=/usr --with-gd --enable-gd-native-ttf --with-freetype-dir=/usr/X11 --with-mcrypt=/usr/local/Cellar/mcrypt/2.5.8 --with-jpeg-dir=/usr/local/Cellar/jpeg/8d --with-png-dir=/usr/X11 --with-gettext=/usr/lo[/code]

It is because your freetype is not working right. It happened to me after I upgraded from Mac OS X Lion to Mac OS X Mountain Lion. To do safe, uninstall and install freetype back:

[code language="bash"]brew uninstall freetype
brew install freetype[/code]

Also if you get a permissions error, you might have to fix it:

[code language="bash"]➜ ~ brew install php54
==> Downloading
Already downloaded: /Library/Caches/Homebrew/php54-5.4.5
==> ./configure --prefix=/usr/local/Cellar/php54/5.4.5 --disable-debug --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/5.4 --with-config-file-path
==> make
==> make install
==> /usr/local/Cellar/php54/5.4.5/bin/pear config-set php_ini /usr/local/etc/php/5.4/php.ini
no write access to /Users/kahwee/.pearrc!
Error: uncaught throw
Failed executing: /usr/local/Cellar/php54/5.4.5/bin/pear config-set php_ini /usr/local/etc/php/5.4/php.ini'[/code]

I changed the owner from root to kahwee (my username):

[code language=”bash”]sudo chown kahwee /Users/kahwee/.pearrc[/code]

That’s all, hope it helps!

How to install PHP GeoIP in Ubuntu

This instructions will install GeoIP over Ubuntu. It is tested over Ubuntu 12.04 LTS.

I assume you already have PEAR/PECL available. I am using the CentOS’s stock PHP. First you need to update your channels:

Continue reading “How to install PHP GeoIP in Ubuntu”

How to install APC in Ubuntu 12.04

This installation is through PEAR. You can install it in other methods too. This has installed APC 3.1.9 for me over Ubuntu 12.04 LTS.

[code lang=”bash”]sudo apt-get install build-essential libpcre3-dev php5-dev
sudo pear update-channels
sudo pecl install apc[/code]

Continue reading “How to install APC in Ubuntu 12.04”

Symfony 2 is hard

Symfony2 is hard. But not simply because it is doing things so differently, rather, it depends on so many packages. While there are certainly a lot of resources online, many can be considered outdated.

This recalls a discussion I had with U-Zyn of gladlyCode on the trends on PHP frameworks. We concluded that Symfony has a brighter future because on the past few years Symfony has became one of the most talked about frameworks in Google Trends. That observation, however, did not consider the scenario where more people posted online as they needed help. Additionally search for Symfony also includes Symfony Legacy (Symfony 1) which turns out to be vastly different from Symfony 2. It is hard to distinguish articles of the two, half the time I’ll be read through then to realized it’s for Symfony 1

Symfony 2 supports both Doctrine 2 and Propel ORMs. There are times I read through articles for Propel rather than Doctrine2 that I am using. Yesterday I spent my day figuring out Symfony and all I achieved is installing bundles. Bundles are not as well documented and many times that are wrappers of another PHP project.

At the end of the day I find myself referring to so much websites that I maxed out my tabs and no longer see the favicon on the tab any more.

Symfony2 reminds me of TurboGears of Python, if anyone is even still using it. It’s not a bad thing, especially in the whole of PHP where writing yet another ORM isn’t really needed. My minor complaint is Symfony requires the developer to do more configuration than other frameworks — say Yii Framework — and the ORM of choice, Doctrine 2, requires too much definitions to be included in an Entity (similar to Model of MVC frameworks). Overall Symfony 2 is a big framework to work with, I am probably discovering something new at every juncture. It’s worth a try but you’ll need a day at least to explore their features.

How to use Symfony with existing database

I recently had to start a Symfony2 project using an existing database. Here is a rough guide on how it is done.

Firstly you have to update your app/config/parameter.ini to your existing database:

[code lang=”bash”][parameters]

My bundle is named GladlyCodeBundle, you will have to rename this. Based on this I do a map of existing database tables into XML format, note that the em dash is 2 dashes due to conversion by WordPress:

[code lang=”bash”]php app/console doctrine:mapping:convert xml ./src/Gladly/CodeBundle/Resources/config/doctrine/metadata/orm –from-database –force[/code]

You need to change the ‘Gladly/CodeBundle’ part to fit your project as the next step will look to import from the default location.

If you get any errors of this sort:

[code lang=”bash”]PHP Fatal error: Call to a member function getColumns() on a non-object in /Users/kahwee/projects/gladlycode/vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php on line 133
PHP Stack trace:
PHP 1. {main}() /Users/kahwee/projects/gladlycode/app/console:0
PHP 2. SymfonyComponentConsoleApplication->run() /Users/kahwee/projects/gladlycode/app/console:22

It could be due to one of your tables not having a primary key. Just assign it the appropriate primary to continue with the import process.

Then I import them with annotations:

[code lang=”bash”]php app/console doctrine:mapping:import GladlyCodeBundle annotation[/code]

Finally I regenerate them into entities:

[code lang=”bash”]php app/console doctrine:generate:entities GladlyCodeBundle[/code]

And that’s it. Everything is imported.

Composer, a package manager for PHP

Composer is probably a bad name for a package manager in the sense where it is hard to research online by searching on the keyword ‘composer’ without receiving Beethoven as part of results. The composer I am referring to is this. Composer is a package manager tracking local dependencies of your projects and libraries.

Composer lets you specify your dependencies in a composer.json file looks like this:

[code lang=”javascript”]
“require”: {
“doctrine/common”: “2.1.*”,
“monolog/monolog”: “>=1.0,<1.2-dev”,
“swiftmailer/swiftmailer”: “>=4.1.2,<4.2-dev”,
“twig/twig”: “>=1.1,<2.0-dev”

This file will install the components into the a vendor folder on the directory where you execute the following:

[code lang=”bash”]php composer.phar install[/code]

How to install PHP GeoIP in CentOS

I assume you already have PEAR/PECL available. I am using the CentOS’s stock PHP. First you need to update your channels:

[code lang=”bash”]kahwee:~ kahwee$ sudo pear update-channels
Updating channel “”
Channel “” is up to date
Updating channel “”
Channel “” is up to date
Updating channel “”
Channel “” is up to date[/code]

Continue reading “How to install PHP GeoIP in CentOS”