I have been playing with Rackspace “cloud” servers for a few weeks now. They’re easy to fire up and shut down, and you only pay for the time the servers are online, so they are great for spinning up a development server for a few hours.
I’ve put together the following as my own selfish reference to setting up a working CentOS LAMP server.
This post assumes you have knowledge of using SSH and have some idea of what you are trying to achieve which in this case is a working LAMP web server.
But it also involves managing your own stuff. Updates, checking logs, making sure your websites are up and running, fixing issues etc. will now be your responsibility.
If the sound of all that makes you dizzy, then you might want to consider a fully managed web hosting service from a reputable hosting company instead who will do all that boring stuff for you.
Still with me?
Good. Lets fire up a server. Remember to give your server a cool name, this will help gain you the respect of more seasoned server admins. If you own a retro Transformers T-shirt, put it on now.
Create a server
When you create a server on rackspace, you will be issued with the important basics. The unique IP address, and your root username and password. So fire up a terminal and get your eyes dirty. For the purpose of this post, I will be using the server “clapton” (cool, huh?) and the IP address is 220.127.116.11, I’m logged in with a clean install of CentOS 5.5.
Yum is your friend
You know that cool retro Tansformers T-shirt you’re wearing? Well Yum is even cooler.
First up, lets update any existing packages that have been included in your CentOS install by using the “update” option
The installed packages are now up to date, now lets move on to the stuff we want. I want to install the following;
- Open SSL
I’m not going to bother with FTP (real men use Git) and I want to keep things lightweight and locked down as much as possible. Having FTP running just means faffing with IP lists in an attempt to stop 7 million Chinese teenagers pwning your FTP login.
Open SSL comes included with CentOS, we just need the apache mod_ssl. I will write another post regarding setting up SSL certs, as this was my one stumbling block when I first started. I’d previously been spoiled by admin panels like Plesk when it came to things like that.
There isn’t really much house work to take care of, other than checking the servers HOSTS file, located at /etc/hosts;
127.0.0.1 localhost localhost.localdomain
18.104.22.168 clapton 22.214.171.124.static.cloud-ips.co.uk
In the Rackspace control panel, if you view the DNS for the server you will see a xxxx.cloud.co.uk record, add this (along with the server name if not already there) to the IP in your HOSTS file.
I also add a localhost.localdomain entry, this will make life easy for things like sendmail.
The rest of the setup may require editing files, be nice to your eyes and use VIM.
yum install vim-enhanced
Lets get Apache up and running. We want SSL support too so we’ll also install the apache mod now (OpenSSL should be installed by default as mentioned above, we just need the mod itself)
yum install httpd mod_ssl
Fire up VIM and edit the apache conf file, we need to tell apache to “listen” on port 80, its around line 135 of httpd.conf;
httpd conf listen port 80
Now Apache is listening to port 80, we now need to open this port as CentOS by default will have every port locked down for obvious reasons.
To open port 80 (http) and 443 (https) we add a rule for each to the iptables config;
iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
iptables -I INPUT 1 -p tcp --dport 443 -j ACCEPT
and then commit these new rules;
That’s it, fire up apache;
service httpd start
and go to your IP address in a browser;
apache default page
Use Yum to install PHP, the MySQL extension, and MySQL itself in one fell swoop;
yum install php php-mysql mysql-server
As of writing this, the latest PHP version that Yum will use is 5.1.x, which lets be fair, is pretty outdated.
5.2.3+ is fine for me, so I’ll go with that. If you want to go big and have 5.3+ (but have never installed manually before) then I would suggest get going with 5.2.x to start with, then upgrade to 5.3 later on once you have a basic web server up and running.
To update to 5.2+ we need to add a .repo file which instructs Yum to do some kung foo for us when finding which packages we want.
We then just update PHP using Yum.
So first, add the .repo file as follows;
Then open the empty file;
Then add the following config to the repo file you just created;
# !!!! CAUTION !!!!
# This repository is a proving grounds for packages on their way to CentOSPlus and CentOS Extras.
# They may or may not replace core CentOS packages, and are not guaranteed to function properly.
# These packages build and install, but are waiting for feedback from testers as to
# functionality and stability. Packages in this repository will come and go during the
# development period, so it should not be left enabled or used on production systems without due
Now update PHP as normal with Yum;
yum update php
service httpd restart
MySQL users !IMPORTANT
MySQL is now installed, but comes with a default user….with NO PASSWORD. So we need to start MySQL, drop the users with no passwords, and create a user with a password;
service mysqld start
Log in as the default password-less root user;
mysql -u root
Set a password for your root user;
SET PASSWORD FOR root@localhost = PASSWORD('newpassword');
SET PASSWORD FOR email@example.com = PASSWORD('newpassword');
Drop the ‘any’ user too
DROP USER ''@localhost;
All done. Exit MySQL;
yum install sendmail sendmail-cf
service sendmail start
At this stage we have 3 main services installed; Apache, MySQL and Sendmail.
But these are currently manually started, which means if you had to reboot your server, you would also have to also manually start each service again, which is pants.
To set all 3 to start by default use the chkconfig command;
chkconfig httpd on
chkconfig mysqld on
chkconfig sendmail on
You can also use the –list parameter to see the changes and view any other default services and their run levels.
Git is cooler than both Yum and your Transformers T-shirt combined.
To install Git we can employ the EPEL (Extra Packages for Linux) RPM;
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/
We can now Yum install;
yum install git
git version 1.5.5.x
That’s it. You now have a LAMP stack on Rackspace. A great tool in the Rackspace Panel is “My Server Images”. Now would be a good time to create an image of what you have done so far, then you can roll this out on other servers really quickly in future.
But don’t be a dingbat and loose all your shit, image or no image. Remote file storage is seriously cheap, see this post on Remote Backups to Amazon S3 and save yourself a huge headache one day
Tags: apache, centOS, git, linux, mysql, rackspace, transformers