Showing posts with label Debian. Show all posts
Showing posts with label Debian. Show all posts

Wednesday, February 3, 2010

Howto Tutorial on setting up Apache2, Php5, Mysql 5.0, phpmyadmin 4 on Debian Lenny (Squeeze Repos)

Recently, I had to rebuild my debian server, and decided to cover (in more depth this time) setting up several essential web server services.  I enabled the squeeze repositories, (I need them for the deluge torrent server setup).  The first thing we need to do is install apache2.


Apache2 Setup and Basic Configure

sudo aptitude install apache2
This should automatically set up and configure apache2 for you. It should also start the apache2 service at the end of installation. If not, here are some useful commands for apache2:
sudo /etc/init.d/apache2 [stop | start] - Starts or Stops the apache2 server.
sudo /etc/init.d/apache2 [restart | reload] - Restarts the apache2 server, or reloads the apache2 configuration files. Many times, all you will need to do is reload the configuration files and not restart apache2 entirely to apply changes.
Note:  When you install apache2, it creates a new user named "www-data".  This is the user that apache2 uses.  By default, the document root for apache web server is /var/www/
To test your configuration, type http://localhost or IP address if you are configuring remotely, and it should say "It works!".
Many of the configuration options can be changed by editing the apache2.conf file.
sudo nano /etc/apache2/apache2.conf
As well, many user configurations can be written to the httpd.conf file located in /etc/apache2/ folder along with apache2.conf
If for some reason apache2 is not working, you can ensure it is running by using the following command:
ps aux | grep apache2
This should list at least a few instances of apache2 running.
As well, if you want to change site specific settings, you can edit your default site file:
sudo nano /etc/apache2/sites-enabled/000-default
Next we will be covering PHP5, and how to integrate that into apache2.

PHP5 Installation and Integration with Apache2


Installing php5 is quite simple:
sudo aptitude install php5
Installing php5 should automatically link it with apache2 correctly. However to ensure that it is installed correctly, or if you encounter problems, you can check the following.
sudo nano /etc/apache2/apache2.conf
Around line 115, you should see the following lines:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
Make sure these lines are correct, and not commented out. This ensures that apache2 loads all of the enabled mods. Now if we want we can check to see which mods we have in our enabled folder.
ls -la /etc/apache2/mods-enabled
Notice that the mods-enabled are all links to .conf and .load files in the mods-available folder.
If you want to enable a mod there is an easy way to do that in debian:
a2enmod
This should bring up a large list of modules you can choose from to install, so just type the module you wish to install and apache should install it.
Next, you will notice that apache2 will not server .php file extensions by default, when there is a index.html file in the folder.  This is caused by a specific mod that is enabled with apache2 by default when installed.  The mod mod_dir controls what extensions and names are served first.  To change this we use the following command:
sudo nano /etc/apache2/mods-enabled/dir.conf
You should see the following line:
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
Change this line to suit your needs and you should be all set to go. Now, to test you php installation, you can create a simple php page and load it in the web browser. It should display a large amount of information about you php installation.


If the page loads successfully without errors, you should have php5 installed correctly.

Mysql 5.0 Server Installation and Configuration


sudo aptitude install mysql-server mysql-client
Follow the command prompts to set up an administrator password and you should be all set, mysql server 5.0 should be installed. To test the installation, log onto mysql:
mysql -u root -p
Enter your password and you should be logged into your mysql server. If you are good at mysql that might be all you need to get things done. However for those that need a little more help, we will install phpmyadmin.

Phpmyadmin Install and Configuration


Phpmyadmin is a very powerful tool for managing your mysql installation. Installing has to be done after you install your webserver, as phpmyadmin will automatically set itself up.
sudo aptitude install phpmyadmin
I am installing version (4:2.11.8.1-5+lenny3). As the package installs, it will prompt you to select the web server you have installed. Select apache2, and you should be all set. To access phpmyadmin, you should be able to navigate to http://localhost/phpmyadmin, and once you log in you should be able to manipulate mysql from your web browser.

Monday, November 9, 2009

Example Preseed file tutorial for Debian Lenny PXEboot Server

 The Default File
The next step for our PXE Server (for the previous step see here) is to make an option for an automated deployment.  This is especially useful in a production environment as you can network boot a computer, feed the appropriate options in the command line and walk away, with entire confidence that the OS will install flawlessly.  Now for the preseed file to work correctly the default file needs to be edited (again, see here). 

If you inspect the file above you will notice the line that is used for the preseed.cfg file, which must be one line, but is broken in this example for formatting. :
LABEL lenny_i386_autoinstall kernel debian/lenny/i386/linux append ramdisk_size=14984 locale=en_US console-setup/layoutcode=en_US netcfg/wireless_wep= netcfg/choose_interface=eth0 netcfg/get_hostname=DebianServer netcfg/get_domain= console-keymaps-at/keymap=us url=http://IP ADDRESS/pxescripts/preseed.cfg initrd=debian/lenny/i386/initrd.gz --
Alright, lets break a little bit of this down.  In order for our auto installation scheme to work, there need to be some options passed on directly to the kernel, and lets go over a few of them.
1. ramdisk_size - stores some execution space in the RAM, speeds things up.
2. locale=en_US and console-setup/layoutcode=en_US - setting US English as the default language
3. netcfg/wireless_wep - I believe this is for a wireless password, but not entirely sure.
4. netcfg/choose_interface - This allows you to chose the network interface that will be used
5. netcfg/get_hostname - allows you to set the hostname of the machine.
6. netcfg/get_domain - allows you to set the domain of the computer
7. console-keymaps-at/keymap - allows you to set the keyboard mapping
8. url=http://IP ADDRESS/PATH/preseed.cfg - specifies where the preseed.cfg file can be found.
Now you will notice that many of these are defined in the default file... if I wasn't lazy, and this was a work environment, it would be better to manually enter at least one of these, namely netcfg/get_hostname.  This way I would not have to go back and change the hostname for almost all of the machines... a big time saver.  As well, you'll notice that to fetch the preseed.cfg file I used a http:// address.. I believe a ftp:// and file:// prefix will work as well.  Now, the reason these options all need to be passed on directly to the kernel is because many of these options are asked before the networking is configured.  So until the machines gets an IP address during installation (which is after the language is decided) the preseed.cfg file is not available to fill in the answers... so these options need to be directly passed onto the kernel.
The Preseed.cfg File


Now I will explain some of the more cryptic/hard to grasp elements of the preseed.cfg file
The first few lines set the installer language and keyboard layout... I don't think those are necessary, they should have passed directly to the kernel.  Next, I am telling the installer to automatically choose the interface to use.  The next few lines are not necessary, as we passed those on directly to the kernel.  The mirror settings section is very important, especially if (like me) you decided to cache (using apt-cache or apt-mirror) files to ease bandwidth traffic.  The first two lines select the country, and the directory string sets the distribution.  The proxy string is the key for making sure the files are pulled from your personal apt-cache.  As you can see, I'm pulling it from my web server, with the port for my apt-cache defined. Next, the suite specifies the version of the linux distro.  The partitioning can be difficult to set up, especially if your machines have one, two or more hard drives.  If the machine only has one hard drive, specifying a hard drive is not necessary.  Since one of my testing machines has two hard drives, I added the "d-i partman-auto/disk string /dev/hda", which specifies that the installer should use the first hard disk.  Next, after selecting lvm for the method, you can choose one of the pre-defined partitioning schemes.  The options are:
# - atomic: all files in one partition
# - home:   separate /home partition
# - multi:  separate /home, /usr, /var, and /tmp partitions
As you can see, I chose the atomic method.  For improved performance, you may want to choose one of the other methods.
Next, you can set up the user accounts and passwords.  The first thing you can do is set the root password.  In the example, the password is sent in clear test (it is masked in the example), but I certainly recommend you send the password as a MD5 hash.  To generate a MD5 hash, just run the following command:
$echo "password" | mkpasswd -s -H MD5
Next, you can choose the package that you want to install.  I chose the standard desktop install.
Essentially, that covers the trickier parts of the preseed.cfg file.  Happy automated installing!

Monday, November 2, 2009

Tutorial, Howto setup Debian Lenny Linux PXEboot Server with DD-WRT DHCP options

Recently, I decided it was time to drop the CD/DVD installs of linux and move to something easier and quicker (although that is debateable).  As well, a few of my computers have no disc drive and switching disc drives from computer to computer gets very old very quickly.  As well, if a computer has a slimline drive opening the case to temporarily add a CD/DVD drive is too much work.  I finally decided to install a PXE server on my debian box, to allow network booting. Networking booting is an extremely handy way to install operating systems, boot to recovery tools, ect.
 Installing and Configuring a Tftp Server
The first thing we need to do is install a tftp server. The tftp server will be used to serve the files to the computer that is booting up. To install a tftpd server on debian we do this from the command prompt:
$sudo apt-get install tftpd-hpa
When you install the tftpd-hpa server, a few dialogs should come up. Just make sure you set the correct path for the server root. The newest version of tftpd-hpa is different than the older version, but since I'm running the cutting edge, I will be covering the newest version. After configuration, we will need to make sure the config file is setup correctly. If you ever need to reconfigure the file just run the following command:
$ sudo dpkg-reconfigure tftpd-hpa
Now to take a look at the config file:
$sudo nano /etc/default/tftpd-hpa 
The config file should appear as follows: Ensure that the "TFTP_DIRECTORY = /var/lib/tftpboot" directory is the correct path to your tftpboot directory. Everything else should be correct.
 Creating the Directory Structure/Downloading the Files
Now we need to create the directory structure necessary for PXEboot.  First, create the directory /var/lib/tftpboot.  Next we will be creating several files and directories.  When we are finished, the directory structure will look as follows. 

Next, we need to download the appropriate initrd.gz, linux, and pxelinux.0 files, which can be found several places.. such as here.  In the newest version of debian PXEboot, they have a GUI bootable version, however I decided to stick with a text boot version, and this tutorial will be about that option.  Once the initrd.gz, linux, and pxelinux.0 files have downloaded, put them in the appropriate folders.  In my configuration, I also have a xen folder for booting and installing a xen server, but that is not covered here.  If you are interested, the xen boot option should be available for download from the download link above.
 Creating the Menus and Defining Options
 Next we need to create the default and the boot.txt files.  The boot.txt file is the menu that shows up when you boot the computer.. in this example it will be a text only file.  The configuration of the file is extremely simple.  The only part you need to pay close attention to is the exact wording of the boot options.    
Next, we need to create the default file, which links to the boot.txt file.  The default file should look something like this:



The text box is not wrapped, to prove a point. Everything entered after the append option must be on one line, otherwise it will not work.  The labels in the default file must match the labels in the boot.txt as that is how the files are linked.  Obviously, you can add new labels to the default file, as long as you match it with the boot file.  I added the lenny_i386_autoinstall label, which will hopefully be covered later.  The DISPLAY option tells the PXEboot server what file to display for the menu.  The DEFAULT option tells the PXEboot server which label is the default label, which works well in conjunction with the TIMEOUT option.  The TIMEOUT option is by default zero (no time limit) but in my configuration I set a timeout of 40 seconds, which means that in 40 seconds of no activity, the DEFAULT option will be booted.
DHCP Server Options
However, there is still one piece of the puzzle missing.  You need a network booted machine to know where to look for the PXEboot server.  This sort of configuration will need to be passed to the machine via DHCP options.  In this instance, I will be using a router with dd-wrt installed to pass the DHCP options to the client.  Since dd-wrt is linux based, the command should be quite similar if you are using a linux DHCP server.  With dd-wrt make sure that you are using DNSMasq for DHCP, which can be found directly under the setup tab.



Next, you will need to add the option that will tell the client where to look for the server and what server to look for when network booting.  The option is configured under the DNSMasq box (not the DHCPd option, which may appear more relevant).  The format for the dhcp-boot option is: dhcp-boot=filename,servername,ipaddress


The filname option is what the name of the file is that the PXEclient should look for... in this case, that file is pxelinux.0.  The servername is not necessary... as you can see I left it out.  However, the commas are necessary.

Troubleshooting
For troubleshooting, I recommend you install Wireshark to sniff network traffic.  It is a very useful tool.  Next, a few common troubleshooting methods for narrowing down the problem.
Ensure the TFTP server is working.  If your client is unable to find the pxelinux.0 file, make sure you can tftp files from any machine (even from the machine that your tftp server is installed on).  This error could be cause by an incorrect tftp boot path, or the tftp server is not running.
Ensure that your network card/BIOS is PXEbootable.  An obvious problem, sometimes upgrading the BIOS will solve this.
 If all else fails, sniff the network traffic.  Use Wireshark to sniff the network traffic, this will help troubleshoot problems.
Hopefully soon I will cover using a preseed.cfg file to do an automated network boot and install. 

Thursday, October 1, 2009

Windows XP to Debian Server Switch

Recently, I decided to switch from Windows XP to Debian, and further more decided to go cutting (read: bleeding) edge and install Debian Squeeze (Debian 6), which is still in the "unstable" phase. At the bottom of this post, I have a Youtube link to a video detailing the installation.

The list of programs that I had on my windows "server" was quite normal, nothing extremely special:
1. Subsonic - for streaming music\video (with my internet connection the video really wasn't practical.

2. uTorrent - I'm kind of a packrat, and I have almost all of the newest versions of software in RSS feeds (Check out SARDU antivirus, UBCD, etc.. I have RSS feeds for all that software so I can download the newest version automatically). As well, I for some reason need to have the newest releases for my favorite linux distro's.. you guessed it, RSS feeds.

3. Hamachi - For VPN, because I need a better router before I will implement OpenVPN, don't have enough NVRAM in my router for it to work. Feel free to donate to help me buy a better router :D.

4. Apache - hosts my web server, which hosts my freemind maps, and other test environments.

5. Freemind - For creating the mindmaps... I had this application shared through another computer, however since I was redoing that computer I was hoping to find a way to remotely share applications.

6. Remote Desktop - As I am not linux-fluent, I would need the gui for somethings, as I would not be able to accomplish everything from the command line.

The following programs were eventually used on my Debian server:
1. Subsonic - since this is Java based it works on pretty much anything. The first install went without any errors, but did not appear to work. Purging the installation and reinstalling worked... not sure what went wrong. As well, I had to change the ownership of some of the files, to root ownership.. my default logon was throwing up permission errors. However, once that was corrected, subsonic was up and running very well. The next thing I had to do was get it to start on boot. By adding the following line to /etc/rc.local "/var/subsonic/standalone/subsonic.sh" Subsonic will boot on startup... rather easy compared to some programs rather long startup scripts.

2. Deluge - Bittorrent was eventually taken over by Deluge. This was a rather difficult one... I originally went for Transmission.. I then realized I wanted something with a Webui. Transmission was said to work with something called Clutch. However, I was unable to get that working. From there I turned to Deluge.. however, the debian repositories appear to be very out of date, they only had Deluge .5. I downloaded Deluge version 1.1.9, and after MANY struggles with dependencies for compiling and installing I finally got it up and running. The only complaint I have is that RSS feeds cannot be managed from the Webui.

3. Hamachi - Hamachi was rather easily installed, however there is one error that occurs when starting.. for some reason the tuncfg command is not run... I believe this is a permissions issue, and is something that needs to be changed with my startup script. As well, there seems to be problems connecting my windows 7 laptop to my server using hamachi; the hamachi connectivity is sporadic. I am currently looking into another solution.

4. Apache2 - Apache has been replace by Apache2. The installation was once again, very easy on debian, sudo apt-get install Apache2. There has been a change with apache2. You now edit the apache2.conf file instead of the httpd.conf file. It is my understanding that you can add lines to the (empty) httpd.conf file and they will be applied. All I did was copy my backed up web files to /var/www and replace the index.html, and I was once again up and running.

5. Freemind - Freemind was easily installed on debian, and worked exactly as it did on windows.

6. NxServer - I originally tried VNC viewer, but VNC was unable to run the server headless.. or at least I was unable to get it working. So I installed nxserver, and installed nxclient for viewing. NOTE: Once I installed xfce4 for the desktop manager, then I was able to use X11 forwarding to forward the desktop to the windows machine.. more on this in another post.

Extras:
1. Webmin - Webmin is an amazing web-based administration suite for linux. A simple install and you can connect via port 10000. Webmin has many advanced options for managing your server, from apache2 configurations, to Samba configurations, all on a nice web-based interface, as shown below.


Essentially, I was able to replace my windows server with alternative software.. now it was much more difficult to get up and running, since I was quite inexperienced with Linux, but now that it is up and running, it runs much quicker than my windows box was running.. although most of that is due to the fact that I am running the server "headless". Below is a video detailing some of the installation.



At this point, the server is up and running... I have not run into any unexpected problems (once I got everything running strongly, when first configuring I ran into a lot) but there are a few kinks to work out still, especially with X11 forwarding.