LAMP架構部署詳解

一、LAMP架構介紹

LAMP架構部署詳解

Linux爲操作系統,apache是提供web服務的中間件,mysql主要存儲數據,php是一個腳本語言,和shell類似,但是相對複雜,通常用來寫網站。

二、httpd、PHP、MySQL三者連接關係

針對apapche、mysql、php三個角色,它們可以部署在同一臺機器上,也可以單獨部署mysql,但是httpd和php要部署在同一臺機器上(爲什麼?)

LAMP架構部署詳解

apache和php視爲一個整體,因爲php是以一個模塊(PHP module)和apapche相互進行數據交互的,也就是說apahce不能直接和mysql進行數據交互,只能通過php module模塊向mysql取數據,然後再返回給apache ,最終再返回用戶發出的訪問請求。

注意:

PHP modle向mysql取數據的過程,我們稱爲動態請求,比如我們訪問知乎網站時,在瀏覽器上輸入賬號密碼,然後交給apache,apache拿到用戶輸入的賬號密碼後,通過PHP Module把數據傳遞給mysql進行一個比較驗證,看看用戶在瀏覽器上輸入賬號密碼和mysql數據中的是否一致,mysql再通過PHP Module返回驗證結果給apapche,如果用戶在瀏覽器輸入正確賬號密碼後就能順利登陸。這個過程就是一個動態請求的過程

如果你是訪問某個網站上圖片(靜態文件),也就是沒有和mysql進行數據交互,這個過程就是靜態請求,需要說明的是mysql裏面不存圖片(靜態文件)

三、靜態頁面和動態頁面知識延伸

1.概念定義

1.1靜態網頁

靜態網頁是標準的HTML文件,它的文件擴展名是.htm或.html,可以包含文本、圖像、聲音、FLASH動畫、客戶端腳本和ActiveX控件及JAVA小程序等。

這種網頁不包含在服務器端運行的任何腳本,網頁上的每一行代碼都是由網頁設計人員預先編寫好後,放置到Web服務器上的,在發送到客戶端的瀏覽器上後不再發生任何變化,因此稱其爲靜態網頁。

靜態網頁的處理流程:

1、當用戶在瀏覽器的‘地址’欄中輸入一個URL地址並單擊‘轉到’按鈕或敲擊鍵盤上的‘回車鍵’後、單擊網頁中的超鏈接後、在瀏覽器菜單欄的‘收藏’選擇一個網址後,瀏覽器將向Web服務器發出一個頁面請求。

2、當Web服務器收到這個頁面請求,根據.htm或.html判斷出這是一個靜態的HTML文件,會從磁盤或存儲器中查找獲取用戶請求的這個頁面。

3、Web服務器找到這個請求文件後,就會把它發送到瀏覽器,瀏覽器對這個返回的HTML文件進行解釋並將結果顯示在瀏覽器中。

1.2 動態網頁

動態頁面是以ASP、PHP、JSP、http://ASP.net、Perl、或CGI等編程語言製作的。 我們經常會看到,在地址欄裏有一些網址特別長,而且還帶有“?”,這樣的鏈接一般是動態鏈接,其所對應的頁面就是動態頁面。

動態頁面具有這些特徵:

動態頁面是以ASP、PHP、JSP、http://ASP.net、Perl、或CGI等編程語言製作的

動態頁面實際上並不是獨立存在於服務器上的網頁文件,只有當用戶請求時服務器才返回一個完整的網頁;動態頁面上的內容存在於數據庫中,根據用戶發出的不同請求,其提供個性化的網頁內容;動態頁面內容不是存在於頁面上,而是在數據庫中,從而大大降低網站維護的工作量;

採用動態網頁技術的網站可以實現更多的功能,如用戶註冊、用戶登錄、在線調查、用戶管理、訂單管理等等;靜態頁面則無法實現這些功能。

動態網頁的處理流程:

1、當用戶在瀏覽器的‘地址'欄中輸入一個URL地址並單擊‘轉到'按鈕或敲擊鍵盤上的‘回車鍵'後、單擊網頁中的超鏈接後、在瀏覽器菜單欄的‘收藏'選擇一個網址後,瀏覽器將向Web服務器發出一個頁面請求。
2、當Web服務器收到這個頁面請求,根據文件擴展名判斷出它是一個動態網頁,會從磁盤或存儲器中查找獲取用戶請求的這個頁面,再將這個頁面傳遞給應用程序服務器。
3、應用程序服務器解釋執行該頁中的腳本代碼,並將結果以靜態網頁的形式保存。
4、應用程序服務器將靜態網頁結果傳遞給Web服務器。

2.區別聯繫

動態網頁和靜態網頁的相同之處:都是ASCII編碼文件,都存在着HTML代碼,都能包含腳本語言代碼,都存放在Web服務器上,都把用戶請求的頁面發送到瀏覽上。

動態網頁和靜態網頁的區別是:動態網頁的文件擴展名不是.htm、.html,而是以.asp、.jsp、.php、.perl、.cgi等形式爲文件後綴;動態網頁中的某些腳本只能在服務器上運行,而靜態網頁不能包含在服務器上運行的任何腳本;當Web服務器收到用戶請求的靜態頁面後,將把查找結果直接發送到瀏覽器,而當Web服務器收到用戶請求的動態頁面後,它將先把這個網頁傳遞給一個稱爲應用服務器擴展的特殊軟件進行處理,然後將處理結果傳送給瀏覽器。

關於靜態頁面和動態頁面的其他文檔資料

https://www.cnblogs.com/bluesungz/p/5955170.html

四、MySQL數據安裝

MySQL數據庫介紹

1、數據庫基礎知識

  • MySQL是一種開放源代碼的關係型數據庫管理系統(RDBMS),MySQL數據庫系統使用最常用的數據庫管理語言–結構化查詢語言(SQL)進行數據庫管理。

  • MySQL在2008年被SUN公司收購,2009年SUN公司被Oracle公司收購。

  • MySQL5.6功能變化較大,MySQL5.7性能上有很大提升

  • Mariadb爲MySQL的一個分支,官方網站:https://mariadb.com, MariaDB主要由SkySQL公司維護,而SkySQL公司團隊是由MySQL原作者等大部分原班人馬組成的。

  • MySQL版本分爲Community社區版、Enterprise企業版、GA(Generally Available)通過版本(通常用於生產環境)、DMR(Development Milestone Release)開發里程碑發佈版、RC(Release Candidate)發行候選版本、Beta開放測試版本、Alpha內部測試版本。

數據庫(Database)是按照數據結構來組織、存儲和管理數據的倉庫,它產生於距今六十多年前,隨着信息技術和市場的發展,特別是二十世紀九十年代以後,數據管理不再僅僅是存儲和管理數據,而轉變成用戶所需要的各種數據管理的方式。數據庫有很多種類型,從最簡單的存儲有各種數據的表格到能夠進行海量數據存儲的大型數據庫系統都在各個方面得到了廣泛的應用。

主流的數據庫有:sqlserver,mysql,Oracle、SQLite、Access、MS SQL Server等,本文主要講述的是mysql

2、數據庫管理的功能

a. 將數據保存到文件或內存

b. 接收特定的命令,然後對文件進行相應的操作

說明:對於數據庫管理系統,無須自己再去創建文件和文件夾,而是直接傳遞 命令給相應軟件,讓其來進行文件操作,他們統稱爲數據庫管理系統(DBMS,Database Management System)

MySQL安裝配置

1. MySQL的幾個常用安裝包方法

a.rpm安裝 ##不能定義安裝路徑,默認就是安裝/usr/目錄下面
b.源碼安裝
c.二進制免編譯安裝 ####不用編譯,可以指定安裝目錄

說明:一般在工作中推薦使用二進制免編譯安裝

2.安裝操作步驟

cd /usr/local/src/   ####指定mysql的安裝目錄,其他目錄也行
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

解壓安裝包

tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz  

移動重命名

mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
cd /usr/local/mysql/
ls
bin  COPYING  data  docs  include  lib  man  mysql-test  README  scripts  share  sql-bench  support-files

創建mysql用戶

useradd mysql

創建存放mysql數據的目錄

[root@localhost mysql]# mkdir /data 
[root@localhost mysql]# ls /data/
[root@localhost mysql]#
[root@localhost mysql]#  ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql

說明:在執行這條命令後,怎麼驗證這條初始化命令是否成功,可以從兩點來確認

1)執行命令後,最後會出現兩個OK

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...2017-11-29 06:16:59 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-29 06:16:59 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-29 06:16:59 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 6626 ...
2017-11-29 06:16:59 6626 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-11-29 06:16:59 6626 [Note] InnoDB: The InnoDB memory heap is disabled
2017-11-29 06:16:59 6626 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-29 06:16:59 6626 [Note] InnoDB: Memory barrier is not used
2017-11-29 06:16:59 6626 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-11-29 06:16:59 6626 [Note] InnoDB: Using Linux native AIO
2017-11-29 06:16:59 6626 [Note] InnoDB: Using CPU crc32 instructions
2017-11-29 06:16:59 6626 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-11-29 06:16:59 6626 [Note] InnoDB: Completed initialization of buffer pool
2017-11-29 06:16:59 6626 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2017-11-29 06:16:59 6626 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2017-11-29 06:16:59 6626 [Note] InnoDB: Database physically writes the file full: wait...
2017-11-29 06:16:59 6626 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2017-11-29 06:17:00 6626 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2017-11-29 06:17:00 6626 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2017-11-29 06:17:00 6626 [Warning] InnoDB: New log files created, LSN=45781
2017-11-29 06:17:00 6626 [Note] InnoDB: Doublewrite buffer not found: creating new
2017-11-29 06:17:00 6626 [Note] InnoDB: Doublewrite buffer created
2017-11-29 06:17:00 6626 [Note] InnoDB: 128 rollback segment(s) are active.
2017-11-29 06:17:00 6626 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-29 06:17:00 6626 [Note] InnoDB: Foreign key constraint system tables created
2017-11-29 06:17:00 6626 [Note] InnoDB: Creating tablespace and datafile system tables.
2017-11-29 06:17:00 6626 [Note] InnoDB: Tablespace and datafile system tables created.
2017-11-29 06:17:00 6626 [Note] InnoDB: Waiting for purge to start
2017-11-29 06:17:00 6626 [Note] InnoDB: 5.6.36 started; log sequence number 0
2017-11-29 06:17:00 6626 [Note] Binlog end
2017-11-29 06:17:00 6626 [Note] InnoDB: FTS optimize thread exiting.
2017-11-29 06:17:00 6626 [Note] InnoDB: Starting shutdown...
2017-11-29 06:17:02 6626 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2017-11-29 06:17:02 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-29 06:17:02 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-29 06:17:02 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 6652 ...
2017-11-29 06:17:02 6652 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-11-29 06:17:02 6652 [Note] InnoDB: The InnoDB memory heap is disabled
2017-11-29 06:17:02 6652 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-29 06:17:02 6652 [Note] InnoDB: Memory barrier is not used
2017-11-29 06:17:02 6652 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-11-29 06:17:02 6652 [Note] InnoDB: Using Linux native AIO
2017-11-29 06:17:02 6652 [Note] InnoDB: Using CPU crc32 instructions
2017-11-29 06:17:02 6652 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-11-29 06:17:02 6652 [Note] InnoDB: Completed initialization of buffer pool
2017-11-29 06:17:02 6652 [Note] InnoDB: Highest supported file format is Barracuda.
2017-11-29 06:17:02 6652 [Note] InnoDB: 128 rollback segment(s) are active.
2017-11-29 06:17:02 6652 [Note] InnoDB: Waiting for purge to start
2017-11-29 06:17:02 6652 [Note] InnoDB: 5.6.36 started; log sequence number 1625977
2017-11-29 06:17:02 6652 [Note] Binlog end
2017-11-29 06:17:02 6652 [Note] InnoDB: FTS optimize thread exiting.
2017-11-29 06:17:02 6652 [Note] InnoDB: Starting shutdown...
2017-11-29 06:17:04 6652 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
  ./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
  cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
  cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as ./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

2) 確認命令是否執行成功的方法

[root@localhost mysql]#  echo $?
0
說明命令初始化成功

3.拷貝mysql配置文件和啓動腳本

[root@localhost mysql]# ls
bin      data  include  man     mysql-test  scripts  sql-bench COPYING  docs  lib      my.cnf  README      share support-files

拷貝mysql啓動配置文件

[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf 

查看/etc/my.cnf 是由哪個rpm安裝的

[root@docker mysql-5.6.36-linux-glibc2.5-x86_64]# rpm -qf /etc/my.cnf
mariadb-libs-5.5.52-1.el7.x86_64

編輯/etc/my.cnf配置文件,修改datadir、socket參數爲

[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock

MySQL數據庫默認啓動腳本爲mysql.server

[root@localhost mysql]# ls support-files/
binary-configure  magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server

[root@localhost mysql]#cp support-files/mysql.server /etc/rc.d/init.d/mysqld

說明:需要把mysql數據庫的啓動腳本mysql.server 配置centos7系統的腳本啓動目錄/etc/rc.d/init.d/mysqld

配置MySQL數據庫啓動腳本參數,編輯support-files/mysql.server,把basedir、datadir參數修改爲

basedir=/usr/local/mysql
datadir=/data/mysql

啓動MySQL數據庫,並驗證進程是否存在

[root@centos7 mysql]# systemctl start mysql
[root@centos7 mysql]# systemctl status mysql
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (running) since Mon 2018-03-19 07:25:05 CST; 9s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 20142 ExecStop=/etc/rc.d/init.d/mysqld stop (code=exited, status=0/SUCCESS)
  Process: 21328 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
   Memory: 436.5M
   CGroup: /system.slice/mysqld.service
           ├─21336 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/centos7.pid
           └─21474 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=...
Mar 19 07:25:03 centos7 systemd[1]: Starting LSB: start and stop MySQL...
Mar 19 07:25:03 centos7 mysqld[21328]: Starting MySQL.Logging to '/data/mysql/centos7.err'.
Mar 19 07:25:05 centos7 mysqld[21328]: . SUCCESS!
Mar 19 07:25:05 centos7 systemd[1]: Started LSB: start and stop MySQL.

查看MySQL進程是否存在

[root@centos7 mysql]# ps aux |grep mysql
root     21336  0.0  0.0 115392  1700 ?        S    07:25   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/centos7.pid
mysql    21474  7.5  0.3 1302864 452224 ?      Sl   07:25   0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/centos7.err --pid-file=/data/mysql/centos7.pid --socket=/tmp/mysql.sock
root     21511  0.0  0.0 112664   968 pts/7    S+   07:25   0:00 grep --color=auto mysql

數據庫3306端口是否被監聽

[root@centos7 mysql]# netstat -nlp |grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      21474/mysqld        
[root@centos7 mysql]#

4、技巧經驗總結

killall和kill命令在日常運維工作中的使用

killall是殺掉所有正在運行的進程,對於正在向MySQL寫數據的時候,如果無法使用kill命令殺掉某個進程,說明此時數據量較大,那麼這樣的情況下,不能使用kill -9 來殺進程,因爲這樣會導致正在寫入磁盤或者緩存(內存)中的數據沒有同步到磁盤,這樣可能會丟掉一些數據,這時候只能用killall。

如果無法kill掉某個服務的進程,說明這個服務的數據量的非常大,只有等服務數據同步完才能殺死進程。

五、Apache安裝、配置

1.下載安裝包

cd /usr/local/src/
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.29.tar.gz
[root@server-1 src]# ll httpd-2.4.29.tar.gz
-rw-r--r--. 1 root root 8638793 Oct 21 03:39 httpd-2.4.29.tar.gz
wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.gz
wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.1.tar.gz

apr和apr-util是一個通用的函數庫,它讓httpd可以不關心底層的操作系統平臺,可以很方便的移植

2.解壓安裝包

tar zxvf  httpd-2.4.9.tar.gz
tar zxvf apr-1.6.3.tar.gz
tar zxvf  apr-util-1.6.1.tar.gz

3.編譯安裝apr

cd apr-1.6.3
./configure --prefix=/usr/local/apr

編譯報錯

[root@server-1 apr-1.6.3]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
Platform: x86_64-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.6.3
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
**configure: error: in `/usr/local/apr-1.6.3':
configure: error: no acceptable C compiler found in $PATH**
See `config.log' for more details
[root@server-1 apr-1.6.3]# echo $?
1

解決辦法:
安裝gcc

[root@server-1 apr-1.6.3]# yum install gcc -y

  [root@server-1 apr-1.6.3]#make && make install

[root@server-1 apr-1.6.3]# echo $?
0

apr編譯安裝完成

4.編譯安裝apr-util

cd /usr/local/src/apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

編譯報錯截圖
LAMP架構部署詳解
LAMP架構部署詳解

解決辦法:
安裝expat庫

yum install expat-devel

安裝完再次

make && make install

報錯解決

5.編譯安裝apache

編譯Apache

cd /usr/local/src/httpd-2.4.29
./configure \
--prefix=/usr/local/apache2.4 \
--with-apr=/usr/local/apr\
--with-apr-util=/usr/local/apr-util \
--enable-so \   ##支持而動態擴展模塊,apache支持以一個動態模塊存在,Apache本身就是一個進程服務
--enable-mods-shared=most

說明:如果在編譯過程中出現,缺少某個依賴包,解決思路
yum list |grep 包
然後安裝devel關鍵字的軟件包
yum install -y 軟件包

編譯安裝

make && make install

編譯安裝報錯

./configure --prefix=/usr/local/apache2.4  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util  --enable-modules=most --enable-so  --enable-rewrite  --with-pcre=/usr/local/pcre --libdir=/usr/lib64
make && make install

報錯截圖
LAMP架構部署詳解

解決辦法:
缺少了xml相關的庫,需要安裝libxml2-devel包。直接安裝並不能解決問題,因爲httpd調用的apr-util已經安裝好了,但是apr-util並沒有libxml2-devel包支持

重新安裝libxml2-devel

yum install -y libxml2-devel

刪除apr-util軟件包

rm -rf /usr/local/src/apr-util-1.6.1
cd /usr/local/src/

重新編譯安裝apr-util

tar zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1/
 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
cd ..
cd httpd-2.4.29/
./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
make && make install
[root@server-1 httpd-2.4.29]# echo $?
0

報錯解決

root@server-1 httpd-2.4.29]# cd /usr/local/apache2.4/
[root@server-1 apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

說明:
bin目錄:命令執行
conf目錄:配置文件所在目錄
htdocs目錄:默認網站訪問的內容就存在這個目錄下
logs日誌目錄:訪問日誌,服務報錯日誌
modules目錄:存放apache需要的模塊

root@server-1 apache2.4]# ls ./modules/
httpd.exp             mod_authz_dbd.so        mod_deflate.so              mod_log_config.so      mod_proxy_scgi.so      mod_socache_memcache.so
mod_access_compat.so  mod_authz_dbm.so        mod_dir.so                  mod_log_debug.so       mod_proxy.so           mod_socache_shmcb.so
mod_actions.so        mod_authz_groupfile.so  mod_dumpio.so               mod_logio.so           mod_proxy_wstunnel.so  mod_speling.so
mod_alias.so          mod_authz_host.so       mod_env.so                  mod_macro.so           mod_ratelimit.so       mod_ssl.so
mod_allowmethods.so   mod_authz_owner.so      mod_expires.so              mod_mime.so            mod_remoteip.so        mod_status.so
mod_auth_basic.so     mod_authz_user.so       mod_ext_filter.so           mod_negotiation.so     mod_reqtimeout.so      mod_substitute.so
mod_auth_digest.so    mod_autoindex.so        mod_file_cache.so           mod_proxy_ajp.so       mod_request.so         mod_unique_id.so
mod_auth_form.so      mod_buffer.so           mod_filter.so               mod_proxy_balancer.so  mod_rewrite.so         mod_unixd.so
mod_authn_anon.so     mod_cache_disk.so       mod_headers.so              mod_proxy_connect.so   mod_sed.so             mod_userdir.so
mod_authn_core.so     mod_cache.so            mod_include.so              mod_proxy_express.so   mod_session_cookie.so  mod_version.so
mod_authn_dbd.so      mod_cache_socache.so    mod_info.so                 mod_proxy_fcgi.so      mod_session_dbd.so     mod_vhost_alias.so
mod_authn_dbm.so      mod_cgid.so             mod_lbmethod_bybusyness.so  mod_proxy_fdpass.so    mod_session.so         mod_watchdog.so
mod_authn_file.so     mod_dav_fs.so           mod_lbmethod_byrequests.so  mod_proxy_ftp.so       mod_setenvif.so
mod_authn_socache.so  mod_dav.so              mod_lbmethod_bytraffic.so   mod_proxy_hcheck.so    mod_slotmem_shm.so
mod_authz_core.so     mod_dbd.so              mod_lbmethod_heartbeat.so   mod_proxy_http.so      mod_socache_dbm.so
[root@server-1 apache2.4]# ls ./htdocs/
index.html
[root@server-1 apache2.4]# ls ./bin/
ab         apxs      dbmmanage  envvars-std  htcacheclean  htdigest  httpd      logresolve
apachectl  checkgid  envvars    fcgistarter  htdbm         htpasswd  httxt2dbm  rotatelogs
[root@server-1 apache2.4]# ls ./logs/
[root@server-1 apache2.4]# ls ./conf/
extra  httpd.conf  magic  mime.types  original

6.查看apache加載的模塊

/usr/local/apache2.4/bin/apachectl

執行上面的命令,實際上是調用

/usr/local/apache2.4/bin/httpd -M
[root@server-1 apache2.4]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.71.11.1. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)

該命令返回的模塊分爲
static:靜態模塊
shared:動態模塊

兩者的區別在於,static模塊是已經編譯安裝到/usr/local/apache2.4/bin/httpd配置文件中,而shared表示apache動態加載的模塊

7.啓動apache服務

[root@server-1 apache2.4]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.71.11.1. Set the 'ServerName' directive globally to suppress this message
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs

從報錯信息得知80端口被tomcat佔用,解決辦法如下

[root@server-1 apache2.4]# netstat -nlp |grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      13427/java          
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      13427/java          
tcp6       0      0 :::8009                 :::*                    LISTEN      13427/java          
unix  2      [ ACC ]     STREAM     LISTENING     3801384  19113/qemu-kvm       /var/lib/libvirt/qemu/domain-25-BasicComServer/monitor.sock
unix  2      [ ACC ]     STREAM     LISTENING     34880    1/systemd            @ISCSID_UIP_ABSTRACT_NAMESPACE
unix  2      [ ACC ]     STREAM     LISTENING     29808    971/gssproxy         /run/gssproxy.sock
unix  2      [ ACC ]     STREAM     LISTENING     3801273  18365/ssh-agent      /tmp/ssh-3zLIq2SWNOcy/agent.18364
unix  2      [ ACC ]     STREAM     LISTENING     28096    1/systemd            /var/run/cups/cups.sock
[root@server-1 apache2.4]# ps aux |grep java
root      2007  0.0  0.0 112664   968 pts/0    S+   06:57   0:00 grep --color=auto java
root     13427  0.0  0.4 38957724 566844 ?     Sl   Feb10  58:26 //bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start

[root@server-1 apache2.4]# kill -9 13427
[root@server-1 apache2.4]# ps aux |grep java
root      2026  0.0  0.0 112664   968 pts/0    S+   06:57   0:00 grep --color=auto java

[root@server-1 apache2.4]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.71.11.1. Set the 'ServerName' directive globally to suppress this message
執行命令後,返回系列信息,不影響, 

8.查看apahce服務進程

[root@server-1 apache2.4]# ps aux |grep httpd
root      2031  0.0  0.0  70900  2192 ?        Ss   06:57   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    2032  0.0  0.0 361948  4260 ?        Sl   06:57   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    2033  0.0  0.0 361948  4260 ?        Sl   06:57   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    2034  0.0  0.0 361948  4256 ?        Sl   06:57   0:00 /usr/local/apache2.4/bin/httpd -k start
root      2120  0.0  0.0 112664   968 pts/0    S+   06:58   0:00 grep --color=auto httpd
[root@server-1 apache2.4]#

服務啓動成功

六、PHP編譯安裝

1.下載安裝包

[root@server-1 src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
--2018-03-26 13:26:44--  http://cn2.php.net/distributions/php-5.6.30.tar.gz
Resolving cn2.php.net (cn2.php.net)... 123.125.23.168, 123.125.23.171, 123.125.23.172, ...
Connecting to cn2.php.net (cn2.php.net)|123.125.23.168|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19274631 (18M) [application/x-gzip]
Saving to: ‘php-5.6.30.tar.gz’

100%[===================================================================================================================>] 19,274,631  1.46MB/s   in 16s    

2018-03-26 13:27:01 (1.16 MB/s) - ‘php-5.6.30.tar.gz’ saved [19274631/19274631]

2.解壓安裝包

[root@server-1 src]# tar zxvf php-5.6.30.tar.gz 

解壓成功

[root@server-1 src]# echo $?
0

3.configure編譯

[root@server-1 src]# tar zxvf php-5.6.30.tar.gz 
[root@server-1 src]# cd php-5.6.30/
[root@server-1 php-5.6.30]#  ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/loca/php/etc --with-mysql=/usr/local/mysql --with-dpo-mysql=/usr/local/mysql --with-mysql=/usr/local/mysql/bin/mysqlc_config  --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir  --with-freetype-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

編譯報錯1

checking whether to enable the SQLite3 extension... yes
checking bundled sqlite3 library... yes
checking for ZLIB support... no
checking if the location of ZLIB install directory is defined... yes
checking for zlib version >= 1.2.0.4... 1.2.7
checking for gzgets in -lz... yes
checking whether to enable bc style precision math functions... no
checking for BZip2 support... yes
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution

解決辦法:

[root@server-1 php-5.6.30]# yum install -y bzip2-devel

編譯報錯2

checking for GD support... yes
checking for the location of libvpx... no
checking for the location of libjpeg... yes
checking for the location of libpng... yes
checking for the location of libXpm... no
checking for FreeType 2... yes
checking for T1lib support... no
checking whether to enable truetype string function in GD... yes
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=<DIR>
configure: error: jpeglib.h not found.

解決辦法:

[root@server-1 php-5.6.30]# yum install -y libjpeg-devel

編譯報錯3

hecking pcre install prefix... no
checking whether to enable FTP support... no
checking OpenSSL dir for FTP... no
checking for GD support... yes
checking for the location of libvpx... no
checking for the location of libjpeg... yes
checking for the location of libpng... yes
checking for the location of libXpm... no
checking for FreeType 2... yes
checking for T1lib support... no
checking whether to enable truetype string function in GD... yes
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.

解決辦法:

[root@server-1 php-5.6.30]# yum install -y libpng-devel

編譯報錯4

checking for GD support... yes
checking for the location of libvpx... no
checking for the location of libjpeg... yes
checking for the location of libpng... yes
checking for the location of libXpm... no
checking for FreeType 2... yes
checking for T1lib support... no
checking whether to enable truetype string function in GD... yes
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
[root@server-1 php-5.6.30]# 

解決辦法:

[root@server-1 php-5.6.30]# yum install -y freetype-devel

編譯報錯5

checking size of long... (cached) 8
checking for an ANSI C-conforming const... yes
checking whether time.h and sys/time.h may both be included... yes
checking for working alloca.h... (cached) yes
checking for alloca... (cached) yes
checking for working memcmp... yes
checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

[root@server-1 php-5.6.30]# yum install -y libmcrypt*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.sohu.com
* updates: mirrors.sohu.com
No package libmcrypt* available.
Error: Nothing to do

解決辦法:
把epel-release卸載掉,重新安裝epel-release
[root@server-1 php-5.6.30]# yum install libmcrypt libmcrypt-devel mcrypt mhash

編譯報錯6

checking for mcrypt_module_open in -lmcrypt... no
checking for mcrypt_module_open in -lmcrypt... yes
checking for MSSQL support via FreeTDS... no
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
configure: error: Cannot find MySQL header files under /usr/local/mysql/bin/mysqlc_config.
Note that the MySQL client library is not bundled anymore!

解決辦法:
編譯安裝的配置文件參數寫錯,正確的如下

 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/loca/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config  --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir  --with-freetype-dir --with-icony-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

編譯成功的返回

Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --with-icony-dir

4.安裝

make && make install 

LAMP架構部署詳解

5.查看PHP加載的模塊

[root@server-1 php-5.6.30]# ls /usr/local/apache2.4/modules/libphp5.so 
/usr/local/apache2.4/modules/libphp5.so
[root@server-1 php-5.6.30]# /usr/local/php/bin/p
pear        peardev     pecl        phar        phar.phar   php         php-cgi     php-config  phpize      
[root@server-1 php-5.6.30]# /usr/local/php/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

說明:php加載的模塊全部是靜態的

關鍵參數說明

[root@server-1 php-5.6.30]# cp php
php5.spec            php5.spec.in         php.gif              php.ini-development  php.ini-production   

php.ini-development 和php.ini-production都是PHP的主配置文件,開發環境用php.ini-development ,生產環境用php.ini-production

6.配置php啓動

[root@server-1 php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini

7.查看PHP的版本關鍵信息

[root@server-1 php-5.6.30]# /usr/local/php/bin/php -i |less
phpinfo()
PHP Version => 5.6.30

System => Linux server-1 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date => Mar 26 2018 14:35:31
Configure Command =>  './configure'  '--prefix=/usr/local/php' '--with-apxs2=/usr/local/apache2.4/bin/apxs' '--with-config-file-path=/usr/loca/php/etc' '--with-mysql=/usr/local/mysql' '--with-pdo-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-libxml-dir' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--with-icony-dir' '--with-zlib-dir' '--with-bz2' '--with-openssl' '--with-mcrypt' '--enable-soap' '--enable-gd-native-ttf' '--enable-mbstring' '--enable-sockets' '--enable-exif'
Server API => Command Line Interface
Virtual Directory Support => enabled
Configuration File (php.ini) Path => /usr/loca/php/etc
Loaded Configuration File => (none)
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
PHP API => 20131106
PHP Extension => 20131226
Zend Extension => 220131226
Zend Extension Build => API220131226,TS
PHP Extension Build => API20131226,TS
Debug Build => no
Thread Safety => enabled
Zend Signal Handling => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => provided by mbstring
IPv6 Support => enabled
DTrace Support => disabled

Registered PHP Streams => https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar
:

PHP5配置完成

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章