Monthly archives of “January 2012

Perceived True

The same good will and kind words can be “felt” very differently, depending on who said those words & what the perceived true intentions are.

Why Do?

Don’t do something because you feel you have to, or because you feel you are in debt to someone; do it simply because you want to.

How I Setup My PHP Dev Env: Part 2

This post is the second part of a 2-part series on how I setup my PHP Development Environment using Windows 7 as a base operating system and a basic LAMP server running on Ubuntu installed on Oracle VirtualBox. (You can read the first part here)

Section 1: phpMyAdmin

To be able to manage MySQL conveniently, we will install phpMyAdmin. We will need an internet connection and perform the following steps:

  1. Fire up your virtual machine and login.
  2. Run sudo apt-get install phpmyadmin to install the package.
  3. Direct your browser to localhost:8080/phpmyadmin. You should see the phpMyAdmin login page there. Try to login using the root account and the password you designated to it when you installed Ubuntu LAMP server.
  4. If you did not set a root password for MySQL, run cd /etc/phpmyadmin to switch to the phpMyAdmin installation directory and then run sudo pico config.inc.php to edit the configuration file. Press Ctrl-W and type in allownopassword to find the keyword, and then uncomment the line. Press Ctrl-X and then Y to save the file. You should now be able to log in as root without using a password.

That’s it, we should now be able to use phpMyAdmin.

Section 2: NetBeans PHP

Now, we’re going to install NetBeans PHP as our IDE of choice. You’re free to install any other IDE to your liking, but I’m only going to explain how to use NetBeans PHP.

  1. Go to the shared folder you have set up previously (see Part 1), create a new folder for your new project, and create a new index.php file there. Just fill it up with some HTML or some code.
  2. Download the Java SE Development Kit if you haven’t already done so. This is a prerequisite to install the NetBeans IDE. Install it.
  3. Download the installation file from the NetBeans website. Install it.
  4. Open NetBeans, then go to File –> New Project.
  5. Select PHP Application with Existing Sources. Click Next.
  6. Set the Sources Folder to the folder you created in step 1. Select your preferred PHP version, then click Next.
  7. Set the Run As option to Local Web Site, and click Finish. Make sure to edit your site URL to add your forwarded port number (set to 8080 in Part 1).

We are now ready to start writing code. Try creating a PHP file and write some echoes or whatever in it. Save it and then click the play button on the top toolbar to open a new browser window/tab directed at your site.

Section 3: Apache/PHP Configuration

The apache2 server works almost out of the box, but usually we would want it to be properly configured and equipped with some of the more common modules. Here’s how to do some basic configuration:

  1. Run sudo pico /etc/php5/apache2/php.ini to open and edit the PHP configuration file.
  2. Find the date.timezone parameter and set it to your liking. You can find the list of valid timezones here.
  3. Find the short_open_tag parameter and set it to Off. This is to prevent you from coding with short open tags, which might not be supported on some servers. Press Ctrl-X and then Y to save and close the file.
  4. Run sudo pico /etc/apache2/sites-available/default to open and edit the apache2 virtual host configuration file.
  5. In the <Directory> tag for root (/) and /var/www/, set AllowOverride to FileInfo Indexes. Save and close the file.
  6. Run sudo a2enmod rewrite proxy proxy_http proxy_ftp proxy_connect to enable the listed modules needed to support mod_rewrite.
  7. Run service apache2 restart to restart the apache2 server.

That’s it. Now we’re practically ready to start cracking. I might write some more about the actual code I’m working on, which is based on CodeIgniter 2 integrated with Doctrine ORM version 2, but I can’t make any promises as of now.

How I Setup My PHP Dev Env: Part 1

This is a post long overdue. Originally started as a favor to a good friend of mine, this now has also turned into my personal quest to document my efforts to set up my PHP Development Environment on my MacBook.

DISCLAIMER: This is some geeky stuff, you have been warned.

So, without further ado, let’s get to it!

Section 1: The Operating System

I have an Apple MacBook A1342, so the documentation pertains to that specific hardware. If you have another type or brand of computer, or if you choose another operating system, the following instructions should not apply to you. You should go ahead and install your operating system as you would normally.

Prerequisites:

  1. Apple MacBook A1342, or a variant of it
  2. Apple Mac OS X installation DVD that came with the laptop
  3. Single-disc Windows 7 64-bit installation DVD
  4. Internet connection (either via LAN or broadband modem)

Steps:

  1. Fire up your MacBook and let it enter Mac OS X as usual. Find Bootcamp Assistant in your Applications folder and open it. Set up your BOOTCAMP partition. As I’ve done this 2 years ago, I don’t need to do it again, and I can’t remember the exact steps, so please go visit Apple’s support site if you need more detailed information.
  2. Insert your Windows 7 64-bit installation DVD and restart your MacBook. Hold down the Option key while booting up to show the boot options, and select the DVD.
  3. Install Windows 7 as you would normally. Select BOOTCAMP as the partition to install Windows 7 on.
  4. At this point you should be able to log into Windows 7. Now, insert your Mac OS X installation DVD, find Bootcamp for Windows, and install it.
  5. Install any additional drivers and software as required.
  6. Voila! Your base operating system is now ready.

Section 2: The Virtual Machine

I choose to use a virtual machine to host my PHP and MySQL server. Why?

  1. I can emulate the deployment server environment as closely as possible without having to compromise my development environment. This way I can only install server software as necessary, perform server configuration as if I was doing it on the real server, and reinstall the entire server if necessary without having to install my base operating system.
  2. I can take the VM with me and run it on another computer if need be.
  3. I don’t have to install server software directly on my base operating system. This keeps it lean and clean for gaming and such 😀

Prerequisites:

  1. Newest stable release of Oracle VirtualBox
  2. Installation DVD (or disk image file) of a guest operating system of your choice, or preferably an image of it. I tend to like the latest server version, so I use Ubuntu 11.10 Oneiric Ocelot Server Edition (64-bit), which is downloadable from the Ubuntu website.
  3. A preferably fast and reliable internet connection.

Steps:

  1. Install Oracle VirtualBox. Just click next next next done. Simple as that.
  2. Fire up Oracle VirtualBox and click File –> Preferences.
  3. Set your Default Machine Folder, or leave it as it is if you prefer to do so. Click OK.
  4. Specify a name for your new virtual machine, set Operating System to Linux and Version to Ubuntu (64 bit). Click Next.
  5. Set the RAM allocated for the virtual machine. Usually 512MB is enough for servers, but you’d probably want to use more if you intend to install the desktop version of Ubuntu. Click Next.
  6. Create a new virtual hard drive. Leave all options as it is and click Next to bring up the virtual hard drive dialog. Select VDI, Dynamically Allocated, and set the size to your liking. I use 20GB.
  7. Click Next, then click Create. After the hard drive dialog disappears, click Create again.
  8. Insert your Ubuntu installation DVD or set the disk image file in Settings –> Storage –> IDE Controller and start your virtual machine.

At this point you should be booted into the Ubuntu installation DVD. Let’s move on:

  1. Select English and then select Install Ubuntu Server.
  2. Select your language and location, and configure the keyboard if necessary. I use English (U.S.).
  3. Specify your hostname.
  4. Set up your partitions. To keep it simple, I use guided partitioning using the entire disk.
  5. Set up your user name, password, and home folder encryption (if you want to).
  6. When asked for a proxy configuration, leave it blank. The installer should start downloading stuff using apt.
  7. Choose your automatic security update setting.
  8. In the software selection, select LAMP Server and Mail Server. Select Internet Site for the mail server setting.
  9. It’s safe to install GRUB as recommended, go ahead and do it.

Section 3: VirtualBox Guest Additions

Proceed until the virtual machine restarts, then shut it down. Remove the Ubuntu installation DVD (image) from the (virtual) drive and insert the VBoxGuestAdditions.iso image from C:Program FilesOracleVirtualBox. Now it’s time to play with the command line:

  1. Run sudo apt-get update to update the repository to the latest source.
  2. Run sudo apt-get dist-upgrade to upgrade all installed packages to the latest version.
  3. Run sudo apt-get install dkms to install Dynamic Kernel Module Support (DKMS), which will be used to install VirtualBox guest additions on your Linux machine.
  4. Run sudo mount /dev/cdrom /media/cdrom to mount the VBoxGuestAdditions media.
  5. Run cd /media/cdrom to switch directory to the mounted media.
  6. Run sudo sh ./VBoxLinuxAdditions.run to install the VirtualBox Guest Additions.

Section 4: Shared Folders

Now that we have VirtualBox Guest Additions installed, we can start adding shared folders to the virtual box:

  1. Shutdown the virtual box, go to Settings –> Shared Folders, and create a shared folder referencing a directory of your choice on the host machine. Take note of the share name.
  2. Run mkdir /home/[your_username]/public_html to create your own public html directory. This will be the mount point of the shared folder.
  3. Run id [your_username] to find out your uid and gid. Take note of this.
  4. Run cd /etc/init.d to change to the startup script directory.
  5. Run sudo pico vboxshare-automount to open pico and create a new file called vboxshare-automount.
  6. Write mount -t vboxsf -o uid=[your_uid],gid=[your_gid] [your_shared_folder_name] /home/[your_user_name]/public_html in the file. Press Ctrl-X and then Y, enter, to save the file.
  7. Run sudo chmod +x vboxshare-automount to make the file executable.
  8. Run sudo update-rc.d vboxshare-automount defaults to make the script run on every startup.
  9. Restart your virtual box, then login and run cd public_html. If you run ls, you should see the contents of your shared folder there.

Section 5: Port Forwarding, User Directories, and PHP Parsing

Alright, we now have a shared folder that we can use to directly edit our PHP files. Now we need to enable our host machine to access the virtual box’s PHP server:

  1. Shutdown your virtual box if it’s not already off.
  2. Go to Settings –> Network –> Adapter 1. It should be set to NAT by default.
  3. Click on Advanced and then Port Forwarding.
  4. Click on the add icon, then set rule name to http, protocol is TCP, host port 8080, and guest port 80.
  5. Start up your virtual box.
  6. Fire up your browser and go to http://localhost:8080. You should see the default apache2 page saying that it works.
  7. Now go to the virtual box’s console and run sudo a2enmod userdir to enable per-user directory service.
  8. Run sudo pico /etc/apache2/mods-available/php5.conf to edit the PHP5 module configuration. Comment out the part between the <IfModule> tags to enable PHP parsing in home directories.
  9. Run sudo /etc/init.d/apache2 restart to restart the apache server.
  10. On your host machine, create a new file info.php in the root of the shared folder. Fill it with the usual phpinfo(); code.
  11. Direct your browser to localhost:8080/~[your_user_name]/info.php. You should see the PHP information page there.

That’s it. Now we have a working Apache/PHP server running on Ubuntu and accessible seamlessly through our Windows machine. Next we should check if we have phpMyAdmin and everything else we need to really start cracking. But I think I’ll save that for another post: Part 2.