Tim Keller

Web, IT, Telecoms, Development, Networks, Photography, Life.

Archive for the ‘apache’ tag

PHP on Windows – Blasting off!

with 4 comments

The mention of “PHP on Windows” to a developer is most commonly met with polite but pointed laughter, if not outright disgust. Historically, this reaction wouldn’t be entirely inappropriate. But that has all changed with the advent of Internet Information Services (IIS) 7 and its FastCGI handler.

Coming from a Linux background, I was skeptical about running our mission-critical apps on Windows. We had a lot of infrastructure built around the traditional LAMP stack, and the mention of throwing Windows IIS in its place was somewhat shocking. But, I can tell you that the transition to IIS7 is utterly painless, and brought with it some incredible advantages.

For the first time, we’re able to easily integrate our PHP products with ASP.NET code. We can build Rich Internet Applications with ASP.NET AJAX on the frontend and PHP on the backend. Even Silverlight 2.0 applications can be enhanced with familar PHP code to create something of value.

At DevDays 2009, which kicks off in Durban on the 10th of March, I’m going to be showing developers just how great it is to develop and deploy PHP applications on the Windows platform. Be there, or be PEAR :)

Written by Tim Keller

March 6th, 2009 at 12:28 pm

Setting up LAMP within a small network

without comments

My friend Alain K is deploying the first version of his soon-to-be-released desktop application, WealthWorks. It is designed for Personal Financial Advisors and Investors that need to track client information, risk profiles, investments and returns. He has a MySQL backend with which the C# client application connects.

Due to the latency on South African DSL connections and the fact that the application is quite chatty, he is installing database servers within company intranets. This tutorial goes through the basics of making this work on a network where there are no static public IP Addresses available.

Decisions

Start with a piece of paper. Draw the network including any cables, routers, computers or switches that you think are important. This will give you a broad understanding of where your server fits into the picture.

The computers on the network will access the server you are setting up via its IP Address. Ask the network administrator for an open address which you can use.

Configure the computer to use this address as a Static IP.

Tutorial: Setting up a Static IP on Windows (Read)
Tutorial: Setting a Static IP on OSX (Read)

MySQL Installation

Start by installing MySQL. If all you want is the database server then head over to the download page on MySQL.com and grab it. If you need a full Apache+MySQL+PHP stack then take a look at WampServer (Windows only) or XAMPP (MacOSX, Windows, Linux, or Solaris). Both packages include very cool GUIs for installing and controlling the server.

MySQL Management

You’ll no doubt want to change the root user password and upload your database scheme to your newly installed server. I personally use Navicat – a great GUI for MySQL which comes in both a paid and free version. Give it the IP address you chose earlier, and the username and password of ‘root’ and blank (nothing, empty string, etc) respectively. In no time at all you’ll be browsing your database.

At this stage, all the other computers on the local network should be able to reach MySQL on the IP address you specified (remember, it serves connections on Port 3306).

Accessing it from the outside

The next step is to make your database accessible from outside of the local network. If you’re a consultant working from home or a different office, you’ll undoubtedly want this sort of access. Similarly, you may want clients to be able to connect in via the internet.

You need to tell your router to accept all incoming mysql traffic and push it to that server. We call this Port Forwarding. We are going to forward all traffic (on mysql port 3306) to our mysql server on our local network (also port 3306).

Follow the instructions on PortForward.com to configure your router.You want to forward all incoming traffic on port 3306 to 10.x.x.x (or 192.x.x.x) on port 3306.

Likewise, if you’ve got an Apache, MySQL, PHP setup on the server, you’ll want to access the website/webapplication by going to a URL from a web browser. The trick is to sign-up for a free DynamicDNS account at www.dyndns.com and add that to your router’s configuration.

I trust this helps! Suggestions and thoughts, please :)

Written by Tim Keller

August 28th, 2008 at 3:56 pm

PHP+MySQL from the Mac OSX Terminal

without comments

I had to write a CLI PHP script today as part of the job-parser for the SMS module in ChirpSchool. The parser executes every 5 minutes as a cron-job and dispatches waiting messages in the Message Queue.

I ran into a small problem in that the Command-Line-Interface PHP binary was different to the one running on my Apache+Mysql+PHP stack so the CLI PHP didn’t know which MySQL socket to attach to:

Warning: mysqli_connect(): (HY000/2002): Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’

The solution is simple. I am using Mac OSX 10.5.4 Leopard and XAMPP.

  1. Find out which PHP you are using from the terminal by typing ‘whereis php’. It is no doubt /usr/bin/php.
  2. Create a php.ini in /etc. Type ‘sudo cp /etc/php.ini.default /etc/php.ini
  3. Then open this new file in something… I did a ‘sudo nano /etc/php.ini’.
  4. Edit the mysqli.default_socket parameter (or mysql if you aren’t using the new improved driver) to point to the MySQL socket Apache is using. Mine was at /Applications/xampp/xamppfiles/var/mysql/mysql.sock (your’s may be at /tmp/mysql.sock)
  5. Be sure to save this new php.ini. Remember, /etc is protected so you won’t be able to save the file unless you have sudo’d yourself admin rights.
  6. Commenter ferzkopp kindly reminds us that an Apache restart may be neccesary to get this activated. Thanks for the Tip!

Hope this helps!

Written by Tim Keller

July 13th, 2008 at 6:24 am

Posted in Uncategorized

Tagged with , , , , , , , ,