亚洲熟女综合色一区二区三区,亚洲精品中文字幕无码蜜桃,亚洲va欧美va日韩va成人网,亚洲av无码国产一区二区三区,亚洲精品无码久久久久久久

「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)

LAMP是什么?

LAMP企業(yè)中最常用的服務(wù),也是非常穩(wěn)定的網(wǎng)站架構(gòu)平臺。其中L-指的是Linux,A-指的是Apache,m-指的是mysql或者marriDB,p-php。相信大家對這些都已經(jīng)非常熟悉了,但是對于剛接觸的新手來說,可能還不是太明白,要裝什么包啊,什么模塊啊。其實LAMP并不難,下面就和大家分享一下以rpm包的方式安裝LAMP,配置基于域名的虛擬機主機并部署PhpMyAdmin 。

1 安裝httpd并配置基于域名的虛擬主機

1.1安裝
yum install httpd 
systemctl start httpd.service
1.2 配置基于域名的虛擬機主機實現(xiàn)

(1) 關(guān)閉防火墻和SELINUX

systemctl stop firewalld 
systemctl disable firewalld

(2)建立虛擬主機的根目錄和文件

mkdir /data/{a,b,c}site
echo asite > /data/asite/index.html 
echo bsite > /data/bsite/index.html 
echo csite > /data/csite/index.html

(3)創(chuàng)建虛擬主機的配置文件

vim /etc/httpd/conf.d/virtualhost.conf
 
<virtualhost *:80>
DocumentRoot "/data/asite"
servername www.a.com
<directory /data/asite>
Require all granted
</directory>
customlog /var/log/httpd/access_a.log testlog
</virtualhost>
 
<virtualhost *:80>
servername www.b.net
DocumentRoot "/data/bsite"
    <directory /data/bsite>
    Require all granted
    </directory>
customlog /var/log/httpd/access_b.log testlog
</virtualhost>
 
<virtualhost *:80>
servername www.c.com
DocumentRoot "/data/csite"
    <directory /data/csite>
    Require all granted
    </directory>
customlog /var/log/httpd/access_c.log testlog
</virtualhost>

(4)重啟Apache

systemctl restart httpd.service

(5)利用宿主機Windows訪問虛擬機前先修改Windows的hosts文件

修改C:WindowsSystem32driversetchosts

根據(jù)虛擬機的地址添加域名解析,192.168.52.128是自己httpd服務(wù)器的地址。

192.168.52.128 www.a.com 
192.168.52.128 www.b.net 
192.168.52.128 www.c.com

(6)在Windows訪問三個站點

打開瀏覽器分別輸入三個地址:

「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)
「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)
「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)

2. 安裝mariadb

(1)yum安裝

yum install mariadb-server
systemctl start mariadb

(2)運行安全腳本

/usr/bin/mysql_secure_installation
 

運行此腳本,執(zhí)行:

  • 設(shè)置數(shù)據(jù)庫管理員root口令
  • 禁止root遠程登錄
  • 刪除anonymous用戶帳號
  • 刪除test數(shù)據(jù)庫

(3)配置mariadb

vim /etc/my.cnf
    [mysqld]
    innodb_file_per_table = ON
    skip_name_resolve = ON
    

(4)重啟mariadb

systemctl restart mariadb

3 安裝php

(1)yum安裝

yum -y install php php-mysql 

安裝后重啟httpd服務(wù):

systemctl restart httpd.service

(2)編寫php腳本,看一下是否能解析成功:

vim /var/www/html/testphp.php

「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)

效果:

「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)

(3)配置php通過PDO方式連接數(shù)據(jù)庫

cp  /usr/share/doc/php-common-5.4.16/php.ini-development /etc/php.ini

編輯此文件,加入這一行:

vim /etc/php.ini
extention=pdo.so

重啟服務(wù):

systemctl restart httpd.service

(4)編寫pdo測試代碼:

vim /data/asite/pdo.php
 
<?php
try {
$user='root';
$pass='magedu';
$dbh = new PDO('mysql:host=192.168.34.27;dbname=mysql', $user, $pass);
foreach($dbh->query('SELECT user,host from user') as $row) {
print_r($row);
}$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>

愉快地實現(xiàn)了pdo連接mysql,上面測試代碼的實現(xiàn)結(jié)果:

「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)

4. 部署phpMyAdmin

(1)下載phpMyAdmin,放在asite下面:

「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)

(2)解壓縮

tar xvf phpMyAdmin-4.0.10-english.tar.xz
mv phpMyAdmin-4.0.10-english phpMyAdmin

(3)提供配置文件

cd phpMyAdmin
cp config.sample.inc.php config.inc.php

vim config.inc.php 設(shè)置密碼

「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)

重新加載服務(wù):

systemctl reload httpd
「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)

輸入數(shù)據(jù)庫的賬號密碼即可登錄:

「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)

注:如果出現(xiàn)這樣的問題:The json extension is missing.

「敲黑板」小白必看:Centos 7 搭建LAMP(rpm方式)

解決辦法是:

vim /etc/php.ini
#加入這一行
extention=json.so

按照以上步驟操作可輕松實現(xiàn)Centos 7 搭建LAMP(rpm方式),建議保存!

好啦!今天的分享啊到這里就結(jié)束了,希望大家持續(xù)關(guān)注馬哥教育官網(wǎng), 每天都會有大量優(yōu)質(zhì)內(nèi)容與大家分享!

文章來源于網(wǎng)絡(luò),侵刪!

相關(guān)新聞

歷經(jīng)多年發(fā)展,已成為國內(nèi)好評如潮的Linux云計算運維、SRE、Devops、網(wǎng)絡(luò)安全、云原生、Go、Python開發(fā)專業(yè)人才培訓(xùn)機構(gòu)!