Installing Apache2 With PHP5 And MySQL Support On CentOS 5.6 (LAMP)

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Tue, 2011-06-14 18:53. :: CentOS | Web Server | Apache | MySQL | PHP

Installing Apache2 With PHP5 And MySQL Support On CentOS 5.6 (LAMP)

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Follow me on Twitter
Last edited 04/11/2011

LAMP is short for Linux, Apache, MySQL, PHP. This tutorial shows how you can install an Apache2 webserver on a CentOS 5.6 server with PHP5 support (mod_php) and MySQL support.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.

 

2 Installing MySQL 5.0

To install MySQL, we do this:

yum install mysql mysql-server

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

Set passwords for the MySQL root account:

mysql_secure_installation

[root@server1 ~]# mysql_secure_installation




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n]
 <-- ENTER
New password: <-- yourrootsqlpassword
Re-enter new password: <-- yourrootsqlpassword
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
 <-- ENTER
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
 <-- ENTER
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
 <-- ENTER
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 <-- ENTER
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


[root@server1 ~]#

 

3 Installing Apache2

Apache2 is available as a CentOS package, therefore we can install it like this:

yum install httpd

Now configure your system to start Apache at boot time...

chkconfig --levels 235 httpd on

... and start Apache:

/etc/init.d/httpd start

Now direct your browser to http://192.168.0.100, and you should see the Apache2 placeholder page:

Apache's default document root is /var/www/html on CentOS, and the configuration file is /etc/httpd/conf/httpd.conf. Additional configurations are stored in the /etc/httpd/conf.d/ directory.

 

4 Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:

yum install php

We must restart Apache afterwards:

/etc/init.d/httpd restart


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by robocatsrule (not registered) on Mon, 2011-07-25 20:02.

After the apache2 steps, open the "www" ports in the firewall using:

 system-config-securitylevel

Submitted by robocatsrule (not registered) on Mon, 2011-07-25 19:28.

The "mysql_secure_installation" step failed with the error:

-------------------------------------------------------------------

Remove anonymous users? [Y/n] Y

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

... Failed!

-------------------------------------------------------------------

To solve this problem change line (~50) in the script: /usr/bin/mysql_secure_installation

from

echo "password=$rootpass"

to

echo "password='$rootpass'"

After this change, no problems!

The original reference for this bug fix is at: http://bugs.mysql.com/bug.php?id=48031

I hope this saves others some time.

Submitted by slapper (not registered) on Tue, 2011-06-14 19:35.

From Centos 5.6 you have the option to install php 5.3 (  specifically 5.3.3 ). You can install it by typing :

yum install php53

More packages are availabe

================= Matched: php53 ====================

php53.i386 : PHP scripting language for creating dynamic web sites

php53-bcmath.i386 : A module for PHP applications for using the bcmath library

php53-cli.i386 : Command-line interface for PHP

php53-common.i386 : Common files for PHP

php53-dba.i386 : A database abstraction layer module for PHP applications

php53-devel.i386 : Files needed for building PHP extensions

php53-gd.i386 : A module for PHP applications for using the gd graphics library

php53-imap.i386 : A module for PHP applications that use IMAP

php53-intl.i386 : Internationalization extension for PHP applications

php53-ldap.i386 : A module for PHP applications that use LDAP

php53-mbstring.i386 : A module for PHP applications which need multi-byte string handling

php53-mysql.i386 : A module for PHP applications that use MySQL databases

php53-odbc.i386 : A module for PHP applications that use ODBC databases

php53-pdo.i386 : A database access abstraction module for PHP applications

php53-pgsql.i386 : A PostgreSQL database module for PHP

php53-process.i386 : Modules for PHP script using system process interfaces

php53-pspell.i386 : A module for PHP applications for using pspell interfaces

php53-snmp.i386 : A module for PHP applications that query SNMP-managed devices

php53-soap.i386 : A module for PHP applications that use the SOAP protocol

php53-xml.i386 : A module for PHP applications which use XML

php53-xmlrpc.i386 : A module for PHP applications which use the XML-RPC protocol