Start using Fuel PHP today


The last few days I have been busy looking at the Fuel PHP framework. And it’s AWESOME. That’s not a great description, its not even very objective, but none the less it is true (you will have to take my word for it now). The framework can be found at fuelphp.com.

Today I am going to give a quick guide for installing and running Fuel PHP on a linux machine and some extra cool tricks to make the setup easier. First what things do you need, assuming that you have a fresh linux install.

  • apache webserver
  • php 5.3 (needs to be at least 5.3)
  • php cli (command line interface)
  • mysql database server
  • command line editor vi or vim (not totally necessary but i will assume that you have one as I believe command line file editing to be the easiest option)
  • wget or curl (fuel documentation uses curl but either could be used)

I will also assume that you have root access and that you are on a home computer using localhost for your domain. Production environments require more careful setup and I will address those issues in a completely different post.

Lets Go

1. install all the necessary components

sudo apt-get update
sudo apt-get install php5 php5-cli apache2 mysql-server phpmyadmin curl vim git-core

2. install the fuel PHP oil installer. (that sounds strange)

curl get.fuelphp.com/oil | sh

3. change into the directory that you want to build you fuel application in and run the fuel PHP oil create script. replace {user} with your username and {app name} with the name you want to give your application. it doesn’t matter what the name is as it wont get used in the website URI

cd /home/{user}/Public/
oil create {app name}

4. Now it that’s as far as the basic section of the documentation on the fuelphp.com documentation website. However you cannot access the app in the browser yet. Before you can do that there are a few steps that you must take. We have to set up the apache virtual host. This greatly varies on you operating system, but for simplicity I will cover just Ubuntu, and will cover different OS’s later. We need to alter the virtual host so that it follows symbolic links and knows what the root directory of the website is. Because the fuel index.php file is in the public folder in the actual top directory we will include the public directory in the website root directory.

sudo vim /etc/apache2/sites-enabled/000-default

Now make the file look like this:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /home/{user}/Public/{app name}/public
        <Directory />
                Options FollowSymLinks
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
        <Directory /home/{user}/Public/{app name}/public>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

Restart apache to apply the configuration changes

sudo /etc/init.d/apache2 restart

5. If everything worked you should now be able to go to http://localhost/ and the fuel app page should be visible. It looks a little bit like the codeigniter welcome page. (most of the developers of fuel have or still do contribute to codeigniter).

Conclusion

Hopefully this is guide is a relatively straight forward explanation of how to set up fuel on a new development environment. Any questions or comments are appreciated. I’m sure I made a mistake somewhere in there or perhaps it just didn’t work on your computer. I would also love to get some suggestions on what you would like to see next.

Using APT – The Complete How to Guide


Debian’s APT (Advanced Packaging Tool) is an amazing program that adds greatest level of manipulability to the distributions that use it. It enables the user to control the software that runs on their computer, making it exactly the way they like it, without any extra programs that do not get used. This is unlike any other non-*nix operating system, giving A clear advantage, in my opinion, to it’s users.

Essentially APT is a front end to dpkg, a base level program for installing and removing and providing information about .deb packages. Going into depth of dpkg and .deb files is for another time, but briefly a .deb package is a way of puting a program into a container that makes it’s installation much simpler for the end user and dpkg was written for handling these packages.

APT is also able to use the RPM package management system, using the apt-rpm method (explained later). This is a newly acquired feature of APT which I believe that was added to make the Debian distribution POSIX compliant. RPM was created for the Red Hat Linux distribution as a simple package management system which has solid dependency handling.

Now APT is available on all Debian based distributions such as Ubuntu, Mint, Knoppix and a number of others, as well as Solaris (not open any more). This means that of all the users of Linux distributions, many have access to APT. Lets see the program in action. Open the terminal and enter the following

sudo apt-get update

To run the APT program you must run as a super user or provide super user privileges. You will also notice that there is the `tack get` addition of the apt program. This is because the program has many sub layers, with others such as apt-cache, apt- secure and apt-key. The update program updates the latest information from the sources list.

The sources list is the location of the Debian packaged programs that are installable via a direct download from apt-get. Finding the best sources for the apt-get program will be in a quick tip, for now we will assume that all the sources will be the optimal ones. Now lets perform a second command related to the sudo apt-get update command, upgrade

sudo apt-get upgrade

This command upgrades the current installed programs in a number of ways. First it checks to see if all the packages are the latest version of the installed programs. If there are new versions it does a dependency check and asks if you would like to update at which stage it will let you know of any other programs need to be installed. (hit enter here) It will then proceed to update and install until your current installed programs are how they should be at their newest version.

How about installing programs. Simple ! Just use the sudo apt-get install command. The trick is knowing exactly what program you need. For example, I am writing a program which works with a database in c. I need the mysql header files which are not installed by default. The trick with accessing header files is to download the development packages of the need programs so I used the following install command.

sudo apt-get install libmysqlclient-dev

These 3 main commands can handle 90% of your apt needs. Below is a list that i have compiled about commands and there functions that you may come across needing in your use of the program.

sudo apt-get remove `program`

This removes the installation of the program specified but still lives on the system

sudo apt-get autoremove

This automatically removes all the programs which are not being used and are not depended on by any other programs.

sudo apt-get clean

This cleans the archives of the downloaded programs. Any Archives that are not needed are removed, freeing up space.

sudo apt-get autoclean

This automatically removes the archives that are not needed and any dependencies as well

sudo apt-get source `program`

This downloads a source version (if available) that will need other install methods, in order to examine the source code and build specifically the way you choose.

deb `link` `version` `relationship`

This adds a source to the list. Link is source location, version is the word number of the version being used eg ubuntu uses “hardy” or your version equivalent and debian would use ‘lenny’ for v5 or ‘squeeze’ for v6. The relationship is a little more complex. Most likely it will be partner, But it may equally be universe or multiverse.

apt-cache search `program`

searches all repositories and list ever instance of the program. This is a great way to find a program that you are looking to download.

sudo apt-get dist-upgrade

This updates packages which have may have any number of dependency discrepancies.

This list is incomplete. Its a ‘working copy’ of the most commonly used apt commands. The important thing to remember is to run the update before you start working with apt so that you have the latest information, as well as anytime you add or remove sources.

If you have any questions or use any commands relating to apt that I haven’t listed, please let me know in a comment below.

Installing the Base System – Ubuntu Server


Now we have the hardware, and the software setup and ready to go, we can begin the install. make sure that you have set up the hardware with all the peripherals attached.

Step 1

First we must enable the computers BIOS to load from the cd. To do that turn the computer on. Depending on the chip set of the computers motherboard there will be different keys for entering the BIOS setup. It is usually either F1, F2, del, esc, or F10. press one of these key before the computer loads the boot loader screen. Once into the BIOS you will want to find the boot load order. Once you have found the boot load setting, change the order so that the CD-DISK option (or similar) is number one.

exit and save from the BIOS screen and insert the install disk from Part 3.

Step 2

The computer will load into the disk. First it will ask for your language, Hit enter for the default (English) or select your preferred language. Next it will bring up a basic option list. Select the “install ubuntu server” option. This will then load an ncurses screen (blue white and red with monospace font). It will then as a for a number of options

  • Select your langauge
  • Select Your Location

You will now be asked whether you want to automatically select your keyboard. I have never had this work successfully, however you could give it a try, particularly if you have a non standard keyboard, otherwise select no.

If you pressed no and you have a standard keyboard it is a US keyboard. There will be 2 or 3 screens where you must select your keyboard. If you have a nonstandard keyboard, select your variation.

If you pressed yes you will have to press some keys and it will work out which keyboard you have. There will be multiple keys.

Step 3

After selecting your keyboard the installer will load a few additional component and then set up DHCP. This means it is looking for an Internet connection. If you do not have an INTERNET connection auto detection will fail and you will have to select “set up DHCP later” other wise it will auto configure and you should be able to move straight on.

If it fails and you have the server plugged in to the Internet there are a few simple things you can check. Make sure that if you have multiple Ethernet ports (multiple NIC’s), try changing the Ethernet cord to another port. Make sure that you actually can connect to the Internet on another computer (you should have another computer else you wouldn’t need to set up a home server).
You can also try manually setting up the DCHP setting, although that shouldn’t be necessary.

You will then need to set the host name. You can set this to what ever you like.

You will then be asked whether you the time zone detection has configured the correct zone, if it has not you will need to change it, otherwise hit enter.

Step 4

Now we have to setup the partitions. Select The Guided – use entire disk and setup LVM. You will then need to select which hard drive you want to use. Select the one that you want to install the primary operating system on. It must be no less than about 10GB, although for the best results from a home server 60 – 80 GB would be optimal (For there to be enough room to backup and store all of your important information.

Next select yes you would like to save the changes. The next screen will ask you for how much you would like to use for the / (root) and swap partitions. I suggest using no less than 20GB or 40 – 50% of the drive. This allows for expansion if necessary.

Save the Logical Volume Management and write the changes to disk.

Step 5

After the completion of Step 4, The system will be installed. At some point, you will be asked to enter a name for the new user. This is the main user that controls the server, they will have root access through the sudo command. You cannot call this user admin or root. I suggest entering your Name.

Next You need to enter the users username, I usually make this my first name or administrator. but it is up to you (you cannot use admin or root). You will then be asked for the users password. If you will be able to access the server from the Internet ie it servers web pages or has public ftp etc, you will need a strong password. Make it more than eight letters, with a mixture of numbers, lower and uppercase letters and if your frantic symbols as well. If you home server will never be accessible from the Internet then you can make the password as simple as you like (still suggest at least 4 letters).

The last two parts of step 5 are 1 – do you want to encrypt you home directory. The answer here should be no. unless you are storing sensitive data it won’t need to be encrypted and 2 – are you behind a proxy. Leave this blank unless you use a proxy server to connect to the Internet

You system will now start to install

Step 6

After a short period of time you will be asked whether you want to automatically update your system. You should manually do this for greater control, so select “No automatic updates”
Another short period of time later you will be asked what extra software you would like to install. I prefer to manually add extras software so I would hit enter, however if you would like the installer to automatically setup the system add which of the servers you would like it to setup by scrolling to the server and pressing space bar and hit enter when you are finished.

The installation is now nearly complete, all you have to do is hit yes when asked if you would like to add the grub boot loader to the master directory and then when prompted remove the cd and restart the computer.

Now you have installed the base ubuntu server.

Next we will add setup users and and user version control so that the files can be better managed.

Removing a file from the command line


In my last post I talked about the 3 main ways of creating files from the command line. Today I will look at how to remove a file. Generally, to remove anything you would use the following command.

rm myfile.text

This is a very simple command, although by using some flags we can make it both safer and easier to use. -I gives a prompt before removing three or more files or when removing recursively, -v (or –verbose) prints everything that has been removed. You can also use the sudo command to remove a file from a folder where you do not have permissions to write.
(more…)

Quick Tip – Fixing a Failed Apt-Get Update – Ubuntu


Woke up this morning, and as usually I had new software to download and install through updater on Ubuntu 10.04. So I click install updates and about halfway through updating it stops. No apparent reason, but the windows is frozen and cannot be closed.

After a quick search on the Ubuntu forums and a look at man apt-get, there appears to be a fix. (more…)

Choosing A Version – Ubuntu Server


Arg. So many flavors. Linux comes in many varieties, and then those varieties have versions. It can be so difficult to choose.

At the first level, Linux is broken up into distributions. There are many different distributions, and while on some level that are all fundamentally different, Many have the same general base. For example Ubuntu, Mint and Backtrack are all derivatives of the Debian distribution, an Operating system based upon fundemental principles and a complex package management system (read more about apt here)

For the next two levels of variety i will be referencing the Ubuntu distribution.

On the second level each distribution has a number of release versions of there OS. They are usually the latest release and a long term support release. The latest release is a stable version of the development version that is actively being worked on, and while it is stable, it is the most likely to break. The long term support release (LTS) is version which is more robust and will be supported further into the future.

At the next level down, each release version comes in a number of version for each CPU type. You can get 64 bit and 32 bit architecture OS and a version that supports arm architecture as well as many others. Mostly likely however you will have an Intel CPU and so will either use AMD64 or i386 versions.

Lets look at an example of choosing a Linux OS. For this example i will be selecting a OS for my server.

First off, we have to make a choice on the preference of which distribution we want to use. I love Debian based distributions, and have recently set up a number of Debian based servers for family friends. As Ubuntu is Debian based, and seems to trend well, i am going to stick with Ubuntu.

Now we need to make a decision of which release to choose.

As I primarily and building an experimental server, to run software that is new and need the all the latest builds, I am going to go with 10.10.

Next, you will need to know what hardware you have. Ideally you should choose AMD64. This version uses a 64bit address system and is far more extensible. Its a little bit better for some processes and not quite as fast for others. If you have older hardware, you may have to use the i386 type. It uses a 32bit address system and is perfectly fine for the home sever.

Always go with the AMD64 version. 64bit programming and process is the way of the future. If you are setting up the server on an old computer running a 32bit only CPU such as a Pentium 3 or 4, you will need to use the i386. The 64bit architecture also allows for much more memory, up to 64GB in the Ubuntu kernel (may be different for server edition), while the 32bit architecture only allows 4GB of memory (strictly speaking you can install software to support more).

You also need to choose which system you creating. This is easy now, where creating a server so we will need the server edition. Below is a description of the different system types for later if you need to know the differences

  • server
  • desktop
  • netbook
  • alternate

Server edition has the main difference to all others of a different kernel I/O handler and no GUI by default. despite this you can still install a GUI with apt-get install gnome-meta or KDE-meta packages

Desktop edition is the standard Ubuntu that comes with all the bells and whistles that makes an operating system useful to the primary end users. I has a GUI (Gnome of KDE depending on your choice) and standard applications and accessories.

Netbook edition is a slim and trim version of the desktop edition. As of Ubuntu 10.10 it uses a different graphical rendering program to display the on screen information and has a different layout.

Alternate edition is the same as the desktop edition, however it comes without the live (demo) functionality. This provides a much greater control over the set-up procedure but as a restore disk is more limiting.

My computer is very old. It runs a Pentium 3 and only supports 32bit architecture (I also only have 2GB RAM) so I will be using the Ubuntu below.

ubuntu-10.10-i386-server.iso

This is the version that I will be using throughout the series of setting up a home server.

Adding New Software – Ubuntu and Fedora


The greatest advantage the Linux, in particular the larger distributions such as Fedora and Ubuntu, is the vast amount of easily available software the can extend a basic setup and make it suitable for any possible situation. This is then made insanely easy by package management.

Think of package management as the ability of the user to look at all the possible software that they need and select, install, setup and troubleshoot and then provide a way to automate the procedure. It’s like the master key that unlocks the heart of functionality of Linux. The two big package management programs are yum on Fedora (and CentOS)  and apt on Ubuntu (and anything that is Debian based). They both work basically the same way and provide similar functionality. (more…)

Why Choose Ubuntu Server


Why Not.

Today, servers come in many many flavors, If your reading from a web browser you got your IP address from a DHCP server, sent information to a DNS server, more information to a web server, which accessed a database server. It is inescapable. And although it is undeniable that servers are everywhere (and will one day take over the world and rule with an iron fist) Why would you need one?

I use a server in my home for a number of reasons. I have 2 desktop computers, a laptop and a home built router. My server is the place where everything is put together and all the behind the scenes work happens. I never have data loss (theoretically that is) and all of my data and internal information is stored. I also can play games with my friends on it and it also allows my printer to be accessible from just about anywhere. This all happens because I have a server running Ubuntu 10.04 (more…)

Creating and Using Symlinks


Often we want some files to be in two places at once. Perhaps you are working a website that has its files in you home folder and then you want them to be displayed in /var/www/. Or maybe the software that your working with requests specific files in one folder but another program wants the in their current one. Despite the difficulty that I have in describing why you would need such an ability, There is know denying that eventually you are going to need to know how to use symlinks.

At the most basic level a symlink (AKA the Symbolic Link or sometimes referred to as a soft link) is a pointer that points to the actually location of the files without the program knowing that the files are not actually there. It also allows for a there to be differences in group and ownership if the content of a file, but more of that another time. (more…)