Centos Virtual LAMP server -- Part II Wed, Aug 5. 2009
Customizing your LAMP server
Unix people are probably familiar with the father of the DNS system -- the /etc/hosts file. The hosts file has a simple format:
In the days prior to DNS, people would update a master hosts file and copy it around to all the servers in the enterprise. Surprisingly Windows versions also support this file, as a way of overriding DNS, so we can use this to our advantage, by adding an entry for our development server. In this example, I'm going to use dev.gizmola.com, which is not a real server.
One important reason to do this is that Apache and other web servers, use a feature of HTTP 1.1 that specifies a header field named "Host:". This mechanism facilitates the service of multiple domains from a single apache server, through the configuration of apache virtual host (or vhost) entires. The server uses the Host name in the HTTP header to determine how to route requests, so without host name resolution. you have to use non-standard ports and other mechanisms that are more trouble than they're worth. a
Updating your MySQL and PHP using an alternative Yum Repo
RHEL is very conservative in the way it handles package management, and often core packages lag far behind the latest releases. Fortunately, there are alternative repositories which provide updated versions of the LAMP stack, as well as support for commonly used php extensions that don't exist in the official RHEL repositories.
I recommend the use of Remi's Repository. Remi in turn depends on Fedora's "Extra Packages for Enterprise Linux (EPEL)" repository. Full instructions for configuration is provided at Remi's site, however, I've provided the steps to use for Centos/RHEL version 5, which is what I'm using in this series.
First we'll install support for EPEL using rpm.
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
The best way to handle this is to place the remi repo repository in the /etc/yum.repos.d directory. This will then allow us to refer to it when we want to install the updated packages we want.
Now you should be able to use the remi repo via yum, by specifying the "--enablerepo=" switch.
Remember to execute this steps as root.
First install the mysql-server.
yum --enablerepo=remi install mysql-server
Start the server to initialize it, and give the root account a password before you forget about it.
service mysqld start
mysqladmin -u root -h localhost password 'your password'
yum --enablerepo=remi install httpd
Now install php and related packages. This may vary depending on what you're doing. I've listed packages I find to be commonly useful.
yum --enablerepo=remi install php php-mysql php-gd php-pear php-mcrypt php-mbstring php-pecl-xdebug
Now you should be able to verify your version of php, using "php -v".
PHP 5.3.1 (cli) (built: Nov 20 2009 18:18:28)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans
Adding a virtual host.
Open up your apache configuration file for editing and move to the bottom of the file and uncomment the NameVirtualHost line:
# Use name-based virtual hosting.
Then add a vhost section for your virtual server. You can add as many of these as you like for development purposes. Read the Apache manual if you have any questions about any of these directives. We'll call this server dev1.gizmola.com.
CustomLog logs/dev1-access_log combined
You'll need to create the directory where your site will live and set permissions. As this is a development server you don't need to be overly concerned, but it's a good practice to get into to setup a user and group to own the webspace for each virtual host. You can then use your ftp client or scp as the user, in the same way you would for a production or shared hosting server to update the files as you develop your website.
useradd -g dev1user dev1user
chown -R dev1user:dev1user /var/dev1
Anytime you make a change to the apache configuration files, or the php.ini file, you need to restart apache.
Make sure that you've installed a hosts file entry for your new vhost as described previously.
# Copyright (c) 1993-2006 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
# 22.214.171.124 rhino.acme.com # source server
# 126.96.36.199 x.acme.com # x client host
If all works as planned, the vhost should now answer. Put a phpinfo file (see Part 1 of this series) and point the browser to it to verify everything is working as planned.
- Putting Apache on a diet - how to get a lean configuration, Part 1
- PHP Mysql support: mysql or mysqlnd?
- Fixing PHP short open tags
- Calculate a person's age in a MySQL query -- continued
- Calculate a person's age in a MySQL query
- SQL UPDATE for strings in MongoDB
- Profile of the GB4k.com launch -- Joomla reborn
- Get files from subversion without creating a sandbox using svn export
This tutorial will introduce you to some of the key concepts behind the RightScale Cloud Management Platform and also show you how easy it is to set up, configure, and launch a fully functioning LAMP (Linux Apache MySQL and PHP/Perl/Python or other Programming language) server running on Rackspace in 10 minutes using a RightScale ServerTemplate. This tutorial is useful for any developer who wants to host a LAMP server on the Rackspace Cloud.
Note: If you want to launch a LAMP Server on EC2, see All-In-One LAMP Server.