CentOS7LAMP部署流程

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

創(chuàng)新互聯(lián)建站是專業(yè)的寧陽網(wǎng)站建設(shè)公司,寧陽接單;提供成都做網(wǎng)站、成都網(wǎng)站建設(shè)、成都外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行寧陽網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊,希望更多企業(yè)前來合作!

  2、172.18.17.8主機(jī)運行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:安裝后自動編譯為httpd的模塊,用于處理動態(tài)資源php腳本

php-mbstring:此程序包為phpMyAdmin遠(yuǎn)程控制mysql所必須的

php-mysql:php驅(qū)動mysql的庫文件程序包

2、服務(wù)配置

包都安裝完成之后,進(jìn)入下一步的配置階段:

(1)添加虛擬主機(jī):(基于FQDN)

  虛擬主機(jī)有三種配置方式:一種是基于不同ip,相同端口(80),二是相同IP不同端口,三是同一IP不同主機(jī)名(FQDN),不管何種配置方式,最后解析到的主機(jī)只有一臺,但是在請求報文首部信息會有不同!以下,僅演示基于FQDN的配置方式

    編輯:/etc/httpd/conf.d/vhost.conf文件

[root@johnson's linux ~]# vim /etc/httpd/conf.d/vhost.conf 
# 添加如下內(nèi)容,基于FQDN的虛擬主機(jī)配置
<VirtualHost 172.18.17.7:80>  # 固定語法 <VirtualHost ip:port>可忽略大小寫
    ServerName   # 很重要,基于FQDN的虛擬主機(jī)必須要有主機(jī)名  
    DocumentRoot "/www/host/htdoc" # 虛擬主機(jī)根目錄,可指定路徑 
<Directory "/www/host/htdoc">   # 對虛擬主機(jī)根目錄的權(quán)限設(shè)置
    Options FollowSymLinks    # FollowSymLinks  表示可以訪問符號連接資源
    require all Granted     # 目錄的權(quán)限設(shè)置
</Directory>               
</VirtualHost>

<VirtualHost 172.18.17.7:80>
    ServerName www.myadmin.com
    DocumentRoot "/www/host2/htdoc"
<Directory "/www/host2/htdoc">
    Options FollowSymLinks
    require all Granted
</Directory>
</VirtualHost>

Options:為個目錄的選項,可以指定多個特性

    如:Index,啟動資源索引,其作用是在用戶在訪問指定的URL不存在時,返回web資源索引,此選項

非常危險,不建議啟用,否則源碼則會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/www/{host,host2}/htdoc

(3)添加測試資源

[root@johnson's linux ~]# vim /www/host/htdoc/index.php
# 前面這段是測試php與mysql連通性的PHP代碼
<?php
    $conn = mysql_connect('172.18.17.8','admin','admin'); # ip填寫mysql主機(jī)ip
    if ($conn)                                          # 用戶為mysql所授權(quán)的用戶,密碼空
        echo "DATABASE Connet OK";
    else
        echo "DATABASE Connet Failure";
?>
# 測試php是否正常工作的php代碼
<?php
    phpinfo() #此函數(shù)調(diào)用會顯示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主頁索引
DirectoryIndex index.php index.html # 將index.php添加在前頭,這樣就會默認(rèn)訪問此類資源索引

# 取消服務(wù)器名稱注釋

(5)啟動服務(wù),測試是否正常

# 檢測配置文件語法有沒有錯誤
[root@johnson's linux ~]# httpd -t
# 語法無誤啟動服務(wù)
[root@johnson's linux ~]# systemctl start httpd.service

 

打開網(wǎng)頁查看服務(wù)是否正常   

CentOS7LAMP部署流程

   

http服務(wù)測試正常,php模塊也能正常工作,但是,如你所見,mysql的連接是失敗,因為我們還mysql的服務(wù)器還沒有配置

(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è)置 - 具體信息來自您正在使用的主機(jī) ** //
/** WordPress數(shù)據(jù)庫的名稱 */
define('DB_NAME', 'wpdb');  # 此填寫mysql所要授權(quán)數(shù)據(jù)庫的名字(后面會配置)

/** MySQL數(shù)據(jù)庫用戶名 */

define('DB_USER', 'wpuser'); # 填寫數(shù)據(jù)庫的用戶名

/** MySQL數(shù)據(jù)庫密碼 */
define('DB_PASSWORD', 'wppasswd'); # 填寫數(shù)據(jù)的密碼

/** MySQL主機(jī) */
define('DB_HOST', '172.18.17.8'); # 填寫mysql主機(jī)的ip

/** 創(chuàng)建數(shù)據(jù)表時默認(rèn)的文字編碼 */
define('DB_CHARSET', 'utf8');

/** 數(shù)據(jù)庫整理類型。如不確定請勿更改 */
define('DB_COLLATE', '');

phpmyadmin配置:

# 將包下載并解壓至/www/host2/htdoc
# cd 到 文件目錄
# 創(chuàng)建符號連接
[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! */
                #單引號填寫隨機(jī)密碼,可使用openssl rand -base64 15(密碼長度)生成
                        
/*
 * 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ù)庫主機(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安裝程序

[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)啟動服務(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!                    # 允許匿名登陸時很危險的,建議移除

Disallow root login remotely? [Y/n] n  # 是否不允許管理員賬號遠(yuǎn)程登陸,一般情況下建議不允許
 ... skipping.                        

Remove test database and access to it? [Y/n] y # 移除測試數(shù)據(jù)庫
 - 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ù)庫更安全

 

(3)創(chuàng)建所需數(shù)據(jù)庫并授權(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ù)庫
Query OK, 1 row affected (0.02 sec)   

# 授權(quán)wordpress數(shù)據(jù)庫
MariaDB [(none)]> GRANT ALL ON wpdb.* TO wpuser@172.18.17.7 IDENTIFIED BY 'wppasswd';
Query OK, 0 rows affected (0.01 sec)

#授權(quán)遠(yuǎn)程訪問主機(jī)(phpMyadmin)
MariaDB [(none)]> GRANT ALL ON *.* TO admin@'172.18.17.7' IDENTIFIED BY 'admin'; 
Query OK, 0 rows affected (0.01 sec)

(4)支持所有配置基本完畢:驗證結(jié)果

 1、驗證數(shù)據(jù)庫聯(lián)通

CentOS7LAMP部署流程

2、查看wordpress是否正常

CentOS7LAMP部署流程

CentOS7LAMP部署流程

CentOS7LAMP部署流程

不知為何,我的phpmyadmin顯示不大正常,能跑起來就行!配置到此結(jié)束!

最后補(bǔ)充一下:             
phpMyadmin常見錯誤:
    1.缺少mbstring插件

    yum 安裝php-mbstring即可

    2.丟失session目錄

   一般 在/var/lib/php/session ,沒有則創(chuàng)建即可


當(dāng)前名稱:CentOS7LAMP部署流程
URL地址:http://bm7419.com/article30/jdjcso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、App開發(fā)、域名注冊、響應(yīng)式網(wǎng)站小程序開發(fā)、

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司