How to Deploy a Cloud Webserver in 5 minutes – LAMP
| By Matt Dunlap on January 4th, 2010 | 6 comments |
Cloud based webhosting is all the rage. The ability to deploy servers, upgrade, downgrade and delete on the fly is a huge advantage over having to buy or rent a full server with co-location rackspace. With cloud prices starting at .015 cents/hour… It’s a no brainer if you need a full webserver.
Start a Rackspace Cloud Server now
When you control the full server, you have many more options on how the websites are ran. Of course, maintaining a full server with little experience can be risky for production servers, but if you want to learn how to set one up, here are the steps. I’m going to install LAMP (Linux, Apache, Mysql, and PHP) That is all you need to build powerful database driven websites. I’ll then update the Iptables to allow for secure access to the server and provide a fairly secure server.
You will see that most of the heavy lifting will be done with yum, Fedora’s package manager. It is used to install and upgrade software.
Install Mysql (Database Server)
yum install mysql mysql-server
/etc/init.d/mysqld start
mysqladmin -u root password YOUR_UNIQUE_PASSWORD
Install Apache2 (Webserver)
yum install httpd
/etc/init.d/httpd start
If httpd starts you will be able to enter the ip number of the server into the browser address bar and visit the website. One thing to note is that fresh Fedora installs do not allow access to port 80. So you will not be able to see the website until you edit your Iptables. for now let’s just flush them so we can look at the new webpage.
iptables -F
Flush and try again, if you see the Fedora test page, congrats, your up and running. You can only server HTML files. We now need to install PHP for server side scripting.
Install PHP5
yum install php
/etc/init.d/httpd restart
To check PHP, go to the default www folder located at /var/www/html/ and make a new file called info.php. In that file add this code
<?= phpinfo(); ?>
Then hit that page in your browser and you should get all the information about your PHP installation.
Everything looks good, but PHP is not talking to Mysql yet, we need to connect them.
yum install php-mysql
/etc/init.d/httpd restart
Optional, but recommended
In our current state, if the server gets restarted, our LAMP server will have to be started manually and the iptables will have to be flushed again. So, enter the following commands to make sure httpd and mysql start automatically on boot up.
chkconfig --levels 235 mysqld on
chkconfig --levels 235 httpd on
You will probably need a few more php modules installed
yum install php-gd php-xml php-xmlrpc php-eaccelerator php-mbstring php-mcrypt php-mhash php-soap php-tidy
Don’t forget to restart httpd after you install the modules
There are many more, to do a search for all modules
yum search php
Then for the iptables, instead of flushing them, and opening up the server, we are going to just open port 80 so you can display your website. Port 22 is the only port open by default. Make sure you don’t remove that or else you will not be able to access the server.
First reload the old iptables
iptables-restore /etc/sysconfig/iptables.old
Then append the new iptables entry:
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
services iptables save
Next check the iptables again to make sure you are allowing SSH and HTTP
iptables -L
If they are there, restart iptables
/etc/init.d/iptables restart
Check your website again to see if you can access it. If you server gets restarted you should reboot with these two ports open.
Here is a list of common entries for Fedora
Another helpful page for iptables at ubuntu.com
Now that the server is up and running we need to start adding virtual directories and domain names. The next couple of posts will cover setting up virtual directories and parking domains, how to set up a templated website directory so you can deploy many websites fast, and I’ll cover more on how to set up WPMU with top level domain names. I have a post about TLD’s, wpmu and godaddy… but with your own server it is much easier and you can automate it!




Post a Comment