Archive for August, 2007...

Filed under Web Hosting

It’s been a little while since I posted part 3 of this tutorial so let’s get this thing going. At this point we have a Linux CentOS 5 server running. Now we need to install and configure all the major web services : Apache, PHP and MySQL.

For the most part of this article, I will be using the command line interface through SSH and not the default GUI (Gnome). You can download putty.exe, an SSH client, at http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Starting Apache Web Server

If you followed the previous parts of this tutorial, Apache 2.2 should be installed by default. You only have to make sure the service is started at boot time. To ensure that the httpd service is started automatically, type : chkconfig httpd on . This will add the httpd startup / shutdown scripts in the proper directories.

Now even though we configured the httpd service to start automatically, it is not started unless you rebooted the server. Simply type “service httpd start” to launch the Apache web server.

To make sure the web server is running, open a web browser on your host system (ie. not on your virtual machine) and try to access http://[your virtual machine’s ip]. If you don’t know your virtual server’s ip address, type “ifconfig” at the command prompt. If the web server is installed correctly and running, you should see a “Apache 2 Test Page”.

Installing MySQL Database Server

Great we now have a web server running so let’s install our database server. Again we’ll be using YUM to install MySQL so issue the following commands :

# yum update yum
# yum –y install mysql mysql-server

When the installation is completed, launch the MySQL server service by issuing : service mysqld start

We also want that service to be launched automatically so type the following command :

# service mysqld start

Now that we have our MySQL server running, let’s set the password for the root user :

# mysqladmin –u root password ‘new password
# mysqladmin –u root –p –h your_hostname password ‘new password

Installing PHP

At the command prompt, simply issue:

# yum –y install php

The PHP version available at the time of this writing is 5.1.6.

Now let’s restart the httpd service:

# service httpd restart

We’re now going to test our PHP installation. Create a new file named “index.php” into the folder /var/www/html. In that file, simply copy the following line :

<? phpinfo(); ?>


Now again, open a web browser at the address http://[your virtual machine’s ip] and you should see PHP’s information page :

PHP Info Page

Well that’s about it, you got yourself a virtual CentOS 5 web server. I will not go into details about how to configure Apache, MySQL, PHP or even hardening your Linux box but stay tuned for more tutorials on the subject.

Comments (0) Posted by Stephane on Tuesday, August 28th, 2007

Filed under Web Hosting

Normally we will set the hostname of a system during the installation process. Many people don’t care about this, and don’t change the hostname even if for example this was set to some random name by the datacenter that installed the system (most likely they will set this to “debian” on any debian installation, etc). For me, it is important to see on each one of the ssh screens I will have open at any time a different hostname that is relevant and will give me quickly the information on what system I am logged in.

On any Linux system, you can change its hostname with command hostname (duh). It’s easy as :

hostname NEWNAME

The problem is that it will be resetted at next reboot by some configuration file. To make the change permanent on a Red Hat / CentOS system, simply edit the /etc/sysconfig/network file :

/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=”plain.domainname.com”
GATEWAY=”192.168.0.1″GATEWAYDEV=”eth0″
FORWARD_IPV4=”yes”

You can also use sysctl to change the variable kernel.hostname :

sysctl kernel.hostname=NEWHOSTNAME

On a Debian based system, edit the file /etc/hostname and change the name of the system. When done, run :

/etc/init.d/hostname.sh
Comments (0) Posted by Stephane on Monday, August 27th, 2007

Filed under Web Hosting

Today I just had to work on a Linux box (CentOS 5) for which I didn’t knew the root password for MySQL so I had to reset it. If you ever face the same problem, here’s how to do it :

  1. Stop the MySQL daemon : service mysqld stop
  2. Start MySQL in safe mode with the –skip-grant-tables and -u root options in background : mysqld_safe –skip-grant-tables -u root &
  3. Start the command line client as root : mysql -u root
  4. Issue the MySQL command to reset the root password : UPDATE mysql.user SET Password=PASSWORD(‘newpwd’) WHERE User=’root’;
  5. Issue the flush privileges command : FLUSH PRIVILEGES;
  6. Quit the command line tool : quit
  7. Stop the MySQL process : kill `cat /var/run/mysqld/mysqld.pid`
  8. Restart the MySQL daemon : service mysqld start
  9. Log in as root to make sure the new password is active : mysql -u root -p

Here’s a screenshot so you can see how it actually goes :

reset-mysql-root-password.jpg

Comments (1) Posted by Stephane on Monday, August 27th, 2007