WebTech#2: Complete Server Solution


Hello everyone, this post will be the second in the Abducted by Servers series. In the last post, we went over the main basics of logging-in and doing some basic commands on your server. (http://abduzeedo.com/webtech-1-introduction-servers). In this article we will look at installing and configuring a complete server solution for your VPS/server, including a web-server (Apache), and a popular Database server (Mysql) This article will cover a broad base of topics in a general sense in order to get things up and running.

This article will be based on CentOS, as we got a huge amount of requests to vary the OS, so we'll give it a try on CentOS, however, you may follow this same tutorial for Ubuntu/Debian you may need to do a few adjustments when using apt-get vs yum. Before we begin lets get a couple of clarifications out of the way. At the time of writing the latest release of CentOS was version 5.2, but this article should apply to any earlier versions without much modification. We will be using the yum package manager rather than installing from source for its ease of use and ability to handle dependencies. Finally, we assume you will be installing from a root-level account. We'll be installing the latest versions of the following software: HTTP: Apache with PHP Database: MySQL


Make sure you login! Read WebTech#1 for details

Before we proceed with installing anything let's update our VPS to the latest version: # yum update

Installing Apache 2 and PHP 5

To install Apache and PHP, run the following command

# yum install httpd httpd-devel php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

Now configure your system to start Apache at boot time:

# chkconfig --levels 235 httpd on

We have to start Apache by hand after installation. To do this, type

# /etc/init.d/httpd start

You will see a warning about ServerName, so let’s go ahead and fix that now. Open the main apache config file:

# nano /etc/httpd/conf/httpd.conf

Hit CTRL+W to bring up the search prompt and type in “ServerName”. Repeat until you find the line of code that says

# ServerName www.example.com:80

Change this line to your hostname or FQDN and take out the pound sign (#) in front of ServerName. Now reload Apache:

# /etc/init.d/httpd reload

Now open a web browser and type in your VPS IP address. If everything went well you should see the default Apache landing page.

Installing MySQL 5

You can install MySQL server, client, and module with the following command:

# yum install mysql mysql-devel mysql-server

MySQL should now be installed. The configuration file is located at: /etc/mysql/my.cnf

Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:

# chkconfig --levels 235 mysqld on # /etc/init.d/mysqld start

Now we delegate control of MySQL to a user. By default MySQL runs on the root account with no password. Lets password protect the root account:

# mysql -u root mysql> USE mysql; mysql> UPDATE user SET Password=PASSWORD(’new-password’) WHERE user=’root’; mysql> FLUSH PRIVILEGES; mysql> quit;

Although we have password protected the root account, you must never use it in your production environment. The best practice is to create a user to connect to MySQL. Then restart your MySQL server:

# /etc/init.d/mysqld restart

You should now have a complete installation of Apache and MySQL and should be ready to serve content on the web.

Written by

I'm Carlos Taborda, I'm a 24 year old Engineer/Developer/Designer from Barranquilla, Colombia @ Miami,FL. I'm the founder of Webbynode, and have a great passion for the Design & (rails & php) Developer Community.