在CentOS/RHEL/Scientific Linux 6下安裝 LAMP

LAMP 是服務器系統中開源軟件的一個完美組合。它是 Linux 、Apache HTTP 服務器、MySQL 數據庫、PHP(或者 Perl、Python)的第一個字母的縮寫代碼。對於不少系統管理員來講安裝 LAMP 除了是必備的技能外,都已經具備得心應手的操做他們的能力了。不過新手們一般但願有沒完沒了的這方面的教程來告訴本身怎麼作,下面我就和你們說說個人方法步驟。 php

LAMP 是服務器系統中開源軟件的一個完美組合。它是 Linux 、Apache HTTP 服務器、MySQL 數據庫、PHP(或者Perl、Python)的第一個字母的縮寫代碼。對於不少系統管理員來講安裝 LAMP 除了是必備的技能外,都已經具備得心應手的操做他們的能力了。不過新手們一般但願有沒完沒了的這方面的教程來告訴本身怎麼作,下面我就和你們說說個人方法步驟。 html

如今,不少時候咱們須要用 MariaDB 來代替 MySQL 了。在這裏我會告訴你們 MariaDB 的安裝過程。 mysql

個人測試主機名爲:server.linux.cn,測試 IP 地址爲:192.168.1.200/24 linux

安裝 Apache

Apache 是一個開源的跨平臺的 Web 服務器。它提供了一個全方位的 Web 服務器功能,包括CGI,SSL 和virtual domains (虛擬域)。

安裝命令很是簡單,只須要打開一個終端,在終端中輸入以下命令: sql

[root@server ~]# yum install httpd -y 數據庫

安裝完畢後,須要設置讓 Apache 服務啓動,而且在每次服務器重啓的時候都自動啓動,輸入以下命令來完成: centos

[root@server ~]# /etc/init.d/httpd start
[root@server ~]# chkconfig httpd on 瀏覽器

若是您想經過您的防火牆活路由器來遠程鏈接,那麼須要容許 Apache 服務接管服務器的 80 端口: 服務器

[root@server ~]# vi /etc/sysconfig/iptables
[...]
-A INPUT -p udp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
[...] cookie

從新啓動 iptables :

[root@server ~]# /etc/init.d/iptables restart

打開您的瀏覽器訪問 http://localhost/ 或者 http://server-ip-address/ 測試 Apache 安裝是否成功。


點擊查看原始大圖

安裝 MariaDB

MariaDB 是一個替換 MySQL 的產品。功能強大而可靠。安裝前,若是您的服務器中安裝有 MySQL ,那麼您須要刪除它。刪除命令:

[root@server ~]# yum remove mysql* mysql-server mysql-devel mysql-libs

爲了讓 MariaDB 同時兼容 MySQL,咱們須要安裝 REMI 庫來解決兼容性和安裝 MariaDB 時軟件包依賴性問題。安裝命令:

[root@server ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

安裝兼容 mysql55 包命令: 

[root@server ~]# yum --enablerepo=remi-test --disablerepo=remi install compat-mysql55

爲 MariaDB 建立一個 repository 文件,並在其中輸入以下代碼:

32 位系統:

[root@server ~]# vi /etc/yum.repos.d/mariadb.repo
# MariaDB 5.5 CentOS repository list - created 2013-06-06 07:42 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-x86
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

64 位系統: 

[root@server ~]# vi /etc/yum.repos.d/mariadb.repo
# MariaDB 5.5 CentOS repository list - created 2013-06-06 07:53 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

保存並退出該文件,並運行 yum update 命令:

[root@server ~]# yum update

如今開始安裝 MariaDB :

[root@server ~]# yum install MariaDB-devel MariaDB-client MariaDB-server -y

安裝完畢後,啓動 MariaDB 服務,並讓它在每次重啓服務器後自動啓動。

[root@server ~]# /etc/init.d/mysql start
Starting MySQL... SUCCESS!
[root@server ~]# chkconfig mysql on

爲 MySQL 的 root 設置密碼,默認狀況下,MySWL root 密碼是空的。爲了防止未經受權的用戶訪問 MySQL 咱們須要設置 root 用戶密碼:

[root@server ~]# /usr/bin/mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

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

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, 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 MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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] 
 ... 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] 
 ... Success!

By default, MariaDB 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] 
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - 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] 
 ... Success!

Cleaning up...

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

Thanks for using MariaDB!

安裝 PHP

PHP(PHP 是:Hypertext Preprocessor 的縮寫)是一種普遍使用的開放源碼的通用腳本語言,適合於 Web 開發,可嵌入到 HTML 中。

安裝 PHP 命令:

[root@server ~]# yum install php -y

建立一個的 「testphp.php」 的文件在 Apache 的文檔根目錄文件夾,在其中如入以下代碼。命令:

[root@server ~]# vi /var/www/html/testphp.php
<?php
phpinfo();
?>

從新啓動 httpd 服務:

[root@server ~]# /etc/init.d/httpd restart

用瀏覽器打開 http://server-ip-address/testphp.php 。它會顯示關於 PHP 的詳細信息,好比版本,創建日期等。


點擊查看原始大圖

若是您須要安裝全部的 PHP 模塊,能夠輸入 yum install php* -y 來安裝,安裝完畢後重啓 httpd 服務。重啓服務後,您能夠用瀏覽器打開 http://server-ip-address/testphp.php 來查看您剛纔安裝的模塊狀況。

安裝 nstall phpMyAdmi

根據您的狀況來選擇是否安裝 nstall phpMyAdmin 。

phpMyAdmin 是一個免費開源的 MySQL 管理工具。默認狀況下 CentOS/RHEL/Scientific Linux 官方庫中沒有 phpMyAdmin。因此咱們須要從 EPEL 庫中安裝。

首先,咱們須要添加 EPEL 庫:

[root@server ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

如今咱們能夠安裝 phpMyAdmin 了。安裝命令:

[root@server ~]# yum install phpmyadmin -y

安裝完畢後,咱們須要配置的 phpMyAdmin。打開 phpmyadmin.conf 的文件。查找以「<Directory」 開頭到 </Directory> 包含的部分,以下命令所示:

[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>

打開 config.inc.php 文件,將 cookie 改成 http。

[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';
[...]

從新啓動 Apache 服務:

[root@server ~]# /etc/init.d/httpd restart

如今,您能夠訪問 phpmyadmin 控制太來管理 MySQL 了。打開一個瀏覽器,訪問:http://server-ip-address/phpmyadmin/ 。須要輸入您的 MySQL 用戶名和密碼,若是您按前面的步驟設置了密碼的話。我設置的是 「root」 和 「centOS」。


點擊查看原始大圖

您將被重定向到 phpMyAdmin 的 Web 主界面:


點擊查看原始大圖

如今,您可以經過 phpMyAdmin 管理您的 MariaDB 數據庫了。

好了,您的 LAMP 服務器已經安裝完畢並運行起來了。

帖子信息

本文系DeadFire原創,版權歸DeadFire及 Linux中國全部,轉貼請註明。
相關文章
相關標籤/搜索