Beginning Adventures in CentOS: Installing Apache and MySQL

January 31, 2012

Here it is, the first of the promised "Beginning Adventures with CentOS" blog posts... I started a new project yesterday. This particular client is running CentOS 5.5 32-bit, Tomcat 5.7, Apache, and a combination of MySQL and SQL Server. One of my first tasks is to build a VMWare image that mirrors that (or gets as close as possible without losing a lot of time) so we have a playground for some development work. I've installed Ubuntu on a desktop once or twice, but that was at least a year ago, and the Ubuntu installer did all the work for me really (which I greatly appreciated). So let's see how different installing CentOS in VMWare is from that experience... I downloaded the DVD ISOs (2 discs total) for CentOS Making a new guest in VMWare is easy enough. And with that "express install" option, VMWare automagically installed CentOS for me! Wow, that was even easier than the Unbuntu install I did last year! :) Firefox comes pre-installed too, so it's easy to tell if I have a working internet connection inside this new VM -- Firefox pop up and sees Google.com, so that's taken care of too. So now we need to move onto the "real" stuff -- installing Apache, MySQL, and Tomcat... Let's open Firefox again and go to "http://localhost"....instead of the default "Apache is running" web page, I get "Problem loading page". So either Apache isn't installed, or it's just not running. Fortunately CentOS has some similarities to Windows, and there is a "Services" screen in CentOS, just like in Windows. The Apache service is actually named "httpd" (which kind of baffles me, but that's a separate discussion), and we do indeed have a service called "httpd" there, so we just need to check it, and click "start". Now let's go back to Firefox and do "http://localhost" again. Success! We now have the "Apache is running" web page. Next up, MySQL and Tomcat. Since I'm more familiar with MySQL, let's start with that one... After checking the Services control panel, it doesn't seem that MySQL came pre-installed with CentOS (I was only half-suspecting it might be). I could use the "Add / Remove Programs" menu, but since the whole point of this is to learn something, let's try to install it from the Linux command line instead. On my Ubuntu machine, you install things with the "apt-get" command, so let's try that on CentOS and see what happens: >apt-get mysql ...and "Command not found". Okay so it's not "apt-get". After a bit of thinking/Googling..."yum" is the command we're looking for, so let's try this again: >yum install mysql And that comes back with "You need to be root to perform this command". Delving back into my "just enough to get in trouble" pile of knowledge, I remember that sometimes you can use this "sudo" command to bypass not having enough permission to do certain tasks. So let's try... >sudo yum install mysql "nolan is not in the sudoers file. This incident will be reported." Hmm....well, I just built this box few hours ago, and "nolan" was the account I used to do everything else. Maybe this is where I should have typed "sudo su" instead of "sudo"? Nope, that also doesn't work. Though this one does: > su -
> yum install mysql Success! Admittedly this is one of those areas where I just sort of "brute force" my way through variations on the "sudo" and "su" command until I find one that works. Like I said, I'm not a Linux guy, and I've never fully understood the detailed specifics of what "sudo" does. (That alone could probably be its own blog post...I could certainly use something to reference in the future when I forget...again...) MySQL should now be installed, let's double-check...a quick look at the Services control panel, I do indeed see a process called "mysqld", which is MySQL (though again, why it's not called "mysql" is somewhat puzzling...there's probably a really long geeky answer as to why, if I wanted to look it up.) Let's test that MySQL is indeed working: >mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Ah...forgot to start the MySQL service. I could go back to the Services GUI and do that, but just for practice, let's try it from a command line: >service mysqld start
Starting MySQL: [ OK ] >mysql
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.0.77 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> Success again! We're on a roll! We still have to install Tomcat, not to mention configuring everything, setting up user accounts, etc, but this is a pretty good stopping point. We'll work on that in a different blog entry.... (If there are any experienced Linux guys reading this far, feel free to chime in with feedback on what I did wrong. I'd appreciate any tips you feel like sharing.) -nolan