(1)配置概要:
1、 172.16.100.31主機(jī)運(yùn)行httpd+php服務(wù)(php為模塊工作模式)
配置兩臺(tái)虛擬主機(jī):wordpress個(gè)人博客系統(tǒng)、PHPmyadmin遠(yuǎn)程控制MySQL
創(chuàng)新互聯(lián)公司是一家朝氣蓬勃的網(wǎng)站建設(shè)公司。公司專注于為企業(yè)提供信息化建設(shè)解決方案。從事網(wǎng)站開發(fā),網(wǎng)站制作,網(wǎng)站設(shè)計(jì),網(wǎng)站模板,微信公眾號(hào)開發(fā),軟件開發(fā),成都小程序開發(fā),十年建站對(duì)成都三輪攪拌車等多個(gè)行業(yè),擁有豐富建站經(jīng)驗(yàn)。
2、172.16.100.31主機(jī)運(yùn)行mariadb服務(wù)(mysql)
(2)配置流程:
首先配置172.16.100.31主機(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/vhost1.conf文件
[root@johnson's linux ~]# vim /etc/httpd/conf.d/vhost1.conf
[root@johnson's linux ~]# vim /etc/httpd/conf.d/vhost2.conf
# 添加如下內(nèi)容,基于FQDN的虛擬主機(jī)配置
<VirtualHost 172.16.100.31:80> # 固定語(yǔ)法 <VirtualHost ip:port>可忽略大小寫
ServerName www1.wufeng.com # 很重要,基于FQDN的虛擬主機(jī)必須要有主機(jī)名
DocumentRoot "/data/vhost/www1" # 虛擬主機(jī)根目錄,可指定路徑
CustomLog logs/www1-access_log combined #指定日志文件路徑以及名字
<Directory "/data/vhost/www1"> # 對(duì)虛擬主機(jī)根目錄的權(quán)限設(shè)置
Options None
AllowOverride None
require all granted # 目錄的權(quán)限設(shè)置
</Directory>
</VirtualHost>
<VirtualHost 172.16.100.31:80>
ServerName www2.wufeng.com
DocumentRoot "/data/vhost/www2"
CustomLog logs/www2-access_log combined
<Directory "/data/vhost/www2">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
Options:為個(gè)目錄的選項(xiàng),可以指定多個(gè)特性
如:Index,啟動(dòng)資源索引,其作用是在用戶在訪問指定的URL不存在時(shí),返回web資源索引,此選項(xiàng)
非常危險(xiǎn),不建議啟用,否則源碼則會(huì)web源碼暴露,后果很嚴(yán)重
訪問權(quán)限設(shè)定:
Require all Granted/deny, Granted表示允許,all表示所有,deny表示拒絕
需要注意的是:CentOS7是默認(rèn)拒絕所有主機(jī)訪問DocumentRoot的資源,所以,配置虛擬主機(jī)必須要配置此先參數(shù)
(2)為虛擬主機(jī)創(chuàng)建配置文件中定義的資源目錄并
[root@johnson's linux ~]# mkdir -pv /data/vhost/www{1,2}
(3)添加測(cè)試資源
[root@johnson's linux ~]# vim /data/vhost/www1/index.php
# 前面這段是測(cè)試php與mysql連通性的PHP代碼
<?php
$conn = mysql_connect('172.16.100.31','admin','admin'); # ip填寫mysql主機(jī)ip
if ($conn) # 用戶為mysql所授權(quán)的用戶,密碼空
echo "DATABASE Connet OK";
else
echo "DATABASE Connet Failure";
?>
# 測(cè)試php是否正常工作的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ù)器名稱注釋
(5)啟動(dòng)服務(wù),測(cè)試是否正常
# 檢測(cè)配置文件語(yǔ)法有沒有錯(cuò)誤
[root@johnson's linux ~]# httpd -t
# 語(yǔ)法無(wú)誤啟動(dòng)服務(wù)
[root@johnson's linux ~]# systemctl start httpd.service
打開網(wǎng)頁(yè)查看服務(wù)是否正常
http服務(wù)測(cè)試正常,php模塊也能正常工作,但是,mysql的連接是失敗,因?yàn)槲覀冞€mysql的服務(wù)器還沒有配置
(5)獲取wordpress和phpmyadmin
wo是在局域網(wǎng)中ftp服務(wù)器中下載的
wordpress配置:
# 下載并解壓至/data/vhost/www1
# 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'); # 此填寫mysql所要授權(quán)數(shù)據(jù)庫(kù)的名字(后面會(huì)配置)
/** MySQL數(shù)據(jù)庫(kù)用戶名 */
define('DB_USER', 'wpuser'); # 填寫數(shù)據(jù)庫(kù)的用戶名
/** MySQL數(shù)據(jù)庫(kù)密碼 */
define('DB_PASSWORD', 'wppasswd'); # 填寫數(shù)據(jù)的密碼
/** MySQL主機(jī) */
define('DB_HOST', '172.16.100.31'); # 填寫mysql主機(jī)的ip
/** 創(chuàng)建數(shù)據(jù)表時(shí)默認(rèn)的文字編碼 */
define('DB_CHARSET', 'utf8');
/** 數(shù)據(jù)庫(kù)整理類型。如不確定請(qǐng)勿更改 */
define('DB_COLLATE', '');
phpmyadmin配置:
phpMyAdmin-4.4.14.1-all-languages.zip# 將包下載并解壓至/data/vhost/www1
# 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)填寫隨機(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.16.100.31'; # 數(shù)據(jù)庫(kù)主機(jī)ip
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
--------------------------------------------------------------------------------
172.16.100.31主機(jī)配置:mysql服務(wù)
(1)yum安裝程序
[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源配置沒有問題,可以輕松解決
(2)啟動(dòng)服務(wù),執(zhí)行安全安裝操作
[root@johnson's linux ~]# systemctl start mariadb
# 查看監(jiān)聽端口,3306為mariaDB的默認(rèn)監(jiān)聽端口
[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沒關(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ù)更安全
(3)創(chuàng)建所需數(shù)據(jù)庫(kù)并授權(quán)
[root@johnson's linux ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 66
Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE wpdb; # 創(chuàng)建wordpress的數(shù)據(jù)庫(kù)
Query OK, 1 row affected (0.02 sec)
# 授權(quán)wordpress數(shù)據(jù)庫(kù)
# 創(chuàng)建數(shù)據(jù)名字
MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'wpuser'@'172.16.%.%' IDENTIFIED BY 'wppass';
然后建立這個(gè)數(shù)據(jù)庫(kù)
MariaDB [(none)]> CREATE DATABASE wpdb;
(4)支持所有配置基本完畢:驗(yàn)證結(jié)果
1、驗(yàn)證數(shù)據(jù)庫(kù)聯(lián)通
2、查看wordpress是否正常
最后補(bǔ)充一下:
phpMyadmin常見錯(cuò)誤:
1.缺少mbstring插件
yum 安裝php-mbstring即可
2.丟失session目錄
一般 在/var/lib/php/session ,沒有則創(chuàng)建即可
網(wǎng)頁(yè)名稱:CentOS7下安裝部署LAMP環(huán)境
文章源于:http://chinadenli.net/article36/iegosg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、移動(dòng)網(wǎng)站建設(shè)、用戶體驗(yàn)、網(wǎng)站策劃、ChatGPT、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)