Skip to content

docker4lamp - A LAMP Docker development environment

I have made this project (Docker For LAMP) publically available on Github, under the MIT license.

The target user group is php developers who want or need a simple, minimal (yet very current) LAMP development environment. I want this to be friendly to new developers, and a useful alternative to localhost environments like xamp, mamp or wamp.

Ideally it offers the type of convenience and isolation of a vagrant lamp environment except with orchestrated containers. Continue reading "docker4lamp - A LAMP Docker development environment"

Centos Virtual LAMP server -- Part II

*Part 1 of this series is here*

Customizing your LAMP server


Unix people are probably familiar with the father of the DNS system -- the /etc/hosts file. The hosts file has a simple format:

ipaddress hostname

In the days prior to DNS, people would update a master hosts file and copy it around to all the servers in the enterprise. Surprisingly Windows versions also support this file, as a way of overriding DNS, so we can use this to our advantage, by adding an entry for our development server. In this example, I'm going to use dev.gizmola.com, which is not a real server.

One important reason to do this is that Apache and other web servers, use a feature of HTTP 1.1 that specifies a header field named "Host:". This mechanism facilitates the service of multiple domains from a single apache server, through the configuration of apache virtual host (or vhost) entires. The server uses the Host name in the HTTP header to determine how to route requests, so without host name resolution. you have to use non-standard ports and other mechanisms that are more trouble than they're worth. a

Continue reading "Centos Virtual LAMP server -- Part II"

Run a Centos Lamp development server on XP, Vista or Win 7 using VirtualBox

If you use a Windows based workstation or notebook computer virtualization offers a way for you to run a linux server environment using the same linux distribution and configuration you'll use in production. Virtualization allows you to explore clustering and network setups that can't be tested on your workstation alone and simplifies your development environment by keeping the LAMP environment contained inside a VM.

While VMWare offers these capabilities with their VMWare workstation product, Sun has created a free alternative called VirtualBox, with many of the same capabilities in VMWare workstation. VirtualBox runs on a variety of intel chip based operating systems including OS/X, Windows XP & Vista, Linux and Solaris, and supports the installation of many different "Guest" operating systems. In this article, I'll detail the installation and configuration of Centos. Centos is a great choice for a Linux server operating system, as it is widely used by hosting companies due to its Redhat Enterprise Linux (RHEL) core.

Our goals in this setup will be:

• Centos server running the LAMP stack
• XP can be used to develop code using the IDE of your choice.
• The XP Workstation can communicate with the linux server using standard tools: putty, winscp, firefox
• The setup works even when no other networking is available. When a network is available, no network reconfiguration is required.
• Use XP to setup private domain resolution so apache vhost configurations can be tested.

Let's get started.

Continue reading "Run a Centos Lamp development server on XP, Vista or Win 7 using VirtualBox"

Mysql Update: Null + 1 is Null!

You can't add to Null


Here's something about mysql create table definitions that can easily catch you if you aren't careful. Consider this table definition:




mysql> CREATE TABLE screenshots (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, votes INT);      
Query OK, 0 rows affected (0.09 sec)
 


What the user wanted was a simple table to keep track of user submitted screen shots. Of course the real table had a submission date, and name column but I've omitted those in order to focus on what can happen when you allow a numeric column to have NULL values.

In the application in question, when a user votes for the screen shot they like, the system should "count" the vote, by increasing the values in the "votes" column by one. Initially the developer working on this application was trying to read the value from the database, and in a PHP web script, they would increment this value and take the result and set "votes" to be equal to it in an UPDATE statement. I explained that this could cause lost votes, because if two or more users were voting at nearly the same time, each would overwrite the value of the "vote" column. In fact there are scenarios far worse than that --- a user with a cached page could vote and set the vote count back days or weeks. I didn't bother to mention the possibility that someone might recognize what was going on in the web form, and start tampering with it, since it was plainly evident that the form was passing the current number of votes.

One of the many benefits of using a relational database is built in concurrency. In an UPDATE statement, you can add to the value of the column without having to know what its original value is, just as computer languages allow assignment to a variable that references the variable's current value (ie. $a = $a + 1, $a++).

  1. UPDATE screenshots SET votes = votes + 1 WHERE id =  


All that's needed is to have the serverside language provide a value for a particular "id" and the votes will be tallied and updated correctly. Even more importantly, mysql will serialize the updates, insuring that no votes are lost.

However, given the original Mysql CREATE TABLE statement , what will happen if our code embeds the UPDATE statement provided? Continue reading "Mysql Update: Null + 1 is Null! "

Lampsig 2008 Presentation on Subversion for Lamp Developers


Here are the slides for the presentation on subversion I gave at the September 2008 LampSIG meeting. I hope some may find them useful, however they were meant only to provide a skeleton for the talk, and aren't a complete tutorial by any means. The following links to other sites were mentioned in the talk:

The Red bean book, aka Subversion manual
The svnmerge python script
Subversion tips Article
Subversion Cheat Card


Defined tags for this entry: , , , ,

LAMP Tutorial Series originally published on PHPFreaks.com

A few years ago I published a 3 part LAMP tutorial series entitled LAMP, MySQL/PHP Database Driven Websites on the well known php community website PHPFreaks.com. This series dealt with a slew of practical issues including how a LAMP server works, relational database design using MySQL, many to many tables, SQL inner and outer joins, practical PHP debugging, php documentation tools, basic PHP classes, css, interactive javascript & DHTML with a chooser widget, php HEREDOC and php basics like how to process forms and utilize GET and POST methods.

The series was fairly successful, (a 4.5 of 5 after hundreds of ratings), many pages of comments and questions, and page views to the 100k's+ although PHPFreaks auditing system was turned off at some point and stopped recording views.

Unfortunately, some years ago PHPFreaks.com suffered some fairly catastrophic issues with its publishing system. There were also some bugs, and the site was exploited with some XSS, and the admins simply decommissioned the majority of the site. My series was part of what disappeared. At that point, a couple of college Computer Science courses on web development had taken the series and integrated it into their curriculum, and the professor of one of these courses had converted it into a Word document, which I was able to download and convert to pdf.

I plan to write a compatible publishing addon for gizmola.com so that I can take the original markup and republish it here, but in the meantime, here is the series in pdf format. The conversion utility they used stripped out the original markup, and page breaks are gone, but the text, source code, and illustrations are all still there.

I also offer all the source code for parts 2 & 3 of the series. I'm not sure what happened to the source for part 1, however, it is all included inline in the tutorial. The LAMP, MySQL/PHP Database Driven Websites series is now available in pdf format. Click here.


Defined tags for this entry: , , , , ,