構建lamp(php-fpm方式)

一适袜、準備一臺centos7虛擬機苦酱,ip為192.168.10.30给猾。同時作為httpd服務器敢伸,fpm服務器池颈,mariadb服務器。192.168.10.20測試機

使用yum倉庫下載mariadb? ? ?httpd版本:2.4.6每币,php-fpm版本:5.4.16脯爪,mariadb版本:5.5.64,php-mysql版本:5.4.16尚揣,php-mbstring版本:5.4.16

(1)安裝并配置MariaDB服務

# yum -y install mariadb-server

編輯mariadb的配置文件添加常用選項

# vim /etc/my.cnf.d/server.cnf

skip_name_resolve=ON 跳過名稱解析

innodb_file_per_table=ON 每表使用單獨的表空間文件

啟動mariadb并開機自啟動

# systemctl start mariadb

# systemctl enable mariadb

本地連接測試:

# mysql

Welcome to the MariaDB monitor.? Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>exit

Bye

安全加固

# mysql_secure_installation

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.

Set root password? [Y/n] Y? ? ? 設置root密碼

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] Y? ? ? ? ?刪除默認的匿名用戶

... 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] Y? ?禁止root管理員遠程登陸,建議禁止

... 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] n? ? 是否刪除名為test的測試庫

... skipping.

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] Y? ? ? ? ? ? ? ? ? ? ?重載特權表

... 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!

加固之后匕得,再使用用戶名密碼登陸

# mysql -uroot -h127.0.0.1 -plhp@ssw0rd

Welcome to the MariaDB monitor.? Commands end with ; or \g.

Your MariaDB connection id is 10

Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

授權一個普通用戶做后面的測試汁掠,用戶名 myuser? 密碼mypass

MariaDB [(none)]> GRANT ALL ON testdb.* TO 'myuser'@'192.168.10.%' IDENTIFIED BY 'mypass';

Query OK, 0 rows affected (0.00 sec)

刷新授權表

? ??MariaDB [(none)]> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

退出sql用新建的用戶測試連接

# mysql -umyuser -h192.168.10.30 -pmypass

Welcome to the MariaDB monitor.? Commands end with ; or \g.

Your MariaDB connection id is 11

Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

創(chuàng)建數據庫testdb并指定默認字符集為utf8

MariaDB [(none)]> CREATE DATABASE testdb CHARACTER SET 'utf8';

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> exit?

Bye


(2)安裝并配置pmp-fpm服務

確保沒有和php同時安裝

# yum info php

還在倉庫中

# yum info php-fpm

還在倉庫中


安裝php-fpm和連接數據庫的php-mysql和支持多字符的php-mbstring和加解密的php-mcrypt

# yum -y install php-fpm php-mysql php-mbstring php-mcrypt

服務配置文件:/etc/php-fpm.conf , /etc/php-fpm.d/*.conf

/etc/php-fpm.d/www.conf中的關鍵參數:

listen = 127.0.0.1:9000? ? 監(jiān)聽的主機和端口,跨主機部署需要修改

;listen.backlog = -1? 后援隊列乞榨,等待隊列,請求等待政溃,-1表示無限制

listen.allowed_clients = 127.0.0.1 允許哪些主機有權限連接請求董虱,跨主機部署amp時需要修改?

user = apache? 運行進程的用戶

group = apache? ?運行進程的組

pm = dynamic? ? 連接池運行為動態(tài)

pm.max_children = 50? 運行的最大子進程數

pm.start_servers = 5? ?服務剛啟動是運行的子進程個數

pm.min_spare_servers = 5? ?最少空閑子進程個數

pm.max_spare_servers = 35? 最大空閑子進程數

;pm.max_requests = 500? ? 每個子進程響應500個請求后重新起一個子進程

;pm.status_path = /status? ?內置狀態(tài)頁

;ping.path = /ping? ? 服務遠程健康狀態(tài)測試

;ping.response = pong??服務遠程健康狀態(tài)測試

php_value[session.save_path] = /var/lib/php/session? 會話持久保持在這個目錄

php環(huán)境配置文件:/etc/php.ini, /etc/php.d/*.ini

創(chuàng)建session保存的目錄愤诱,默認沒創(chuàng)建捐友,在/etc/php-fpm.d/www.conf中定義

# mkdir -pv /var/lib/php/session

mkdir: created directory ‘/var/lib/php/session’

設置運行用戶apache匣砖,組apache猴鲫,和php-fpm一致

# chown apache:apache /var/lib/php/session/

啟動php-fpm服務

# systemctl start php-fpm

# ss -tnl

(3)安裝并配置httpd服務

安裝啟動httpd

# yum -y install httpd

# systemctl start httpd

# systemctl enable httpd

配置一個虛擬主機做測試

# vim /etc/httpd/conf.d/vhosts.conf

<VirtualHost *:80>

? ? ? ? ServerName www.b.net

? ? ? ? DocumentRoot "/apps/vhosts/b.net"

? ? ? ? <Directory "/apps/vhosts/b.net">

? ? ? ? ? ? ? ? Options None

? ? ? ? ? ? ? ? AllowOverride None

? ? ? ? ? ? ? ? Require all granted

? ? ? ? </Directory>

</VirtualHost>

創(chuàng)建虛擬主機對應的網頁目錄及文件

# mkdir -pv /apps/vhosts/b.net

# touch /apps/vhosts/b.net/index.html

# vim /apps/vhosts/b.net/index.html

<h1>

? ? ? ? test page

</h1>

語法檢查

# httpd -t

重啟httpd服務及關閉防火墻和SELinux

# systemctl restart httpd

# systemctl stop firewalld

關閉SELinux

# setenforce 0

測試

配置httpd通過fpm訪問動態(tài)資源

增加/etc/httpd/conf.d/vhost.conf的參數

DirectoryIndex index.php 主頁支持index.php

ProxyRequests Off 關閉正向代理

ProxyPassMatch? ?^/(.*\.php)$? ?fcgi://127.0.0.1:9000/apps/vhosts/b.net/$1? ? ? ?正則表達式模式匹配牺弄,如果用戶請求的URL是以任意字符開頭但以.php結尾势告,那么我們就把他反代到?fcgi://127.0.0.1:9000端口?抚恒,指定動態(tài)網頁存放路徑為/apps/vhosts/b.net/$1俭驮,$1為后向引用,引用第一個括號中的內容馅而,在正則表達式外用$引用瓮恭,在正則表達式中用\引用

進入虛擬主機配置文件目錄

# cd /apps/vhosts/b.net/

將原來的靜態(tài)頁面改名保持屯蹦,創(chuàng)建新的動態(tài)資源.php

# mv index.html test.html

# vim index.php

<?php

? ? ? ? phpinfo()

?>

重啟服務測試

# systemctl restart httpd


(4)設置能通過phpmyadmin網頁管理數據庫

使用宿主機下載phpmyadmin圖形工具用于圖形化管理數據庫:由于當前php版本為5.4.16登澜,所以從https://www.phpmyadmin.net/files/找到降低版本phpMyAdmin-4.0.10.20-all-languages.zip,上傳至centos7服務器/root目錄下脑蠕。

切換到/root目錄對文件進行解壓

# cd ~

# unzip phpMyAdmin-4.0.10.20-all-languages.zip

將解壓后的文件移動至虛擬主機所在的DocumentRoot路徑下的phpmyadmin目錄

# mv phpMyAdmin-4.0.10.20-all-languages /apps/vhosts/b.net/phpmyadmin

切換當前目錄到/apps/vhosts/b.net/phpmyadmin/目錄

# cd /apps/vhosts/b.net/phpmyadmin/

復制其中的文件config.sample.inc.php 命名為config.inc.php?

# cp config.sample.inc.php config.inc.php

編輯配置文件config.inc.php,添加隨機數谴仙,此版本默認有可以不填晃跺,有的版本沒有必須填寫

# vim config.inc.php?

測試機瀏覽器打開192.168.10.30/phpmyadmin/index.php即可訪問


輸入此前設置的數據庫root用戶名密碼即可登陸


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市烹玉,隨后出現的幾起案子春霍,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,036評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件莲趣,死亡現場離奇詭異喧伞,居然都是意外死亡,警方通過查閱死者的電腦和手機翁逞,發(fā)現死者居然都...
    沈念sama閱讀 93,046評論 3 395
  • 文/潘曉璐 我一進店門挖函,熙熙樓的掌柜王于貴愁眉苦臉地迎上來怨喘,“玉大人振定,你說我怎么就攤上這事『笃担” “怎么了梳庆?”我有些...
    開封第一講書人閱讀 164,411評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長卑惜。 經常有香客問我靠益,道長,這世上最難降的妖魔是什么残揉? 我笑而不...
    開封第一講書人閱讀 58,622評論 1 293
  • 正文 為了忘掉前任胧后,我火速辦了婚禮,結果婚禮上抱环,老公的妹妹穿的比我還像新娘壳快。我一直安慰自己镇草,他們只是感情好眶痰,可當我...
    茶點故事閱讀 67,661評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著梯啤,像睡著了一般竖伯。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上因宇,一...
    開封第一講書人閱讀 51,521評論 1 304
  • 那天七婴,我揣著相機與錄音,去河邊找鬼察滑。 笑死打厘,一個胖子當著我的面吹牛,可吹牛的內容都是我干的贺辰。 我是一名探鬼主播户盯,決...
    沈念sama閱讀 40,288評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼嵌施,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了莽鸭?” 一聲冷哼從身側響起吗伤,我...
    開封第一講書人閱讀 39,200評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎硫眨,沒想到半個月后足淆,有當地人在樹林里發(fā)現了一具尸體,經...
    沈念sama閱讀 45,644評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡捺球,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,837評論 3 336
  • 正文 我和宋清朗相戀三年缸浦,在試婚紗的時候發(fā)現自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片氮兵。...
    茶點故事閱讀 39,953評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡裂逐,死狀恐怖,靈堂內的尸體忽然破棺而出泣栈,到底是詐尸還是另有隱情卜高,我是刑警寧澤,帶...
    沈念sama閱讀 35,673評論 5 346
  • 正文 年R本政府宣布南片,位于F島的核電站掺涛,受9級特大地震影響,放射性物質發(fā)生泄漏疼进。R本人自食惡果不足惜薪缆,卻給世界環(huán)境...
    茶點故事閱讀 41,281評論 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望伞广。 院中可真熱鬧拣帽,春花似錦、人聲如沸嚼锄。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,889評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽区丑。三九已至拧粪,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間沧侥,已是汗流浹背可霎。 一陣腳步聲響...
    開封第一講書人閱讀 33,011評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留正什,地道東北人啥纸。 一個月前我還...
    沈念sama閱讀 48,119評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像婴氮,于是被迫代替她去往敵國和親斯棒。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,901評論 2 355

推薦閱讀更多精彩內容