Upgrading PHP on Mac and Ubuntu

In this post we list the steps of installing php 5.4, however, the steps are the same for any version. You may have to choose different binary names but for those you can look up in macports.com. In addition, once multiple versions of php binaries installed, it is easy to switch between the versions. It involves only two steps – activate proper version binaries all of which covered in this post

Mac

Step-1 Installing PHP 5.4
We use macports packaging management system to fetch artifacts

sudo port selfupdate
sudo port install php54
sudo port install php54-gd
sudo port install php54-mysql
sudo port install php54-apache2handler
sudo port activate php54
sudo port activate php54-gd
sudo port activate php54-mysql
sudo port activate php54-apache2handler

The activate commands may not need to be run since its auto activate when running ‘port install’, however. We list here for information

Step-2 Enable PHP in Apache
When installing php54-apache2handler module via MacPorts, it downloads php54.so binary for apache and places it in the /path/to/apache2/modules folder(in our case it is /opt/local/apache2)

So, you have to tell Apache load the new php54 version binary by replacing following lines in apahce configure file http.conf (/path/to/apache2/http.conf) as following:

LoadModule php5_module libexec/apache2/libphp5.so

–with–

LoadModule php5_module modules/mod_php54.so

Afterward, restart Apache service. This ensure that the php module is loaded.

Note: you may want to confirm that the new module ‘mod_php54.so’ with proper permissions is present (for mac 10.7 in /path/to/apache2/modules)

Step-3 Customize PHP

cd /opt/local/etc/php54
cp php.ini-development php.ini

Step-4. Verify Php Version
To verify, run:

php -v

The version may be different. This happens if you have php already installed, then you have to remove the default PHP configuration:

which php
/usr/bin/php
sudo rm /usr/bin/php
sudo ln -s /path/to/php/executable php

Here, we removed the pointer to the old php executable and create reference to the new one. MacPorts downloads the new php executable in /opt/local/bin directory and name it ‘php55’

Aftewards, the ‘php -v’ should match with version you installed.

Switching PHP Version
To switch between versions you would run:

sudo port select --set php php54

And then updating /path/to/apache2/http.conf to load proper *.so module for the particular PHP

...
LoadModule php5_module modules/mod_php54.so
...

To see what php modules available and their exact naming see ‘/path/to/apache2/modules’

To see MacPorts logs

To see MacPorts logs

 /opt/local/var/macports/logs/

Uninstalling before upgrading
You may have to uninstall before you can install newer version. If so, make sure first deactivate/uninstall dependencies i.e. php5-gd and php5-mysql. Please see more
How to Deactivate One Macport Variant and Switch to Another One

Ubuntu

For ubuntu

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5-oldstable
sudo apt-get update
sudo apt-get install php5
sudo apt-get install php5-mysql
sudo apt-get install php5-curl
sudo apt-get install php5-gd

The ‘php5-oldstable’ is for PHP 5.4. For the php5.5 there is ppa:ondrej/php5, however. The repository ppa:ondrej/php5 doesn’t seem to have lucid Ubuntu distribution as well it is upgrading to Apache2.4 which a lot of changes.

The ‘python-software-properties’ is installed in order to use ‘add-apt-repository’ command, however. you as well manually can add the repository at /etc/apt/sources.list as following:

deb http://ppa.launchpad.net/ondrej/php5-oldstable/ubuntu lucid main
deb-src http://ppa.launchpad.net/ondrej/php5-oldstable/ubuntu lucid main

If you may need to uninstall php on ubuntu:

sudo apt-get -y purge php*

or more conservative approach:

sudo apt-get -y purge libapache2-mod-php5 libapache2-mod-php5filter libexpect-php5 libgv-php5 libow-php5 php5 php5-adodb php5-auth-pam php5-cgi php5-cli php5-common php5-curl php5-dbg php5-enchant php5-exactimage php5-ffmpeg php5-fpm php5-geoip php5-gmp php5-idn php5-imagick php5-imap php5-interbase php5-intl php5-json php5-lasso php5-ldap php5-librdf php5-mapscript php5-memcache php5-memcached php5-mhash php5-midgard2 php5-ming php5-mssql php5-mysql php5-mysqlnd php5-odbc php5-pgsql php5-ps php5-pspell php5-radius php5-recode php5-remctl php5-rrd php5-sasl php5-snmp php5-sqlite php5-suhosin php5-svn php5-sybase php5-tidy php5-tokyo-tyrant php5-uuid php5-xcache php5-xdebug php5-xmlrpc php5-xsl

You can also search for all php packages as following:

sudo aptitude search php5|awk {'print $2'}|grep -v i386|grep -v "^A"|tr "\n"  " "

Other

1. How to locate a dir from which the Apache is currently running on your machine

ps -ef | grep apache

2. How to locate a dir from which the current installation of PHP is running from on machine
Create php config info file – phpinfol.php and place the following.

<?php phpinfo(); ?>

Afterwards, open this file in the browser

Issues

1. Page Not Found

After doing everything and pointing to phpinfo.php, the browser returns page not found. the issue was that it was loading the php module from the wrong dirrectory. The http.conf was containing:

...
LoadModule php5_module modules/mod_php54.so
...

But needed to be:

LoadModule php5_module libexec/apache2/mod_php54.so
2. Exception: Stripe needs the CURL PHP extension. in require_once()[…]

One of the libraries(Stripe) is using CURL, so i forgot to install. To do so:

sudo port install php54-curl

For Ubuntu

sudo apt-get install php5-curl

This also activates the php-curl, so all is left to restart the apache server. Depending on you PHP Version, there may be different php-curl module to install. Please see macports.com for list of packages and versions

3. Stripe needs the Multibyte String PHP extension

Here the Stripe module is using MultiByte String lib that is missing. To install

sudo port install php54-mbstring  

Depending of your PHP Version, you may have to install a different version of mbstring lib. Afterwards, make sure to restart the apache server

3.PDOException: SQLSTATE[HY000] [2002] No such file or directory in lock_may_be_available()

(line 167 of /Users/maxit/Sites/drupal/commerce/first-commerce/includes/lock.inc)

By default, mysql is configured not to use TCP connection(particular for php55), so your sites will break. For solution see post Installing Mysql On Mac for ‘ERROR 2003 (HY000): Can’t connect to MySQL server on 127.0.0.1’

References

Configure Debugging with PHPStorm

Debugging is crucial part in being productive developer. Setting up debugging for PHPStorm IDE has been a painful process partly because the info on the subject matter online have been confusing to say at least. In this post, I hope to clarify some of the misconceptions and, perhaps, save some of your time.

It’s important to note, you will not be able to do remote debugging if your PHPStorm IDE is on machine with dynamic IP and is behind LAN that you don’t have control of configuring the router because Apache server Xdebug service needs to forward requests to the PHPStorm IDE

The post is divided into two main parts – Configure Server and Configure PHPStorm IDE both of which needed to make debugging work in PHPStorm

Tested: PHP5.4.10, Mac OSx 10.7, PHPStorm 5.0.4

How it works?

(in general)
When you start debugging at PHPStorm IDE, then your PHPStorm IDE makes request to the Apache Server Xdebug service and goes into wait mode. Next, you make request from your choice of browser to your site. Apache server receives this requests and from the session forwards it to the Xdebug service part of Apache suite. The Xdebug service forwards the request to PHPStorm IDE that steps through your break points. After done stepping thought the code, PHPStorm IDE sends response to Apache server Xdebug service which forwards it to Apache and Apache responds to your browser. A real good description on how it works is listed at http://xdebug.org/docs/remote

Part I – Configure Server

On server, we have to enable Xdebug service to be loaded with Apache and then configure Xdebug to be able communicate with PHPStorm IDE.

1) Install Xdebug

For Mac:

sudo port install php54-xdebug
port activate php54-xdebug

For Ubuntu:

sudo apt-get install php5-xdebug

For windows:
In the php.ini file add the following:

extension="/path/to/xdebug.so"
2. Configure Xdebug

To configure Xdebug add the following in php.ini file:

[Xdebug]
zend_extension="/usr/lib/php5/20090626/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_port=9123
xdebug.remote_host=localhost//or IP of your remote server
//xdebug.remote_connect_back=1
xdebug.remote_log = /Users/mkapacs/xdebug/xdebug.log
xdebug.idekey="PHPSTORM"

The above configurations:

  • ‘zend_extension’ ensures to load xdebug module with apache
  • remote_port(i.e. ‘9123’) is the port used in communication between apache xDebug service and PHPStorm IDE.
  • remote_host(i.e. localhost) is the IP of machine with PHPStorm IDE.
  • ‘remote_connect_back’ if it set to 1, then you don’t need the remote_host because xDebugger determines PHPStorm machine’s location from the initial PHPStorm request header. This is preferred way when your PHPStorm IDE is on machine with dynamic IP, so you don’t have to reconfigure remote_host every time new IP is issued
  • idekey(i.e.’PHPSTORM’) can be any string. It is used for identifying unique session

Restart apache to load the new configurations.

3. Test Xdebug

In older versions and setups of Apache, we could test whatever xdebug was loaded by running:
apachectl -t -D DUMP_MODULES
If no xdebug configurations shows up in the list then your xdebug modules is not loaded

Today, i check by looking to see if there is logs written in locations as specified in xdebug.remote_log. If nothing is written than xdebug does not load…or a wrong assumption!!! The Xdebug Manual states:

xdebug.remote_enable
Type: boolean, Default value: 0
This switch controls whether Xdebug should try to contact a debug client which is listening on the host and port as set with the settings xdebug.remote_host and xdebug.remote_port. If a connection can not be established the script will just continue as if this setting was 0.

This makes me think that in past i didn’t see the logs written not because xdebug module was not loading but because Xdebug wasn’t able to establish connection with PHPStorm IDE, so it continued without xdebug and without writing logs. I don’t know, but when that happened I often forced xdebug module to load till the logs came up.

Force Xdebug to load with Apache

So, when there is no Xdebug logs written in location as specified at xdebug.remote_log, I was under impression that xdebug.so module is not loaded with Apache. In the following are steps to make to load xdebug module to see the Xdebug logs.
For Apache2.4 and Ubuntu14, it is as easy as installing package containing xdebug

sudo apt-get install libwxbase2.8-dbg

This will configure and load xdebug for Apache. Xdebug logs should be written

For older version of Apache, add the following line to apache configuration file httpd.conf:
LoadModule xdebug_module libexec/apache2/xdebug.so

!!!Make sure you copy the ‘xdebug.so’ into /path/to/apache2/modules directory

If you don’t know the path to xdebug.so, then To find location of your xdebug.so:

find / -name 'xdebug.co'

In our case it was in ‘/usr/lib/php/extensions’ dir

Part II – Configure PHPStorm IDE

Configure PHPStorm IDE involves configuring server info, so PHPStorm IDE knows where to make the initial request and then specify the port on which to wait from Server to forward user request. At last, set up the debugging.

1. Provide Server Info

a) Open PHPStorm settings(command + ‘,’) and navigate to PHP->Servers. Add server as following:


The drupal.local can be the IP address of the Apache Server. The port can be 80 as well so you don’t have to configure extra port(i.e. 9001) for Apache to listen

2. Provide Port

The port(i.e remote_port) you specified in the php.ini for communicating with PHPStorm IDE should go here. Navigate to PHP->Debug and then enter port under Xdebug section as following:

3. Set Up Debugging

At last, set up the debugging in the PHPStorm IDE by going to RUN->Edit Configurations and Add ‘PHP Remote Debug’ as following:

4. Test Drive

Lets test it by initiating the debugging in PHPStorm IDE:

a) Set break points

b) Start debugging as following:

To validate it started, look for message as follows:

c) Open browser

  • Turn on session via PHPStorm Marklets
  • –OR–

  • append ‘?XDEBUG_SESSION_START=PHPSTORM’ to your url

Both do the same thing add session id to the request
It should stop at your break point

Other

Enhance with xdebug.remote_autostart=1

If you include the following setting in php.ini:

[Xdebug]
...
xdebug.remote_autostart=1

Then XDebuger starts automatically without need for session id be sent from browser. As long there is PHPStorm Xdebuger listener waiting the apache server will forward all requests to it automatically. Turn off the PHPStorm Xdebuger listener and apache server will not forward request instead process them.

Start Debugger from Command Line

To start debugger from command line, everything is the same as above described except you have to give id to the command shell:

export XDEBUG_CONFIG="idekey=PHPSTORM"

Now, start the debugger at PHPSTORm and run script such as Drush command. Is should break at your breakpoints.

Troubleshooting

1. xdebug logs not showing up

This means xdebug module is not loading for apache(this is not always true, please see above). Besides php5-xdebug & it’s configurations in php.ini, the apache itself needs to load xdebug module. For ubuntu, you have to install a separate package – that includes xdebug module as following:

 sudo apt-get install libwxbase2.8-dbg
 service apache2 restart

Now, you see the logs of xdebug to help troubleshoot further

2. Address already in use: make_sock: could not bind to address [::]:80

This error happens when it is declared apache to listen on port 80 two times. Make sure you don’t have specified ‘Listen 80’ in two places httpd.conf and httpd-vhost.conf.

3. Scripts Run from command line always breaks at first line

Its the PHPStorm debugger configuration that you can change by unchecking the ‘Force break at [..]’ PHP->Debug PHPStorm configurations in xDebug section

Remote address found, connecting to [..]Time-out connecting to client. :-(…Could not connect to client

This happens when the Apache server Xdebug service is forwarding request to the PHPStorm IDE but it doesn’t have static IP or it’s behind firewall, NAT or some other configurations that prevents the communication between server to client. You can verify it by telneting from your Apache server machine to your PHPSTorm IDE machine:

>telnet
>O
(to) IP.COMES.HERE PORT

Solution is to open the port in the firewall or configure IP accordingly to make PHPStorm reachable from server. For Mac, make sure the ‘Remote Login’ is enabled at ‘Preferences/Sharing’

Remote file [..] is not mapped to any file path in project

You have to map the directory of your project locally to the one at the server. This can be done by going to File -> Settings->PHP->Server.

It doesn’t break at my breakpoints

One possible problem is that you haven’t mapped all of the files to the ones on the remote server. As result, Xdebug service doesn’t forward execution to your PHPSTorm IDE files. Go to ‘Settings’->’PHP’->’Server’ and configure dir mappings for your debug server

Useful Links

Importing MySQL on WordPress Cloud Instance

Prerequisites: MySql, VMC, AppFog installed

In prevouse post, i deployed my first PHP app on Cloud. The reasoning for doing was, so i don’t have to configure and maintain my local development infrastructure(Apache, PhpMyAdmin,etc). So, I make a change following with push to cload and the resulting instance on cloud is my development solution ready for testing, however. In order to do, we need import data into MySql on the cloud instance to keep it in sync with production environment. This post is exactly how we accomplish it with ColdeCott  – an extension of CloudFoundry that lets run commands on MySql instance residing on cloud feeding our PHP App

Step 1 – Install DevKit and ColdeCott

DevKit is needed, so we are able to install ColdeCott. To install DevKit, go to rubbyinstaller page and download DevKit. Afterwards, extract DevKit and in ‘Command Line with Ruby’ go to the folder where you extracted DevKit and run the following:

In the above screen shot, the last command was run to install ColdeCotte – ‘get install CaldeCotte’

Step 1 For Mac – Install ColdeCott via XCode

For Mac environments, the Coldecott is installed via XCode as follows:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer   
sudo gem install caldecott

Step 2 – Connect to MySql instance

To connect with the particular MySql instance feeding your app, we use a command ‘tunnel’ from Command Line with Ruby  that establishes the connection. Here is the screen shot:

!!! Before tunneling make sure you are logged in by running ‘af login -u appFogUsername’

The Shell on the left you tunnel(connect to) MySQL instance and afterwards, you are able to run any inquiries you like via mysql command. As you can also see while connecting MySQL, it displayed the current instance username, password and database name that you will need next step when importing data.

Step 3 – Import Data

Once you tunneled in your MySql instance (see shell on the left in the above screen shot), you can use another shell from which you can run mysql command to import data as it is displayed in the shell on the left of the screen shot above

Alternative is to use MySql Workbench with the same credentials given to you in Step 2

!!! Once you close the tunnel(shell), the connection is lost with the MySql instance

!!! The credentials seems to stay the same next time you open connection(tunnel) into the MySql instance

After data imported, we have  our development WordPress app working in sync with production and available for testing without much developers configuring and setting up Apache, PhpMyAdmin,MySql,PHP,etc. Next would be nice to have  Gradle script to do all this for us, so that once me make change, it auto updates our cloud instance but that will be another post….till then, happy coding!

Sources:

‘Manage you AppFog data from workstation’ by Jeremy Voorihs

Documentation Installing WebKit by the RubyInstaller Google Group

 

Deploying WordPress using AppFog PaaS

I started this post thinking that i will be able to deploy PHP app on cloud just like Grails app via CloudFoundry Paas.  As i learnt, cloudfoundry directly does not support php technology, however,  if run AppFog on top of cloudfoundry this mission – deploy PHP app such as WordPress on cloud  can be accomplished. This post demonstrates an example of exactly that – WordPress deployed in cloud

In order to use AppFog, we have to do one additional step to process described in post ‘Starting with CloudFoundry on  Windows‘. That is we install AppFog

Step 0 – Installing AppFog

Open Command line with Ruby as described in ‘Starting with CloudFoundry on Windows’ post. From Command line run the following command:

>gem install af

This installed AppFog, so you can use it to deploy WordPress

Step 1 – Sign up for account on AppFog.com.

Step 2 – Configure MySql Service

In order our WordPress app to communicate with MySql db in cloud, we have to set cloud environment variables (currently auto-configuration is available only for Node.js under cloudfoundry, however, its possible in near future it will work for other frameworks as well)

So edit wp-config.php as following:

Replace:
define('DB_NAME', 'dbName');
define('DB_USER', 'dbUser');
define('DB_PASSWORD', 'dbPass');
define('DB_HOST', 'margotskapacs.com');

With:

$services = getenv("VCAP_SERVICES");
$services_json = json_decode($services,true);
$mysql_config = $services_json["mysql-5.1"][0]["credentials"]
define('DB_NAME', $mysql_config["name"]);
define('DB_USER', $mysql_config["user"]);
define('DB_PASSWORD',$mysql_config["password"]);
define('DB_HOST',$mysql_config["hostname"]);
define('DB_PORT',$mysql_config["port"]);

As you see, ‘getenv(“VCAP_SERVICES”) is way to retrieve cloud instance variables that later is passed to your WordPress app

Step 3 – Deploy on Cloud

Open Command line with Ruby and run following commands:

>af login

This will prompt for username and password you registered Step 1

>af push

Given you are in the root directory of your WordPress app. If not, you specify location by ‘ af push –path somePath’

Afterward, follow the default settings and your application will be published under domain name – yourAppName.cloudDomain that you can also find out by logging into appfog.com

Next, how do we import MySql data into our WordPress PHP app residing on Cloud? That’s in next post – Importing MySQL on WordPress Cloud Intance

 

Starting with CloudFoundry on Windows

UPDATE Nov 1, 2013: The new version of CloudFoundry API is ‘cf’ instead of ‘vmc’ and the target url is ‘https://api.run.pivotal.io’

Currently, I am using CloudFoundry to deploy my Grails applications in production and development on cloud. This post is how to configure CloudFoundry on Windows, so you can deploy application. Please, see another post for how to deploy Grails Apps using CloudFoundry or PHP Applications using AppFog

Step 1 – Installing Ruby Installer

You will need this to intall VMC – command line tool to communicate with CloudFoundry Cloud Controller

Go to Ruby Installer website and run executable to install Ruby Installer

Step 2 – Installing RubyGems

To install RubyGems, open command line with Ruby(Start->Programs->Ruby XXX-> Start Command Prompt with Ruby) and run the following command:

>gem update --system

This will install RubyGems

Step 3 -Install VMC

Open Command Line with Ruby like described avobe. Run the following command:

>gem install vmc

This will install VMC tool and with it you are able to run commands on the CoudFoundry Controller to deploy your apps. For that see the post – ‘Deploy WordPress App WordPress on Cloud using CloudFoundry’

Starting On Mac

For Mac you can skip the ‘Step1 – Installing Ruby Installer’ as mac newest OS comes with the ruby installer. Otherwise, rest is the same from Mac as Windows

Issues

1. Environment variable ‘HOME’

We were getting following error:

non-absolute home
C:/DevTools/Ruby193/lib/ruby/gems/1.9.1/gems/vmc-0.3.21/lib/cli/config.rb:92:in `expand_path'
C:/DevTools/Ruby193/lib/ruby/gems/1.9.1/gems/vmc-0.3.21/lib/cli/config.rb:92:in `aliases'
C:/DevTools/Ruby193/lib/ruby/gems/1.9.1/gems/vmc-0.3.21/lib/cli/runner.rb:427:in `process_aliases!'
C:/DevTools/Ruby193/lib/ruby/gems/1.9.1/gems/vmc-0.3.21/lib/cli/runner.rb:460:in `run'
C:/DevTools/Ruby193/lib/ruby/gems/1.9.1/gems/vmc-0.3.21/lib/cli/runner.rb:14:in `run'
C:/DevTools/Ruby193/lib/ruby/gems/1.9.1/gems/vmc-0.3.21/bin/vmc:5:in `<top (required)>'
C:/DevTools/Ruby193/bin/vmc:23:in `load'
C:/DevTools/Ruby193/bin/vmc:23:in `<main>'

This happens if you set environment variable ‘HOME’ to something. Apparently, Ruby gems is using this variable, so by having it set to something causes the above error

Installing PHP 5.2 and configure Apache 2.2 on Windows & Linux

 

Over the years it has been times when i have to reinstall PHP to configure with Apache to work together. Today, it has been that occasion where i have to set up my local developing environment on new laptop to support some WordPress, Zend and Magento developments. It has never been a smooth process and it was no different this time….i guess i was too naive thinking that things have changed….Perhaps, things have changed, i just should have looked at new ways – deploying on cloud via Saas, however. This post is PHP(3.2.17) installed and configured with Apache 2.2.22

 

Installing PHP 5.2

My first failure come with the fact that the newest PHP 5.4 and 5.3 does not support Apache. Make sure you download the right  version VC6 (on Sep 13,2012).  Later, i also learn there is differences between Thread Safe and Non-Thread Safe versions. To run with Apache 2.2.22, you need Thread safe version

1. Download proper PHP version to work with Apache on Windows

2. Extract to your chosen directory. In our case, we use ‘C:/DevTools/php’

3. Update the windows environment variable ‘Path’.

We create new variable ‘PHP_HOME’ and then append ‘%PHP_HOME%’ to the ‘PATH’ variable. To check it works, open command line and type ‘php -v’. If it works then you should see php version displayed

 

Configuring Apache 2.2

I have Apache 2.2.x installed and tested currently. For how to install Apache server, please, consult other source

1. Edited Apache Configuration file httpd.conf (by default in C:\Program Files\Apache Software Foundation\Apache2.2)

In the httpd.conf, we add these lines,  right below the other LoadModule lines:
LoadModule php5_module "c:/DevTools/php/php5apache2_2.dll" #(change the path to wherever the file is)
AddType application/x-httpd-php .php .phtml .inc .php3
AddType application/x-httpd-php-source .phps

!!! Important to note, if you have Apache2.0, then use php5apache2.dll instead of php5apache2_2.dll

 

2. For Apache to use index.php as the default index page, change the line
DirectoryIndex index.html
-to-
DirectoryIndex index.php index.html index.htm

 

3. Copy the file “php5ts.dll” to “c:\Program Files\Apache Group\Apache2\bin\”.

The ‘ts’ at the end of php5ts.dll must mean Thread Safe, so if you don’t see it you must have happen to download & install non thread safe version of PHP that will not work with Apache 2.2.22

 

4. Copy the file “php.ini-recommended” to c:\Program Files\Apache Group\Apache2\ and rename it to “php.ini”

 

5. For PHP sessions to work properly, you need to specify where to save the sessions.

Edit the php.ini file, and find the setting for session.save_path. Set it to “c:\windows\temp\” or another folder you use as a temp directory.

5a.Enable GD extension for Image handling
The GD extension is used so often to handle the images that we recommend to enabled this extension at this time. To do so uncomment the following line and specify path to the GD extension in php directory

extension="C:\path_to_php\ext\php_gd2.dll"

 

6.  Restart Apache server:

Go to start -> run -> services.msc

or

From Apache Service Monitor (Start->All Programs->Apache HTTP Server 2.2->Apache Service Monitor->ReStart)

Test Drive

Its time to test our php configuration to work with appache server. To do so, create a file phpinfo.php with content:

<?php print phpinfo(); ?>

Save this file into dir Apache is serving pages(by default its “c:\Program Files\Apache Group\Apache2\htdocs”)
This should display php configuration info file that is also useful when installing add-ons of PHP because you can come here and always check if a particular add-on was installed for the PHP

Configure MySql

We assume you have mysql installed. To configure PHP to work with mysql you have to uncomment the following line and specify path to the libraries in php.ini file

extension="C:\path_to_php\ext\php_mysql.dll"
extension="C:\path_to_php\ext\php_pdo_mysql.dll"

This will enable necessary libraries for your php sites to talk to mysql database. We also enabled pdo_mysql library that is often used by opens source platforms such as Drupal

Virtual Hosts

Virtual host allows you easy to configure multiple sites to run on your apache server with different domain names

1. Enable Virtual Hosts

To enable the virtual hosts, uncoment the following line in path_to_apache/conf/httpd.conf

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Here we uncomment line ‘Include..’ so the vhosts configurations are loaded

2. Configure Virtual host

To configure virtual host, add the following in path_to_apache/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "C:\path_to_sites\my-site"
    ServerName some-domain
    <Directory C:\path_to_sites\my-site>
        Options FollowSymLinks
        AllowOverride All
	Allow from all
	Order Deny,Allow
    </Directory>
    ErrorLog "C:\server\apache\logs\stefan-cascade-error_log"
    CustomLog "C:\server\apache\logs\stefan-cascade-access_log" common
</VirtualHost>

Here, the ‘DocumentRoot and ‘Direcory’ specifies the path where is the code base for your site located. The ‘ServerName’ specifies domain name of your site(i.e. some-domain). This can be anything as long as you update the hosts file to point request to your local computer/apache server the next step

3. Point Domain name to Apache server

In previous step, you specified domain. Lets update hosts file, so all requests made to this domain name from your browser goes to the local apache server. To do so update %SystemRoot%\system32\drivers\etc\hosts as following

127.0.0.1      some-domain

This will make all requests to ‘some-domain’ go to your local computer/apache server

Test Virtual Host

Create file of index.html with some text and put it into your virtual host as specified above(i.e.C:\path_to_sites\my-site). Afterwards restart apache and open browser with ‘some-name’ as url. This should display the text in your index.html file

Issue Encountered

1. When restarting Apache, it was giving the following error:

“The Requested operation has failed!”

The Apache logs showed no clues of whats the problem, so I run 'httpd.exe -e debug' from command line in apache/bin folder. From there, it was clear the problem:

Solution: this is because we are installing PHP that is Non-Thread safe version but Appache 2.2.22, apparently, requires to have PHP Thread Safe

2. “Permission denied: AH00529: […].htaccess pcfg_openfile: unable to check htaccess file”

This happens when the Apache user (often www-data or if not, check the file – envvars in apache dir) doesn’t have access to read your web directory. The solution is to add Appache user to the group assigned to the web dir

usermod www-data --append --groups root

Here, we add user www-data to a group named root that is currently assigned to the web directory serving your site

AH01630: client denied by server configuration

This error came after upgrading from Apache 2.2 to Apache 2.4 with old configurations of “Order allow,deny

Allow from all” in virtual host setting in 2.2 with new configuration of”Require all granted” in the 2.4

Other

1. Host File

In case you forgotten, the host file in windows are located

 	%SystemRoot%\system32\drivers\etc\hosts