Thứ Hai, 23 tháng 9, 2013

// // Leave a Comment

Install LAMP server in CentOS 6.4 / RHEL 6.4

LAMP is a short form of Linux, Apache, MySQL and PHP. In this tutorial i will show you how to install LAMP server in CentOS 6.4. My testbox hostname and IP Address are “server.unixmen.com” and “192.168.1.200/24″ respectively.

Install Apache
[root@server ~]# yum install httpd -y
Start Apache and make it to start automatically on every reboot.
[root@server ~]# /etc/init.d/httpd start
[root@server ~]# chkconfig httpd on
Test Apache:
Open your Browser and Enter “http://192.168.1.200″. Now you will see the Apache home page.
Apache HTTP Server Test Page powered by CentOS - Mozilla Firefox_014

Install MySQL
[root@server ~]# yum install mysql mysql-server -y
Start the MySQL service and make to start automatically on every reboot.
[root@server ~]# /etc/init.d/mysqld start
[root@server ~]# chkconfig mysqld on
Setup MySQL root password
[root@server ~]# /usr/bin/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):     ## Press Enter ## 
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]     ## Press Enter ##
New password:                ## Enter new password ##
Re-enter new password:       ## Re-enter new password ##
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]     ## Press 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]     ## Press 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]     ## Press 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]     ## Press 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!
Install PHP
[root@server ~]# yum install php -y
Restart Apache server
[root@server ~]# /etc/init.d/httpd restart
Test PHP:
Create a sample “testphp.php” file in Apache document root folder and append the lines as shown below.
[root@server ~]# vi /var/www/html/testphp.php
<?php
phpinfo();
?>
Now open the testphp.php file in browser using http://192.168.1.200/testphp.php. It will display the details about php package.
phpinfo() - Mozilla Firefox_015
If you wanna to get MySQL support in your PHP, you should install “php-mysql” package. If you want to install all php modules just you use the command “yum install php*”
[root@server ~]# yum install php-mysql -y
Now open the phptest.php file in your browser using http://192.168.1.200. Scroll down and you will see the mysql module will be presented there.
phpinfo() - Mozilla Firefox_016

Install phpMyAdmin
phpMyAdmin is a free open source web interface tool, used to manage your MySQL databases. By default phpMyAdmin is not found in CentOS official repositories. So let us install it using EPEL repository.
Download and install EPEL Repository first.
[root@server ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[root@server ~]# rpm -ivh epel-release-6-8.noarch.rpm
Now install phpMyAdmin
 [root@server ~]# yum install phpmyadmin -y
Configure phpMyAdmin
Open the phpmyadmin.conf file and make the changes as shown below.
[root@server ~]# vi /etc/httpd/conf.d/phpMyAdmin.conf

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

## Comment the following Section ##
#<Directory /usr/share/phpMyAdmin/>
#   <IfModule mod_authz_core.c>
#     # Apache 2.4
#     <RequireAny>
#       Require ip 127.0.0.1
#       Require ip ::1
#     </RequireAny>
#   </IfModule>
#   <IfModule !mod_authz_core.c>
#     # Apache 2.2
#     Order Deny,Allow
#     Deny from All
#     Allow from 127.0.0.1
#     Allow from ::1
#   </IfModule>
#</Directory>
Open the “config.inc.php” file and change from “cookie” to “http” to change the authentication in phpMyAdmin.
[root@server ~]# cp /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php 
[root@server ~]# vi /usr/share/phpMyAdmin/config.inc.php 
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';
Restart the Apache service.
[root@server ~]# /etc/init.d/httpd restart
Now you can access the phpmyadmin console using http://ipaddress or domainname/phpmyadmin/.
Enter your MySQL username and password which you have given in previous steps. In my case its “root” and “centos”.
New Tab - Mozilla Firefox_018
Now you will get the phpmyadmin page as shown below.
192.168.1.200 - localhost | phpMyAdmin 3.5.7 - Mozilla Firefox_019
Thats it. Now the LAMP server is up and running.

Sau này, nếu muốn đăng nhập vào mysql thì dùng lệnh: 
?
1
$ mysql --user=root -p

0 nhận xét:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.