You get a bonus - 1 coin for daily activity. Now you have 1 coin

Installing LAMP (Apache + MySQL + PHP 5.3) on CentOS 5.x (RedHat 5)

Practice



Task: install a LAMP server on CentOS 5, with PHP being the latest 5.3 version and staying updated.

In general, this task can be solved in two ways:
a) Long and more complicated: build it by hand from source (since the PHP that comes from the repos is ancient)
b) Fast and simpler: use a third-party repository whose maintainers periodically update to the latest versions for RHEL systems as those versions are released by the developers.

In this note we'll go the second route.


1) To use this repository you'll need EPEL. Let's check whether it's already present:

# yum repolist | grep epel

If not — see the note on how to install it:



2) Register the repository for our version of CentOS (5.x):

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm


3) Install MySQL:

# yum --enablerepo=remi install mysql-server

Now start the server:

# /etc/init.d/mysqld start

and run the security script

# mysql_secure_installation

In which you set the root password (empty by default) and answer "yes" to the remaining questions.


4) Install Apache (in CentOS it's called HTTPD):

# yum --enablerepo=remi install httpd


5) Install PHP:

# yum --enablerepo=remi install php php-common


6) Install PHP extensions (you can't do without them — bare PHP is almost never used as-is).

To list the extensions available for installation from this repo:

# yum --enablerepo=remi search php-

And now let's install the ones we need. For example, here's the installation of packages for a typical web server (if something is missing, your web developers will let you know):

# yum --enablerepo=remi install php-pear php-pdo php-gd php-mysql php-pecl-memcache php-mbstring php-mcrypt php-xml php-gettext php-imap


7) Add Apache and MySQL to autostart (CentOS 5.6 does this itself).

If you're installing on an OS that doesn't add Apache to autostart on its own:

# chkconfig --levels 235 httpd on
# chkconfig --levels 235 mysqld on


8) Configure Apache

Before starting Apache we need to do at least one useful thing — so it doesn't complain every time it starts — set the server name in the configuration file.

Apache's configuration in CentOS is located at:

/etc/httpd/conf

The file we're interested in is called httpd.conf. Let's open it and add the following line:

ServerName "MyWebServer"

where instead of MyWebServer you put the name of this server that you want to appear in Apache's messages.

Now find the line "NameVirtualHost *:80" and uncomment it — this enables support for virtual hosts, i.e. the normal mode of Apache operation where a single web server on a single IP hosts several sites at once, distinguished by DNS name (FQDN).

Right below this option there's an example of such a virtual host — it looks roughly like this:

<VirtualHost *:80>
ServerName mysite.ru
ServerAlias www.mysite.ru
DirectoryIndex index.php
DocumentRoot /www/mysite.ru
</VirtualHost>


9) Start Apache

# /etc/init.d/httpd start



10) Installing phpMyAdmin:



And that's basically it.

Applies to: CentOS 5.6 (RedHat 5)

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)