1. 程式人生 > >九、LAMP的安裝與配置

九、LAMP的安裝與配置

lamp安裝、配置

9.1、PHP與httpd的結合工作方式

常見PHP開源軟件:

論壇:phpwind、discuz 、phpbb

博客系統:wordpress

門戶站點:drupal、xooms

數據庫:phpMyAdmin、Workbench、MySQL Front、Navicat for MySQL、Toad

CMS(Content Management System)內容管理系統:Drupal、joomla

PHP與httpd的結合方式:

Module作為模塊,需要時加載:

prefork: 一個請求用一個進程處理,穩定性好、大並發場景下消耗資源較多;事先創建進程,按需維 持適當的進程,模塊塊設計,核心比較小,各種功能都模塊添加(包括php),支持運行配置,支持單獨編譯模塊,支持多種方式的虛擬主機配置。

worker: 一個進程多個線程,一個線程響應一個請求

event: 一個線程響應多個請求,事件驅動,主要目的在於實現單線程響應多個請求

Cgi(Common gateway interface):通用網關接口,為HTTP服務器與其他機器上的程序服務通信的一種交流工具。(CGI程序必須運行在網絡服務器,每次HTTP服務遇到動態程序時都需要成新啟動解析器)

技術分享

Fastcgi,可伸縮的,高速的在HTTP服務器和動態腳本語言間通信的接口,優點是把動態語言和HTTP服務器相分離。其主要行為是將CGI解釋器進程保持在內存中並因此獲得較高的性能。CGI解釋器的反復加載是CGI性能低下的主要原因,如果CGI解釋器保持在內存中並接受FastCGI進程管理器調度,則可以提供良好的性能、伸縮性、Fail- Over特性等等。

LAMP配置順序:httpd --> MySQL --> php --> XCache(緩存器/優化器)

rpm格式配置lamp

# yum -y install httpd php php-mysql mysql-server mysql php-mcrypt

9.2、編譯安裝LAMP

軟件版本:

apacge:httpd-2.4.25.tar.gz

依賴包:apr-1.5.2.tar.gz apr-util-1.5.4.tar.gz

mysql:mysql-5.5.55-linux2.6-x86_64.tar.gz

php: php-5.6.30-src.zip

相關軟件下載:
#wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.25.tar.gz
#wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz
#wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
#wget http://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-5.5/mysql-5.5.55-linux2.6-x86_64.tar.gz
#wget http://cn2.php.net/distributions/php-5.6.30.tar.gz

1、安裝apache

[[email protected] app]# tar xf apr-1.5.2.tar.gz
[[email protected] app]# cd apr-1.5.2
[[email protected] apr-1.5.2]## ./configure --prefix=/usr/local/apr
[[email protected] apr-1.5.2]## make && make install

[[email protected] app]# tar xf apr-util-1.5.4.tar.gz 
[[email protected] app]# cd apr-util-1.5.4
[[email protected] apr-util-1.5.4]./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
[[email protected] apr-util-1.5.4]make && make install

[[email protected] home]#yum install pcre-devel -y

[[email protected] app]# tar xf httpd-2.4.25.tar.gz 
[[email protected] app]# cd httpd-2.4.25
[[email protected] httpd-2.4.25]# ./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=event
[[email protected] httpd-2.4.25]#make && make install
[[email protected] httpd24]# vim /etc/httpd24/httpd.conf     #修改配置文件
   PidFile  "/var/run/httpd.pid"                        #添加該行
   ServerName 127.0.0.1:80                              #修改服務名稱 
   
#提供服務腳本
[[email protected] httpd24]# cp /home/app/httpd-2.4.25/build/rpm/httpd.init /etc/rc.d/init.d/httpd
[[email protected] init.d]# vim /etc/rc.d/init.d/httpd       #修改相關參數
 CONFFILE=/etc/httpd24/httpd.conf
 apachectl=/usr/local/apache/bin/apachectl
 httpd=${HTTPD-/usr/local/apache/bin/httpd}
 pidfile=${PIDFILE-/var/run/${prog}.pid}
 lockfile=${LOCKFILE-/var/lock/subsys/${prog}}
 RETVAL=0
 prog=httpd
 
[[email protected] init.d]# chmod +x /etc/rc.d/init.d/httpd   #為此腳本賦予執行權限
[[email protected] init.d]# chkconfig --add httpd             #加入服務列表
[[email protected] init.d]# service httpd start               #啟動測試
Starting httpd: [  OK  ]

技術分享

2、通用二進制格式安裝MySQL

[[email protected] app]# tar xf mysql-5.5.55-linux2.6-x86_64.tar.gz 
[[email protected] app]# ln -sv /home/app/mysql-5.5.55-linux2.6-x86_64 /usr/local/mysql
`/usr/local/mysql‘ -> `/home/app/mysql-5.5.55-linux2.6-x86_64‘
[[email protected] app]# cd mysql
[[email protected] mysql]# chown -R root:mysql .
[[email protected] mysql]# scripts/mysql_install_db --user=mysql          #初始化
[[email protected] mysql]# cp support-files/my-large.cnf /etc/my.cnf      #提供配置文件
[[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld #服務腳本
[[email protected] mysql]# service mysqld start                           #啟動測試
Starting MySQL.. SUCCESS! 
[[email protected] profile.d]# vim /etc/mysql.sh                          #添加環境變量
[[email protected] profile.d]# source mysql.sh 
[[email protected] profile.d]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.55-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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
[[email protected] profile.d]#

3、安裝PHP

# yum -y groupinstall "Desktop Platform Development"    #解決依賴關系
# yum -y install bzip2-devel libmcrypt-devel
[[email protected] app]# tar xf php-5.6.30.tar.gz
[[email protected] app]# cd php-5.6.30
[[email protected] php-5.6.30]#  ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts
[[email protected] php-5.6.30]# make
[[email protected] php-5.6.30]# make test
[[email protected] php-5.6.30]# make install
[[email protected] php-5.6.30]# cp php.ini-production  /etc/php.ini   #提供配置文件

4、修改apache相關配置

 # vim /etc/httpd/httpd.conf
   AddType application/x-httpd-php  .php           #添加兩行
   AddType application/x-httpd-php-source  .phps
   ...
   <IfModule dir_module>
    DirectoryIndex  index.php index.html           #修改該行
   </IfModule>

5、測試

[[email protected] php-5.6.30]# service httpd restart
Stopping httpd: [  OK  ]
Starting httpd: [  OK  ]
[[email protected] htdocs]# vim /usr/local/apache/htdocs/123.php 
<?php
 $link = mysql_connect(‘127.0.0.1‘);
 if ($link)
   echo "Success...";
 else
   echo "Failure...";
 mysql_close();
?>
[[email protected] htdocs]# vim /usr/local/apache/htdocs/index..php
<?php
phpinfo()
?>

技術分享

技術分享

本文出自 “隨風而飄” 博客,請務必保留此出處http://yinsuifeng.blog.51cto.com/10173491/1932921

九、LAMP的安裝與配置