新聞中心
(1)配置概要:
1、 172.18.17.7主機(jī)運(yùn)行httpd+php服務(wù)(php為模塊工作模式)
配置兩臺(tái)虛擬主機(jī):wordpress個(gè)人博客系統(tǒng)、PHPmyadmin遠(yuǎn)程控制mysql

2、172.18.17.8主機(jī)運(yùn)行mariadb服務(wù)(mysql)
(2)配置流程:
首先配置172.18.17.7主機(jī):http服務(wù)
1、安裝程序:
[root@johnson's linux ~]# yum install httpd php php-mysql php-mbstring
========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
httpd x86_64 2.4.6-40.el7.centos base 2.7 M
php x86_64 5.4.16-36.el7_1 base 1.4 M
php-mbstring x86_64 5.4.16-36.el7_1 base 503 k
php-mysql x86_64 5.4.16-36.el7_1 base 99 k
Transaction Summary
=======================================================================================
httpd:提供web服務(wù)
php:安裝后自動(dòng)編譯為httpd的模塊,用于處理動(dòng)態(tài)資源php腳本
php-mbstring:此程序包為phpMyAdmin遠(yuǎn)程控制mysql所必須的
php-mysql:php驅(qū)動(dòng)mysql的庫(kù)文件程序包
2、服務(wù)配置
包都安裝完成之后,進(jìn)入下一步的配置階段:
(1)添加虛擬主機(jī):(基于FQDN)
虛擬主機(jī)有三種配置方式:一種是基于不同ip,相同端口(80),二是相同IP不同端口,三是同一IP不同主機(jī)名(FQDN),不管何種配置方式,最后解析到的主機(jī)只有一臺(tái),但是在請(qǐng)求報(bào)文首部信息會(huì)有不同!以下,僅演示基于FQDN的配置方式
編輯:/etc/httpd/conf.d/vhost.conf文件
[root@johnson's linux ~]# vim /etc/httpd/conf.d/vhost.conf
# 添加如下內(nèi)容,基于FQDN的虛擬主機(jī)配置
ServerName # 很重要,基于FQDN的虛擬主機(jī)必須要有主機(jī)名
DocumentRoot "/www/host/htdoc" # 虛擬主機(jī)根目錄,可指定路徑
Options FollowSymLinks # FollowSymLinks 表示可以訪問(wèn)符號(hào)連接資源
require all Granted # 目錄的權(quán)限設(shè)置
ServerName www.myadmin.com
DocumentRoot "/www/host2/htdoc"
Options FollowSymLinks
require all Granted
Options:為個(gè)目錄的選項(xiàng),可以指定多個(gè)特性
如:Index,啟動(dòng)資源索引,其作用是在用戶在訪問(wèn)指定的URL不存在時(shí),返回web資源索引,此選項(xiàng)
非常危險(xiǎn),不建議啟用,否則源碼則會(huì)web源碼暴露,后果很嚴(yán)重
訪問(wèn)權(quán)限設(shè)定:
Require all Granted/deny, Granted表示允許,all表示所有,deny表示拒絕
需要注意的是:CentOS7是默認(rèn)拒絕所有主機(jī)訪問(wèn)DocumentRoot的資源,所以,配置虛擬主機(jī)必須要配置此先參數(shù)
(2)為虛擬主機(jī)創(chuàng)建配置文件中定義的資源目錄并
[root@johnson's linux ~]# mkdir/www/{host,host2}/htdoc
(3)添加測(cè)試資源
[root@johnson's linux ~]# vim /www/host/htdoc/index.php
# 前面這段是測(cè)試php與mysql連通性的PHP代碼
$conn = mysql_connect('172.18.17.8','admin','admin'); # ip填寫(xiě)mysql主機(jī)ip
if ($conn) # 用戶為mysql所授權(quán)的用戶,密碼空
echo "DATABASE Connet OK";
else
echo "DATABASE Connet Failure";
?>
# 測(cè)試php是否正常工作的php代碼
phpinfo() #此函數(shù)調(diào)用會(huì)顯示php的詳細(xì)信息
?>
(4)配置httpd主配置文件
編輯:/etc/httpd/conf/httpd.conf
[root@johnson's linux ~]# vim /etc/httpd/conf/httpd.conf
# 找到 DocumentRoot "/var/www/html" ,#將其注釋掉,一般使用虛擬機(jī)都要注釋掉,避免沖突
#DocumentRoot "/var/www/html"
# 添加php主頁(yè)索引
DirectoryIndex index.php index.html # 將index.php添加在前頭,這樣就會(huì)默認(rèn)訪問(wèn)此類資源索引
# 取消服務(wù)器名稱注釋
(5)啟動(dòng)服務(wù),測(cè)試是否正常
# 檢測(cè)配置文件語(yǔ)法有沒(méi)有錯(cuò)誤
[root@johnson's linux ~]# httpd -t
# 語(yǔ)法無(wú)誤啟動(dòng)服務(wù)
[root@johnson's linux ~]# systemctl start httpd.service
打開(kāi)網(wǎng)頁(yè)查看服務(wù)是否正常
http服務(wù)測(cè)試正常,php模塊也能正常工作,但是,如你所見(jiàn),mysql的連接是失敗,因?yàn)槲覀冞€mysql的服務(wù)器還沒(méi)有配置
下面關(guān)于LAMP相關(guān)的內(nèi)容你可能也喜歡:
(5)獲取wordpress和phpmyadmin
博主的是在局域網(wǎng)中ftp服務(wù)器中下載的
wordpress配置:
# 下載并解壓至/www/host/htdoc
# cd 到wordpress目錄 ,配置文件如下
[root@johnson's linux wordpress]# ls
index.php wp-blog-header.php wp-cron.php wp-mail.php
license.txt wp-comments-post.php wp-includes wp-settings.php
readme.html wp-links-opml.php wp-signup.php
wp-activate.php wp-config-sample.php wp-load.php wp-trackback.php
wp-admin wp-content wp-login.php xmlrpc.php
# 復(fù)制配置文件以上的 wp-config-sample.php 為 wp-config.php
[root@johnson's linux wordpress]# cp wp-config-sample.php wp-config.php
# 編輯配置文件
[root@johnson's linux wordpress]# vim wp-config.php
// ** MySQL 設(shè)置 - 具體信息來(lái)自您正在使用的主機(jī) ** //
/** WordPress數(shù)據(jù)庫(kù)的名稱 */
define('DB_NAME', 'wpdb'); # 此填寫(xiě)mysql所要授權(quán)數(shù)據(jù)庫(kù)的名字(后面會(huì)配置)
/** MySQL數(shù)據(jù)庫(kù)用戶名 */
define('DB_USER', 'wpuser'); # 填寫(xiě)數(shù)據(jù)庫(kù)的用戶名
/** MySQL數(shù)據(jù)庫(kù)密碼 */
define('DB_PASSWORD', 'wppasswd'); # 填寫(xiě)數(shù)據(jù)的密碼
/** MySQL主機(jī) */
define('DB_HOST', '172.18.17.8'); # 填寫(xiě)mysql主機(jī)的ip
/** 創(chuàng)建數(shù)據(jù)表時(shí)默認(rèn)的文字編碼 */
define('DB_CHARSET', 'utf8');
/** 數(shù)據(jù)庫(kù)整理類型。如不確定請(qǐng)勿更改 */
define('DB_COLLATE', '');
phpmyadmin配置:
1234567891011121314151617181920212223242526272829303132 # 將包下載并解壓至/www/host2/htdoc
# cd 到 文件目錄
# 創(chuàng)建符號(hào)連接
[root@johnson's linux htdoc]# ln -s phpMyAdmin-4.4.14.1-all-languages myadmin
[root@johnson's linux htdoc]# ls
index.php phpMyAdmin-4.4.14.1-all-languages
myadmin phpMyAdmin-4.4.14.1-all-languages.zip
#cd 至myadmin 目錄里面,修改配置文件
[root@johnson's linux htdoc]# cp config.sample.inc.php config.inc.php
#編輯配置文件
[root@johnson's linux htdoc]# vim config.inc.php
$cfg['blowfish_secret'] = 'o71mI9rimj6syc00fT3g'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
#單引號(hào)填寫(xiě)隨機(jī)密碼,可使用openssl rand -base64 15(密碼長(zhǎng)度)生成
/*
* Servers configuration
*/
$i = 0;
/*
* First server
*/
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '172.18.17.8'; # 數(shù)據(jù)庫(kù)主機(jī)ip
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
--------------------------------------------------------------------------------
172.18.17.8主機(jī)配置:mysql服務(wù)
(1)yum安裝程序
1234567891011121314151617 [root@johnson's linux ~]# yum install mariadb-server
========================================================================================
Installing:
mariadb-server x86_64 1:5.5.44-2.el7.centos base 11 M
Installing for dependencies:
mariadb x86_64 1:5.5.44-2.el7.centos base 8.9 M
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBD-MySQL x86_64 4.023-5.el7 base 140 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k
Transaction Summary
========================================================================================
一大推依賴包,只要有yum在且yum源配置沒(méi)有問(wèn)題,可以輕松解決
(2)啟動(dòng)服務(wù),執(zhí)行安全安裝操作
12345678910111213141516171819202122232425262728293031323334353637383940414243444546 [root@johnson's linux ~]# systemctl start mariadb
# 查看監(jiān)聽(tīng)端口,3306為mariaDB的默認(rèn)監(jiān)聽(tīng)端口
[root@johnson's linux ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:3306 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 :::22 :::*
執(zhí)行安全安裝操作
[root@johnson's linux ~]# mysql_secure_installation
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y # 設(shè)置管理員登陸秘密(此密碼和linux系統(tǒng)的root沒(méi)關(guān)系)
New password:
Re-enter new password: # 輸入密碼即可
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] y # 是否移除匿名用戶(在執(zhí)行安全安裝之前不需要密碼登陸)
... Success! # 允許匿名登陸時(shí)很危險(xiǎn)的,建議移除
Disallow root login remotely? [Y/n] n # 是否不允許管理員賬號(hào)遠(yuǎn)程登陸,一般情況下建議不允許
... skipping.
Remove test database and access to it? [Y/n] y # 移除測(cè)試數(shù)據(jù)庫(kù)
- 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] y # 重載權(quá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!
強(qiáng)烈建議在mariaDB安裝完成后執(zhí)行安全安裝操作,這樣可以使得數(shù)據(jù)庫(kù)更安全
名稱欄目:CentOS7下安裝部署LAMP環(huán)境
網(wǎng)站地址:http://fisionsoft.com.cn/article/dhdcehg.html


咨詢
建站咨詢
