INTRODUCTION
This tutorial shows a quick way of installing a LAMP server (
Linux +
Apache +
MySQL +
PHP/Perl together commonly known as
LAMP Server) with some additionally repositories (for updated PHP, MySQL packages and phpMyAdmin) on CentOS/RHEL server systems.
Install the extra repositories
The first step requires downloading some RPM files that contain the additional YUM repository definitions.
Centos 5.x
wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
sudo rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
Centos 6.x
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
Update CentOS
yum update
YUM PRIORITIES
The
Yum Priorities plugin can be used to enforce ordered protection of repositories, by associating priorities to repositories. Visit the
Yum Priorities CentOS Wiki for more information.
Install Yum Priorities
yum install yum-priorities
Configure Yum Priorities
1. Open the Yum Priorities configuration file with your favourite text editor
vi /etc/yum/pluginconf.d/priorities.conf
- Ensure the following lines exist
[main]
enabled=1
- Save and close the file
2. Open the CentOS base repository configuration file
vi /etc/yum.repos.d/CentOS-Base.repo
- Add the following text to the end of the Base, Updates, Addons, and Extras repository entries (A repository entry is specified with the repository name placed between [example], i.e. the base repository entry is specified with [base])
priority=1 -
Enable (change the enable value 0 to 1) and add the following text to the end of the CentOSPlus repository entry
priority=2
EPEL RPOSITORY
Extra Packages for Enterprise Linux (EPEL) is a volunteer-based community effort from the Fedora project to create a repository of high-quality add-on packages that complement the Fedora-based Red Hat Enterprise Linux (
RHEL) and its compatible spinoffs such as CentOS or Scientific Linux. Visit the
Fedora EPEL Wiki for more information.
Install EPEL Repository
- Download the latest EPEL repository
wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
- Run the rpm install command
rpm -Uvh epel-release-5*.rpm
Open the EPEL repository file
/etc/yum.repos.d/epel.repo
- Set priority for the EPEL repository
Add
priority=3 to the end of the [epel] section
REMI REPOSITORY
The Remi repository is a repository containing updated PHP and MySQL packages and is maintained by Remi. See the
Remi Documentation for more information.
Install Remi Repository
1. Download the latest Remi repository
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
2. Run the rpm install command
rpm -Uvh remi-release-5*.rpm
Configure Remi Repository
1. Open the Remi repository file
vi /etc/yum.repos.d/remi.repo
2. Enable the Remi Repository
Change
enabled=0 to
enabled=1
3. Set priority for the Remi Repository
Add
priority=3 to the end of the [remi] section
Exclude PHP and MySQL packages from the CentOS base repositories
1. Open the CentOS base repository configuration file
vi /etc/yum.repos.d/CentOS-Base.repo
2. Append the following text to all repositories
exclude=*php* *mysql* *phpmyadmin*
APACHE SERVER
Apache HTTP Server is an open-source HTTP server for modern operating systems including UNIX and Windows NT. For more information on Apache HTTP Server, you can visit their website at
httpd.apache.org.
Install Apache
yum install httpd
NOTE: The Apache server is installed with our VPS packages with CentOS by default so you may skip this step.
Set the apache service to start on boot
chkconfig httpd on
or type
ntsysv for GUI tool
PHP
PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. For more information on PHP, visit their website at
http://www.php.net/.
Install PHP
yum install php
Restart Apache to load php
/etc/init.d/httpd restart
Test If PHP Is Working Or Not:
1. Create a file named info.php
vi /var/www/html/info.php
with the following text:
<?php
phpinfo();
?>
Then point your browser to
http://ipaddress/info.php.
NOTE: It is NOT recommended to expose the info PHP file to public view.
That's it! You should see a PHP configuration file displaying all kind of paths and installed modules.
MYSQL
MySQL is a Relational Database Management System (RDBMS) that runs as a server providing multi-user access to a number of databases. For more information on MySQL, you can visit their website at
www.mysql.com.
Install MySQL Database Server
yum install mysql-server mysql php-mysql
1. Set the MySQL service to start on boot
chkconfig mysqld on or type ntsysv for GUI tool
2. Start the MySQL service
/etc/init.d/mysqld start
3. Log into MySQL
mysql -u root
4. Set the root user password for all local domains
(otherwise anybody can access your MySQL database!)
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new-password');
SET PASSWORD FOR 'root'@'localhost.localdomain' = PASSWORD('new-password');
SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('new-password');
5. Drop the Any user
DROP USER ''@'localhost';
DROP USER ''@'localhost.localdomain';
6. Exit MySQL
exit
Alternatively you can run a script to improve the security of your MySQL installation. This is recommended for all MySQL servers in production use!
mysql_secure_installation
PHPMYADMIN
phpMyAdmin is a tool written in PHP intended to handle the administration of MySQL over the Web. Visit the
phpMyAdmin website for more information.
Install phpMyAdmin
yum install phpmyadmin
NOTE: You might encounter the following errors while configuring phpMyAdmin
Forbidden
You don't have permission to access /phpmyadmin/ on this server.
To fix:
Edit the
/etc/httpd/conf.d/phpMyAdmin.conf file and uncomment the line
deny from all
vi /etc/httpd/conf.d/phpMyAdmin.conf
<Directory "/usr/share/phpmyadmin">
Order Deny,Allow
# Deny from all
Allow from 127.0.0.1
</Directory>
NOTE: The location of the phpMyAdmin configuration file is
/etc/phpMyAdmin/config.inc.php
Restart the Apache Server
/etc/init.d/httpd restart
Test:
1. Visit
http://ipaddress/phpmyadmin in your web browser. You should be prompted for authentication
2. Enter the system root username and password and click OK
3. You should now be presented with the phpMyAdmin home page