LAMP服务架构
LAMP服務架構
文章目錄
- LAMP服務架構
- 1. LAMP簡介
- 2. LAMP工作原理
- 3. 部署LAMP
- 3.1 源碼安裝http服務
- 3.2 源碼安裝mysql數據庫
- 3.3 源碼安裝php
- 3.2 apache和php配置
1. LAMP簡介
LAMP是指一組通常一起使用來運行動態網站或者服務器的自由軟件名稱首字母縮寫
- L代表服務器操作系統使用Linux
- A代表網站服務使用的是Apache軟件基金會中的httpd軟件
- M代表網站后臺使用的數據庫是MySQL數據庫
- P代表網站是使用PHP/Perl/Python等語言開發
2. LAMP工作原理
當客戶端請求的是靜態資源時,web服務(httpd程序),會直接返回靜態資源給客戶端
當客戶端請求的是動態資源時,apache(httpd程序)會調用libphpX.so模塊進行相應的解析
如果解析處理需要用到后臺數據庫相關數據,此時php程序也會連接后臺數據庫
最終php程序將解析后的結果返回給apache(httpd程序),讓apache返回給客戶端
靜態網頁
- 靜態網頁指使用HTML(超文本標記語言)編寫,一般后綴為.htm,.html等;網頁文件中沒有程序代碼。
- 靜態頁面,用戶雙擊打開,看到的效果與web服務器是相同的,因為網頁的內容在用戶訪問之前就已經確定。
動態網頁
- 動態網頁指網站使用特定的編程語言編寫,網頁文件中除了HTML標記以外,還包括一些實現特定功能的程序代碼。
- 服務端可以根據客戶端的不同請求動態產生網頁內容。
- 動態網頁后綴一般為.php .asp .aspx .cgi .perl .jsp等
- 常見的留言板,論壇,注冊,發帖都是用動態網頁實現的
3. 部署LAMP
3.1 源碼安裝http服務
# 下載解壓包后解壓 [root@localhost ~]# ls anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz [root@localhost ~]# tar -xf apr-1.7.0.tar.gz [root@localhost ~]# tar -xf apr-util-1.6.1.tar.gz [root@localhost ~]# tar -xf httpd-2.4.53.tar.gz # 安裝環境 [root@localhost ~]# dnf -y group mark install "Development Tools" [root@localhost ~]# dnf -y install gcc gcc-c++ openssl-devel pcre-devel expat-devel # 創建用戶 [root@localhost ~]# useradd -r -M -s /sbin/nologin apache # 編譯安裝 [root@localhost ~]# cd apr-1.7.0 [root@localhost apr-1.7.0]# vim configure$RM "$cfgfile" //刪除此行 [root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr [root@localhost apr-1.7.0]# make && make install [root@localhost apr-1.7.0]# cd /root/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 && make install [root@localhost apr-util-1.6.1]# cd /root/httpd-2.4.53 [root@localhost httpd-2.4.53]# ./configure --prefix=/usr/local/apache \ > --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.53]# make && make install # 安裝后配置 [root@localhost httpd-2.4.53]# cd /usr/local/apache/ [root@localhost apache]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh [root@localhost apache]# source /etc/profile.d/apache.sh [root@localhost apache]# cd /usr/lib/systemd/system [root@localhost system]# cp sshd.service httpd.service [root@localhost system]# vim httpd.service [Unit] Description=httpd server daemon After=network.target sshd-keygen.target[Service] Type=forking ExecStart=/usr/local/apache/bin/apachectl start ExecStop=/usr/local/apache/bin/apachectl stop ExecReload=/bin/kill -HUP $MAINPID[Install] WantedBy=multi-user.target [root@localhost system]# systemctl enable --now httpd [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:*
3.2 源碼安裝mysql數據庫
# 安裝5.7yum源和所需的依賴包 [root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm [root@localhost ~]# rpm -ivh mysql80-community-release-el7-5.noarch.rpm [root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo [root@localhost ~]# wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.35-1.el7.x86_64.rpm \ > http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.35-1.el7.x86_64.rpm \ > http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.35-1.el7.x86_64.rpm \ > http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-devel-5.7.35-1.el7.x86_64.rpm \ > http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.35-1.el7.x86_64.rpm # 啟動服務 [root@localhost ~]# systemctl enable --now mysqld [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 80 *:3306 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:* # 查看密碼并進入 [root@localhost ~]# grep 'password' /var/log/mysqld.log 2022-04-21T16:26:14.702813Z 1 [Note] A temporary password is generated for root@localhost: _3(biehY-h!J [root@localhost ~]# mysql -uroot -p'_3(biehY-h!J'3.3 源碼安裝php
所需軟件包網址:https://pkgs.org/
# 下載oniguruma-devel工具包 [root@localhost ~]# dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpmphp官網:php.net
鏈接:https://www.php.net/distributions/php-7.4.29.tar.xz
# 配置安裝環境進行編譯安裝 [root@localhost ~]# dnf -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 sqlite-devel libzip-devel [root@localhost ~]# wget https://www.php.net/distributions/php-7.4.29.tar.xz [root@localhost ~]# tar xf php-7.4.29.tar.xz [root@localhost ~]# cd php-7.4.29 [root@localhost php-7.4.29]# ./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 \ --enable-gd \ --with-jpeg \ --with-zlib-dir \ --with-freetype \ --with-gettext \ --enable-json \ --enable-mbstring \ --enable-pdo \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-readline \ --enable-shmop \ --enable-simplexml \ --enable-sockets \ --with-zip \ --enable-mysqlnd-compression-support \ --with-pear \ --enable-pcntl \ --enable-posix [root@localhost php-7.4.29]# make && make install3.2 apache和php配置
# 配置php [root@localhost php-7.4.29]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh [root@localhost php-7.4.29]# source /etc/profile.d/php7.sh [root@localhost php-7.4.29]# \cp php.ini-production /etc/php.ini [root@localhost php-7.4.29]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@localhost php-7.4.29]# chmod +x /etc/rc.d/init.d/php-fpm [root@localhost php-7.4.29]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf [root@localhost php-7.4.29]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc//php-fpm.d/www.conf [root@localhost php-7.4.29]# service php-fpm start Starting php-fpm done [root@localhost php-7.4.29]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process 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 [::]:* # 配置apache [root@localhost ~]# mkdir /usr/local/apache/htdocs/test.com [root@localhost test.com]# cat > /usr/local/apache/htdocs/test.com/index.php <<EOF <?phpphpinfo(); ?> EOF[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf <VirtualHost *:80>DocumentRoot "/usr/local/apache/htdocs/test.com"ServerName test.example.comProxyRequests OffProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test.com/$1<Directory "/usr/local/apache/htdocs/test.com">Options noneAllowOverride noneRequire all granted</Directory> </VirtualHost>[root@localhost ~]# vim /usr/local/apache/conf/httpd.confAddType application/x-compress .ZAddType application/x-gzip .gz .tgzAddType application/x-httpd-php .php //添加此行AddType application/x-httpd-php-source .phps //添加此行[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf <IfModule dir_module>DirectoryIndex index.php index.html </IfModule> [root@localhost ~]# systemctl restart httpd總結
- 上一篇: 浙江大学黄杨思博计算机学院,浙江大学节能
- 下一篇: java运行vbs_如何在Java中执行