日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

lamp

發布時間:2024/8/1 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 lamp 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 1. LAMP架構介紹
  • 2. web服務器工作流程
    • 2.1 cgi與fastcgi
    • 2.2 httpd與php結合的方式
    • 2.3 web工作流程
  • 3. lamp平臺構建
    • 3.1 安裝httpd
    • 3.2 安裝mysql
    • 3.3 安裝php
    • 3.4 配置apache
      • 3.4.1 啟用代理模塊
      • 3.4.2 配置虛擬主機
    • 3.5 驗證

1. LAMP架構介紹

lamp,其實就是由Linux+Apache+Mysql/MariaDB+Php/Perl/Python的一組動態網站或者服務器的開源軟件,除Linux外其它各部件本身都是各自獨立的程序,但是因為經常被放在一起使用,擁有了越來越高的兼容度,共同組成了一個強大的Web應用程序平臺。

LAMP指的是Linux(操作系統)、Apache(HTTP服務器)、MySQL(也指MariaDB,數據庫軟件)和PHP(有時也是指Perl或Python)的第一個字母,一般用來建立web應用平臺。

2. web服務器工作流程

在說lamp架構平臺的搭建前,我們先來了解下什么是CGI,什么是FastCGI,什么是…

web服務器的資源分為兩種,靜態資源和動態資源:

  • 靜態資源就是指靜態內容,客戶端從服務器獲得的資源的表現形式與原文件相同。可以簡單的理解為就是直接存儲于文件系統中的資源
  • 動態資源則通常是程序文件,需要在服務器執行之后,將執行的結果返回給客戶端

那么web服務器如何執行程序并將結果返回給客戶端呢?下面通過一張圖來說明一下web服務器如何處理客戶端的請求


如上圖所示:

階段①顯示的是httpd服務器(即apache)和php服務器通過FastCGI協議進行通信,且php作為獨立的服務進程運行

階段②顯示的是php程序和mysql數據庫間通過mysql協議進行通信。php與mysql本沒有什么聯系,但是由Php語言寫成的程序可以與mysql進行數據交互。同理perl和python寫的程序也可以與mysql數據庫進行交互

2.1 cgi與fastcgi

CGI(Common Gateway Interface,通用網關接口),CGI是外部應用程序(CGI程序)與WEB服務器之間的接口標準,是在CGI程序和Web服務器之間傳遞信息的過程。CGI規范允許Web服務器執行外部程序,并將它們的輸出發送給Web瀏覽器,CGI將web的一組簡單的靜態超媒體文檔變成一個完整的新的交互式媒體。
FastCGI(Fast Common Gateway Interface)是CGI的改良版,CGI是通過啟用一個解釋器進程來處理每個請求,耗時且耗資源,而FastCGI則是通過master-worker形式來處理每個請求,即啟動一個master主進程,然后根據配置啟動幾個worker進程,當請求進來時,master會從worker進程中選擇一個去處理請求,這樣就避免了重復的生成和殺死進程帶來的頻繁cpu上下文切換而導致耗時

2.2 httpd與php結合的方式

httpd與php結合的方式有以下三種:

  • modules:php將以httpd的擴展模塊形式存在,需要加載動態資源時,httpd可以直接通過php模塊來加工資源并返回給客戶端

    • httpd prefork:libphp5.so(多進程模型的php)
    • httpd event or worker:libphp5-zts.so(線程模型的php)
  • CGI:httpd需要加載動態資源時,通過CGI與php解釋器聯系,獲得php執行的結果,此時httpd負責與php連接的建立和斷開等

  • FastCGI:利用php-fpm機制,啟動為服務進程,php自行運行為一個服務,https通過socket與php通信

較于CGI方式,FastCGI更為常用,很少有人使用CGI方式來加載動態資源
三種方式的特點:

以CGI方式運行PHP,由于CGI是非常駐內存集,每次Webserver接受客戶端的HTTP請求,然后建立進程執行CGI程序,客戶端的請求被傳遞給CGI程序,CGI執行后結果再返回Webserver。 每次瀏覽頁面都要重復上面的動作,會有非常大的消耗。
以mod_php模式運行PHP,意味著php是作為apache的一個模塊來啟動的,因此只有在apache啟動的時候會加載擴展模塊,在apache運行期間是不會再去讀取和加載擴展模塊的。顯然使用mod_php的方式運行PHP效率比CGI方式更高。
FastCGI方式,使用php-fpm單獨管理php進程池,PHP-FPM簡單可靠的 FastCGI 進程管理器(FastCGI Process Manager),FastCGI是一個常駐型的CGI,可以一直執行,只要激活后,而且還支持分布式運算(使得php程序解釋執行可以單獨交給php服務器),即可以在網站服務器以外的主機上執行并且接受來自其它網站服務器來的請求。而mod_php與fastcgi相比,倆者都有進程池的概念,但是,fastcgi將服務器端動、靜態請求更好的分離。php進程除了問題不會將web服務器也當掉。

2.3 web工作流程

通過上面的圖說明一下web的工作流程:

  • 客戶端通過http協議請求web服務器資源
  • web服務器收到請求后判斷客戶端請求的資源是靜態資源或是動態資源
    • 若是靜態資源則直接從本地文件系統取之返回給客戶端。
    • 否則若為動態資源則通過FastCGI協議與php服務器聯系,通過CGI程序的master進程調度worker進程來執行程序以獲得客戶端請求的動態資源,并將執行的結果通過FastCGI協議返回給httpd服務器,httpd服務器收到php的執行結果后將其封裝為http響應報文響應給客戶端。在執行程序獲取動態資源時若需要獲得數據庫中的資源時,由Php服務器通過mysql協議與MySQL/MariaDB服務器交互,取之而后返回給httpd,httpd將從php服務器收到的執行結果封裝成http響應報文響應給客戶端。

3. lamp平臺構建

環境說明:

系統平臺IP需要安裝的服務
centos8
redhat8
192.168.50.134httpd-2.4
mysql-5.7
php
php-mysql

lamp平臺軟件安裝次序:

  • httpd --> mysql --> php

注意:php要求httpd使用prefork MPM

3.1 安裝httpd

安裝yum源 [root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo [root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo [root@localhost ~]# yum clean all Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. 0 files removed [root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm [root@localhost ~]# sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel* [root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel* [root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# ls CentOS-Base.repo epel.repo redhat.repo epel-modular.repo epel-testing-modular.repo epel-playground.repo epel-testing.repo [root@localhost yum.repos.d]# vi CentOS-Base.repo 將里面的$releasever改成8 [root@localhost yum.repos.d]# vi epel.repo 將里面的$releasever改成8 [root@localhost yum.repos.d]# cd [root@localhost ~]# yum clean all Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. 34 files removed [root@localhost ~]# yum makecache Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. CentOS-8 - Base - mirrors.aliyu 386 kB/s | 2.2 MB 00:05 CentOS-8 - Extras - mirrors.ali 31 kB/s | 8.1 kB 00:00 CentOS-8 - AppStream - mirrors. 741 kB/s | 5.8 MB 00:08 Extra Packages for Enterprise L 168 kB/s | 97 kB 00:00 Extra Packages for Enterprise L 3.0 MB/s | 8.2 MB 00:02 Metadata cache created.安裝開發工具包 [root@localhost ~]# yum groups mark install "Development Tools"創建apache服務的用戶和組 [root@localhost ~]# useradd -r -M -s /sbin/nologin -g apache apache [root@localhost ~]# id apache uid=994(apache) gid=48(apache) groups=48(apache)安裝依賴包 [root@localhost ~]# yum -y install make openssl-devel pcre-devel expat-devel libtool gcc gcc-c++下載和安裝apr以及apr-util [root@localhost ~]# cd /usr/src/ [root@localhost src]# wget http://mirror.bit.edu.cn/apache/apr/apr-1.6.5.tar.gz [root@localhost src]# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz [root@localhost src]# wget https://downloads.apache.org/httpd/httpd-2.4.46.tar.bz2 [root@localhost src]# ls apr-1.6.5.tar.gz apr-util-1.6.1.tar.gz debug httpd-2.4.46.tar.bz2 kernels [root@localhost src]# yum -y install bzip2 [root@localhost src]# tar xf apr-1.6.5.tar.gz [root@localhost src]# tar xf apr-util-1.6.1.tar.gz [root@localhost src]# tar xf httpd-2.4.46.tar.bz2 [root@localhost src]# ls apr-1.6.5 apr-util-1.6.1.tar.gz httpd-2.4.46.tar.bz2 apr-1.6.5.tar.gz debug kernels apr-util-1.6.1 httpd-2.4.46 [root@localhost src]# cd apr-1.6.5 [root@localhost apr-1.6.5]# vim configurecfgfile="${ofile}T"trap "$RM \"$cfgfile\"; exit 1" 1 2 15# $RM "$cfgfile" //將此行加上注釋,或者刪除此行配置,編譯安裝 [root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr [root@localhost apr-1.6.5]# make [root@localhost apr-1.6.5]# make install[root@localhost apr-1.6.5]# cd ../apr-util-1.6.1 [root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@localhost apr-util-1.6.1]# make [root@localhost apr-util-1.6.1]# make install[root@localhost apr-util-1.6.1]# cd ../httpd-2.4.46 [root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/apache \--sysconfdir=/etc/httpd24 \--enable-so \--enable-ssl \--enable-cgi \--enable-rewrite \--with-zlib \--with-pcre \--with-apr=/usr/local/apr \--with-apr-util=/usr/local/apr-util/ \--enable-modules=most \--enable-mpms-shared=all \--with-mpm=prefork [root@localhost httpd-2.4.46]# make [root@localhost httpd-2.4.46]# make install寫環境變量 [root@localhost httpd-2.4.46]# ls /usr/local/apache/ bin cgi-bin htdocs include man modules build error icons logs manual [root@localhost httpd-2.4.46]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh [root@localhost httpd-2.4.46]# source /etc/profile.d/httpd.sh [root@localhost httpd-2.4.46]# cd [root@localhost ~]# which httpd /usr/local/apache/bin/httpd做一個軟連接 [root@localhost ~]# ln -s /usr/local/apache/include /usr/include/apache [root@localhost ~]# ll /usr/include/ ...... lrwxrwxrwx. 1 root root 25 Oct 30 14:42 apache -> /usr/local/apache/include ......查找幫助文檔 [root@localhost ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man_db.conf(在8的版本里不需要做此步驟就可以直接查找幫助文檔) [root@localhost ~]# man httpdHTTPD(8) httpd HTTPD(8)NAMEhttpd - Apache Hypertext Transfer Protocol ServerSYNOPSIShttpd [ -d serverroot ] [ -f config ] [ -C directive ] [-c directive ] [ -D parameter ] [ -e level ] [ -E file ][ -k start|restart|graceful|stop|graceful-stop ] [ -h ] [-l ] [ -L ] [ -S ] [ -t ] [ -v ] [ -V ] [ -X ] [ -M ] [-T ]On Windows systems, the following additional argumentsare available:httpd [ -k install|config|uninstall ] [ -n name ] [ -w ]SUMMARYhttpd is the Apache HyperText Transfer Protocol (HTTP)server program. It is designed to be run as a standalonedaemon process. When used like this it will create a poolof child processes or threads to handle requests.In general, httpd should not be invoked directly, butrather should be invoked via apachectl on Unix-based sys‐tems or as a service on Windows NT, 2000 and XP and as aconsole application on Windows 9x and ME.OPTIONS-d serverrootSet the initial value for the ServerRoot directiveManual page httpd(8) line 1 (press h for help or q to q取消ServerName前面的注釋 [root@localhost ~]# vim /etc/httpd24/httpd.conf ServerName www.example.com:80啟動apache [root@localhost ~]# apachectl start 查看80端口已經起來 [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:*

此時可以訪問網頁

3.2 安裝mysql

安裝依賴包 [root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel創建用戶和組 [root@localhost ~]# useradd -r -M -s /sbin/nologin mysql [root@localhost ~]# id mysql uid=993(mysql) gid=991(mysql) groups=991(mysql)下載二進制格式的mysql軟件包 [root@localhost ~]# ls anaconda-ks.cfg apr-util-1.6.1.tar.gz apr-1.6.5 httpd-2.4.46 apr-1.6.5.tar.gz httpd-2.4.46.tar.bz2 apr-util-1.6.1 mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz解壓軟件至/usr/local/ [root@localhost ~]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@localhost ~]# cd /usr/local/ [root@localhost local]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64 mysql [root@localhost local]# chown -R mysql.mysql mysql [root@localhost local]# ll total 0 drwxr-xr-x. 13 root root 152 Oct 30 14:37 apache drwxr-xr-x. 6 root root 58 Oct 30 14:25 apr drwxr-xr-x. 5 root root 43 Oct 30 14:30 apr-util drwxr-xr-x. 2 root root 6 Aug 12 2018 bin drwxr-xr-x. 2 root root 6 Aug 12 2018 etc drwxr-xr-x. 2 root root 6 Aug 12 2018 games drwxr-xr-x. 2 root root 6 Aug 12 2018 include drwxr-xr-x. 2 root root 6 Aug 12 2018 lib drwxr-xr-x. 2 root root 6 Aug 12 2018 lib64 drwxr-xr-x. 2 root root 6 Aug 12 2018 libexec lrwxrwxrwx. 1 mysql mysql 35 Oct 30 15:11 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64 drwxr-xr-x. 9 7161 31415 129 Jun 2 21:11 mysql-5.7.31-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 Aug 12 2018 sbin drwxr-xr-x. 5 root root 49 Aug 30 14:26 share drwxr-xr-x. 2 root root 6 Aug 12 2018 src添加環境變量 [root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@localhost local]# source /etc/profile.d/mysql.sh [root@localhost local]# cd [root@localhost ~]# which mysql /usr/local/mysql/bin/mysql建立數據存放目錄 [root@localhost ~]# mkdir /opt/data [root@localhost ~]# chown -R mysql.mysql /opt/data初始化數據庫 [root@localhost ~]# mysqld --initialize-insecure --datadir=/opt/data --user=mysql -insecure是不設密碼生成配置文件 此時打開配置文件已有內容,所以我們先把這內容備份,以防后面會用到 [root@localhost ~]# vim /etc/my.cnf# # This group is read both both by the client and the server # use it for options that affect everything # [client-server]# # include all files from the config directory # !includedir /etc/my.cnf.d [root@localhost ~]# mv /etc/my.cnf{,-bak} [root@localhost ~]# ls /etc/my.cnf* /etc/my.cnf-bak/etc/my.cnf.d: client.cnf 此時再寫配置文件 [root@localhost ~]# vim /etc/my.cnf [mysqld] basedir = /usr/local/mysql datadir = /opt/data socket = /tmp/mysql.sock port = 3306 pid-file = /opt/data/mysql.pid user = mysql skip-name-resolve做一個軟連接 [root@localhost ~]# ln -s /usr/local/mysql/include /usr/include/mysql [root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf/usr/local/mysql/lib [root@localhost ~]# ldconfig 重新讀取配置文件配置服務啟動腳本 [root@localhost ~]# cd /usr/local/mysql [root@localhost mysql]# ls bin include LICENSE README support-files docs lib man share [root@localhost mysql]# cd support-files/ [root@localhost support-files]# ls magic mysqld_multi.server mysql-log-rotate mysql.server [root@localhost support-files]# cp mysql.server /etc/init.d/mysqld[root@localhost support-files]# cd [root@localhost ~]# vim /etc/init.d/mysqld basedir=/usr/local/mysql 添加這兩行 datadir=/opt/data啟動mysql [root@localhost ~]# service mysqld start Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.SUCCESS! [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 80 *:3306 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:* 此時登陸Mysql會報錯 [root@localhost ~]# mysql mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory 安裝這個包 [root@localhost ~]# yum -y install libncurses.so.5*修改密碼 [root@localhost ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.31 MySQL Community Server (GPL)Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> set password=password("maqiang123"); Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> quit Bye 使用新密碼登陸 [root@localhost ~]# mysql -uroot -pmaqiang123 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.31 MySQL Community Server (GPL)Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quit Bye

3.3 安裝php

配置yum源 [root@localhost ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm [root@localhost ~]# rpm -Uvh remi-release-7.rpm [root@localhost ~]# yum makecache --enablerepo=remi-php74 因為8的版本里有各種包就不可以忽略 [root@localhost ~]# yum list all|grep php php.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-IDNA_Convert.noarch 0.8.0-14.el8 epel php-adodb.noarch 5.20.6-9.el8 epel php-bcmath.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-cli.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-common.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-dba.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-dbg.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-devel.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-embedded.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-enchant.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-fpm.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-gd.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-gmp.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-intl.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-json.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-ldap.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-mbstring.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-mysqlnd.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-odbc.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-opcache.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-pdo.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-pear.noarch 1:1.10.5-9.module_el8.2.0+313+b04d0a66 AppStream php-pear-Auth-SASL.noarch 1.1.0-6.el8 epel php-pear-Cache-Lite.noarch 1.8.3-1.el8 epel php-pear-Date.noarch 1.4.7-22.el8 epel php-pear-HTTP-Request.noarch 1.4.4-18.el8 epel php-pear-Mail.noarch 1.4.1-6.el8 epel php-pear-Net-SMTP.noarch 1.9.0-1.el8 epel php-pear-Net-Socket.noarch 1.2.2-6.el8 epel php-pear-Net-URL.noarch 1.0.15-20.el8 epel php-pecl-apcu.x86_64 5.1.12-2.module_el8.2.0+313+b04d0a66 AppStream php-pecl-apcu-devel.x86_64 5.1.12-2.module_el8.2.0+313+b04d0a66 AppStream php-pecl-zip.x86_64 1.15.3-1.module_el8.2.0+313+b04d0a66 AppStream php-pgsql.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-process.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-recode.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-snmp.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-soap.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-xml.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-xmlrpc.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream php-xmpphp.noarch 0.1-0.23.rc2.r77.el8 epel sphinx-php.x86_64 2.2.11-15.el8 epel 安裝依賴包 [root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel 安裝php-mysqlnd [root@localhost ~]# yum list all|grep php|grep mysql php-mysqlnd.x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 AppStream [root@localhost ~]# yum -y install php-mysqlnd下載php [root@localhost ~]# cd /usr/src/ [root@localhost src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz [root@localhost ~]# ls anaconda-ks.cfg httpd-2.4.46 apr-1.6.5 httpd-2.4.46.tar.bz2 apr-1.6.5.tar.gz install.sh apr-util-1.6.1 mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz apr-util-1.6.1.tar.gz php-7.2.8.tar.xz編譯安裝php [root@localhost src]# tar xf php-7.2.8.tar.xz [root@localhost src]# cd php-7.2.8 [root@localhost php-7.2.8]# ./configure --prefix=/usr/local/php7 \ --with-config-file-path=/etc \ --enable-fpm \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-soap \ --with-openssl \ --enable-bcmath \ --with-iconv \ --with-bz2 \ --enable-calendar \ --with-curl \ --enable-exif \ --enable-ftp \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-freetype-dir \ --with-gettext \ --enable-json \ --enable-mbstring \ --enable-pdo \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-readline \ --enable-shmop \ --enable-simplexml \ --enable-sockets \ --enable-zip \ --enable-mysqlnd-compression-support \ --with-pear \ --enable-pcntl \ --enable-posix [root@localhost php-7.2.8]# make [root@localhost php-7.2.8]# make install配置環境變量 [root@localhost php-7.2.8]# ls /usr/local/php7/ bin etc include lib php sbin var [root@localhost php-7.2.8]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php.sh [root@localhost php-7.2.8]# source /etc/profile.d/php.sh [root@localhost php-7.2.8]# which php /usr/local/php7/bin/php配置php-fpm [root@localhost php-7.2.8]# which php /usr/local/php7/bin/php [root@localhost php-7.2.8]# cp php.ini-production /etc/php.ini cp: overwrite '/etc/php.ini'? y [root@localhost php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@localhost php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm [root@localhost php-7.2.8]# cd /usr/local/php7/ [root@localhost php7]# ls bin etc include lib php sbin var [root@localhost php7]# cd etc/ [root@localhost etc]# ls pear.conf php-fpm.conf.default php-fpm.d [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf [root@localhost etc]# ls pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d [root@localhost etc]# cd php-fpm.d/ [root@localhost php-fpm.d]# ls www.conf.default [root@localhost php-fpm.d]# cp www.conf.default www.conf [root@localhost php-fpm.d]# ls www.conf www.conf.default編輯php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf) 配置fpm的相關選項為你所需要的值:配置文件最后添加以下四行 [root@localhost ~]# vim /usr/local/php7/etc/php-fpm.conf ..... ..... pm.max_children = 50 ;最多同時提供50個進程提供50個并發服務 pm.start_servers = 5 ;啟動時啟動5個進程 pm.min_spare_servers = 2 ;最小空閑進程數 pm.max_spare_servers = 8 ;最大空閑進程數啟動php-fpm [root@localhost etc]# service php-fpm start Starting php-fpm done [root@localhost etc]# cd [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port 默認情況下,fpm監聽在127.0.0.1的9000端口,也可以使用如下命令驗證其是否已經監聽在相應的套接字 LISTEN 0 128 127.0.0.1:9000 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 80 *:3306 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:*

3.4 配置apache

3.4.1 啟用代理模塊

在apache httpd 2.4以后已經專門有一個模塊針對FastCGI的實現,此模塊為mod_proxy_fcgi.so,它其實是作為mod_proxy.so模塊的擴展,因此,這兩個模塊都要加載,編輯httpd.conf文件,取消以下兩行內容的注釋:

  • LoadModule proxy_module modules/mod_proxy.so
  • LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
進入配置文件,將這兩個注釋取消掉 [root@localhost ~]# vim /etc/httpd24/httpd.conf LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

3.4.2 配置虛擬主機

將這行注釋取消 [root@localhost ~]# vim /etc/httpd24/httpd.conf Include /etc/httpd24/extra/httpd-vhosts.conf

注意:
這里寫的/var/www/html/是yum源安裝方式生成的網頁存放目錄,這里必須改成你編譯安裝指定的網頁存放路徑,禁止直接復制我這里的路徑
這里的idfsoft.com是域名,你必須改成你所使用的域名,禁止直接復制此處的域名
這里的$1表示匹配所有以.php結尾的http請求

在配置文件里添加以下內容 [root@localhost ~]# vim /etc/httpd24/extra/httpd-vhosts.conf <VirtualHost *:80>DocumentRoot "/usr/local/apache/htdocs"ServerName www.example.comServerAlias www.dummy-host.example.comErrorLog "logs/www.example.com-error_log"CustomLog "logs/www.example.com-access_log" commonProxyRequests OffProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1<Directory "/usr/local/apache/htdocs">Require all granted</Directory></VirtualHost>提供網站 [root@localhost ~]# cd /usr/local/apache/htdocs/ [root@localhost htdocs]# ls index.html [root@localhost htdocs]# vim index.php<?phpphpinfo(); ?>修改屬主 [root@localhost htdocs]# cd .. [root@localhost apache]# pwd /usr/local/apache [root@localhost apache]# chown -R apache.apache htdocs/ [root@localhost apache]# ll total 36 drwxr-xr-x. 2 root root 262 Oct 30 14:37 bin drwxr-xr-x. 2 root root 167 Oct 30 14:37 build drwxr-xr-x. 2 root root 78 Oct 30 14:37 cgi-bin drwxr-xr-x. 3 root root 4096 Oct 30 14:37 error drwxr-xr-x. 2 apache apache 41 Oct 30 17:18 htdocs drwxr-xr-x. 3 root root 8192 Oct 30 14:37 icons drwxr-xr-x. 2 root root 4096 Oct 30 14:37 include drwxr-xr-x. 2 root root 58 Oct 30 14:49 logs drwxr-xr-x. 4 root root 30 Oct 30 14:37 man drwxr-xr-x. 14 root root 8192 Oct 30 14:37 manual drwxr-xr-x. 2 root root 4096 Oct 30 14:37 modules[root@localhost ~]# vim /etc/httpd24/httpd.conf //搜索AddType,添加以下內容 ......AddType application/x-compress .ZAddType application/x-gzip .gz .tgzAddType application/x-httpd-php .php #添加此行AddType application/x-httpd-php-source .phps #添加此行//搜索index.htmlDirectoryIndex index.php index.html 添加index.php啟動服務 [root@localhost ~]# apachectl restart [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 127.0.0.1:9000 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 80 *:3306 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:*

3.5 驗證

  • 必須有mysql,說明部署成功

總結

以上是生活随笔為你收集整理的lamp的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日本打白嫩屁股视频 | 日本成人免费 | 男人天堂网址 | 日韩成人福利 | 黄色在线免费看 | 久久乐国产精品 | 伊人青青久 | 国产aⅴ精品一区二区三区久久 | 午夜少妇 | 91精品人妻一区二区三区蜜桃欧美 | 亚洲精品国产精品国自产观看浪潮 | 极品白嫩的小少妇 | 中文字幕免费在线观看视频 | 在线观看第一页 | 日韩黄色av网站 | 在线免费观看日韩 | 久久久高清视频 | 婷婷五月精品中文字幕 | 亚洲第一av | 欧美激情免费观看 | 欧美性三级 | 操三八男人的天堂 | 婷婷视频在线 | 久久丁香网 | 全肉的吸乳文 | 99久视频 | 天天干天天拍 | 美女脱光内衣内裤 | 日日爽天天 | 日本黄动漫 | 日韩精品无码一区二区三区久久久 | 黄网av| 国产国语性生话播放 | 日韩r级电影在线观看 | 性欧美大战久久久久久久久 | 国产艳情片 | 国产情趣视频 | 日本aaa视频 | 喷水视频在线观看 | 4hu最新网址 | 三级黄色在线播放 | 桃色网址 | 春闺艳妇(h)高h产乳 | ktv做爰视频一区二区 | a黄色片 | 特级黄色大片 | 五月天av网 | 少妇久久精品 | 日韩免费在线视频观看 | 精品无码av在线 | 91色站 | a级免费网站 | 男女猛烈无遮挡 | 黄色a区 | 在线精品视频一区 | 亚洲理伦 | 亚洲精品乱码久久久久久自慰 | 少妇人妻一区二区三区 | 国产免费黄色小视频 | 欧美日韩一区二区在线播放 | 日本xxxx裸体xxxx | 蜜臀av性久久久久蜜臀aⅴ麻豆 | 黄频在线 | 中国女人内谢69xxxx免费视频 | 91蜜桃| 天堂av片| 午夜色综合| 午夜欧美成人 | 国产福利小视频在线观看 | 黄色在线观看国产 | 欧美区一区 | 欧美国产日韩一区二区三区 | 天天操天天操天天操天天操天天操 | 国产免费一区二区三区四区五区 | 国产v片在线观看 | 末发成年娇小性xxxxx | 欧美日韩美女 | 一区二区三区黄色片 | 久久综合久久久久 | 欧美激情一区二区三区蜜桃视频 | 国内久久久 | 少妇无内裤下蹲露大唇视频 | 国产欧美一区二区三区另类精品 | 琪琪午夜伦理影院7777 | 久草视频2| 久久看片网 | 丰满少妇xoxoxo视频 | 青青草官网 | 免费一区二区三区四区 | 成人亚洲精品 | 波多野结衣一区二区三区四区 | 色www情| 国产成人无码久久久精品天美传媒 | 女人叫床高潮娇喘声录音mp3 | 黑人巨大精品欧美 | av资源网址 | 涩涩视频在线播放 | 最新视频 - 88av | 欧美二区在线观看 |