在同一主機上基於編譯實現lamp並構建虛擬機使用pma和discuz
目的:
①通過手動編譯方式,在linux系統上安裝apache http2.4,mariadb,php構建lamp;其中php與http的結合方式需要構建兩種:1、php以http模塊方式安裝;2、php以獨立守護進程方式安裝 ;
②在上面構建的lamp基礎上設置兩個虛擬機,分別使用安裝phpMyAdmin和discuz
第一部分:模塊話php安裝lamp
一、準備工作
(一)、查詢有沒有安裝過amp的程序包:
[root@kingdom ~]# rpm -q httpd package httpd is not installed [root@kingdom ~]# rpm -q php package php is not installed [root@kingdom ~]# rpm -q httpd package httpd is not installed [root@kingdom ~]# rpm -q mysql package mysql is not installed
結果是都沒有。
(二)、下載源碼包等文件到本地
[root@kingdom ~]# lftp 172.16.0.1/pub lftp 172.16.0.1:/pub/Sources/sources/httpd> get apr-1.5.0.tar.bz2 apr-util-1.5.3.tar.bz2 httpd-2.4.10.tar.bz2 6541113 bytes transferred Total 3 files transferred lftp 172.16.0.1:/pub/Sources/sources/mariadb> get mariadb-5.5.43-linux-x86_64.tar.gz phpMyAdmin-4.3.5-all-languages.zip 231764570 bytes transferred in 9 seconds (25.62M/s) Total 2 files transferred lftp 172.16.0.1:/pub/Sources/5.i386/LAMP> get Discuz_7.2_FULL_SC_GBK.zip 4636048 bytes transferred lftp 172.16.0.1:/pub/Sources/sources/php> get php-5.4.40.tar.bz2 12272787 bytes transferred lftp 172.16.0.1:/pub/Sources/sources/php> bye [root@kingdom ~]#
(三)、安裝編譯開發工具包組
[root@kingdom ~]# yum install @"Development tools" -y [root@kingdom ~]# yum groupinstall "Server Platform Development" -y
二、基於php模塊化組建lamp
(一)、編譯httpd2.4
httpd2.4 的編譯安裝依賴於pcre-devel開發包和apr1.4+、 apr-util 1.4+的環境,後2者由於教室環境yum安裝是默認1.4以下的,所以都需要手動編譯安裝。
APR(Apache portable Run-time libraries,Apache可移植運行庫)的目的如其名稱一樣,主要爲上層的應用程序提供一個可以跨越多操作系統平臺使用的底層支持接口庫。在早期 的Apache版本中,應用程序本身必須能夠處理各種具體操作系統平臺的細節,並針對不同的平臺調用不同的處理函數。隨着Apache的進一步開 發,Apache組織決定將這些通用的函數獨立出來並發展成爲一個新的項目。這樣,APR的開發就從Apache中獨立出來,Apache僅僅是使用 APR而已。目前APR主要還是由Apache使用,不過由於APR的較好的移植性,因此一些需要進行移植的C程序也開始使用APR,開源項目比如 Flood loader tester(http://httpd.apache.org/test/flood/,該項目用於服務器壓力測試,不僅僅適用於Apache)、
一般情況下,APR開發包很容易理解爲僅僅是一個開發包,不過事實上並不是。目前,完整的APR實際上包含了三個開發包:apr、apr-util以及apr-iconv,每一個開發包分別獨立開發,並擁有自己的版本。
1、編譯httpd2.4需要先安裝開發環境包,pcre-devel:
[root@kingdom ~]# yum install pcre-devel -y
2、編譯安裝apr-1.5.0
[root@kingdom apr-1.5.0]# make && make install 最後出現: /usr/bin/install -c -m 644 apr.exp /usr/local/apr/lib/apr.exp /usr/bin/install -c -m 644 apr.pc /usr/local/apr/lib/pkgconfig/apr-1.pc for f in libtool shlibtool; do \ if test -f ${f}; then /usr/bin/install -c -m 755 ${f} /usr/local/apr/build-1; fi; \ done /usr/bin/install -c -m 755 /root/apr-1.5.0/build/mkdir.sh /usr/local/apr/build-1 for f in make_exports.awk make_var_export.awk; do \ /usr/bin/install -c -m 644 /root/apr-1.5.0/build/${f} /usr/local/apr/build-1; \ done /usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk /usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config [root@kingdom apr-1.5.0]#
3、編譯安裝apr-util-1.5.3
[root@kingdom apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ [root@kingdom apr-util-1.5.3]# make && make install 最後結果是: /usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib /usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
4、編譯安裝httpd2.4
(1)爲httpd24創建特定用戶apache
# groupadd -r apache # useradd -r -g apache apahce [root@kingdom httpd-2.4.10]# id apache uid=48(apache) gid=48(apache) groups=48(apache)
(2)編譯httpd24
# ./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=worker
--enable-so:支持模塊動態裝卸載
--enable-ssl:啓用ssl功能
--enable-rewrite:支持url重寫
--with-zlib:支持調用zlib完成壓縮功能
# make && make install 生成的配置文件地址: Installing configuration files mkdir /etc/httpd24 mkdir /etc/httpd24/extra mkdir /etc/httpd24/original mkdir /etc/httpd24/original/extra Installing HTML documents mkdir /usr/local/apache/htdocs Installing error documents mkdir /usr/local/apache/error Installing icons mkdir /usr/local/apache/icons mkdir /usr/local/apache/logs Installing CGIs mkdir /usr/local/apache/cgi-bin Installing header files mkdir /usr/local/apache/include Installing build system files mkdir /usr/local/apache/build Installing man pages and online manual mkdir /usr/local/apache/man mkdir /usr/local/apache/man/man1 mkdir /usr/local/apache/man/man8 mkdir /usr/local/apache/manual
(3) 啓動服務前的準備工作
將服務腳步添加到系統查找路徑中
[root@kingdom httpd-2.4.10]# which httpd /usr/local/apache/bin/httpd
(4) 啓動服務,並查看安裝結果
(5) 導出頭文件及幫助手冊
(6) 配置SysV服務腳本
編輯/etc/httpd24/httpd.conf,添加如下行即可:
PidFile "/usr/local/apache/logs/httpd.pid"
創建服務腳本文件:
[root@kingdom init.d]# vim /etc/rc.d/init.d/httpd #!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd # config: /etc/httpd24/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /usr/local/apache/logs/httpd.pid # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} -d 10 $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=$? echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else killproc -p ${pidfile} $httpd -HUP RETVAL=$? fi echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f ${pidfile} ] ; then stop start fi ;; reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL
保存退出
爲腳本賦予執行權限:
[root@kingdom init.d]# chmod +x /etc/rc.d/init.d/httpd
加入服務列表:
[root@kingdom init.d]# chkconfig --add httpd [root@kingdom apache]# chkconfig | grep httpd httpd 0:off1:off2:off3:off4:off5:off6:off [root@kingdom apache]# chkconfig httpd on [root@kingdom apache]# chkconfig | grep httpd httpd 0:off1:off2:on3:on4:on5:on6:off
(二)、安裝mariadb-5.5.43-linux-x86_64
1、 創建一個新建一個邏輯卷,並將其掛載至特定目錄
(1)新建一個單獨的邏輯分區作爲mariadb的數據庫存儲位置
[root@kingdom bin]# fdisk /dev/sda Command (m for help): p Disk /dev/sda: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0004edbf Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 7859 62914560 8e Linux LVM n→e→4→→+50G→n→l→→+10G→t→5→8e ———————————————————————————————— Command (m for help): p Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 7859 62914560 8e Linux LVM /dev/sda4 7859 14386 52435161 5 Extended /dev/sda5 7859 9164 10489414+ 8e Linux LVM (邏輯分區sda5準備創建爲mariadb用,10G) Command (m for help): w
兩次partx讓系統重讀分區
[root@kingdom bin]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 [root@kingdom bin]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5
(2) 創建pv——vg——lv:
[root@kingdom bin]# pvcreate /dev/sda5 Physical volume "/dev/sda5" successfully created [root@kingdom bin]# vgcreate myvg /dev/sda5 Volume group "myvg" successfully created [root@kingdom bin]# lvcreate -L 10G -n mylv myvg Logical volume "mylv" created
(3) 格式化邏輯卷
[root@kingdom bin]# mke2fs -t ext4 -L Mariadb -m 4 /dev/myvg/mylv
(4) 掛載:
[root@kingdom bin]# vim /etc/fstab 在末尾添加一行: LABEL="Mariadb" /mydata ext4 defaults 0 0
保存退出
[root@kingdom logs]# mkdir /mydata [root@kingdom bin]# mount -a (掛載所有在/etc/fstab裏的設備) [root@kingdom bin]# mount (查看是否掛載成功) /dev/mapper/vg0-root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) /dev/mapper/vg0-usr on /usr type ext4 (rw) /dev/mapper/vg0-var on /var type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/mapper/myvg-mylv on /mydata type ext4 (rw) ——掛載成功
2、編譯安裝mariadb
(1)新建用戶以安全方式運行進程:
[root@kingdom dev]# mkdir /mydata/data -p [root@kingdom bin]# groupadd -r mysql 創建系統組mysql [root@kingdom bin]# useradd -r -g mysql -s /sbin/nologin -M -d /mydata/data mysql
創建系統用戶mysql,不使用shell,沒有家目錄,默認登錄後的工種作目錄是/mydata/data
[root@kingdom bin]# chown -R mysql:mysql /mydata/data [root@kingdom apache]# ll -d /mydata/data/ drwxr-xr-x 2 mysql mysql 4096 May 2 16:00 /mydata/data/
(2) 安裝並初始化mariadb-5.5.43-linux-x86_64
[root@kingdom ~]# tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local [root@kingdom ~]# cd /usr/local/ [root@kingdom local]# ln -sv mariadb-5.5.43-linux-x86_64/ mysql [root@kingdom local]# cd mysql [root@kingdom mysql]# chown -R mysql:mysql . [root@kingdom mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mydata/data [root@kingdom mysql]# chown -R root . [root@kingdom mysql]# ll total 220 drwxr-xr-x 2 root mysql 4096 May 2 16:04 bin -rw-r--r-- 1 root mysql 17987 Apr 30 02:55 COPYING -rw-r--r-- 1 root mysql 26545 Apr 30 02:55 COPYING.LESSER drwxr-xr-x 3 root mysql 4096 May 2 16:04 data -rw-r--r-- 1 root mysql 8245 Apr 30 02:55 EXCEPTIONS-CLIENT drwxr-xr-x 3 root mysql 4096 May 2 16:04 include -rw-r--r-- 1 root mysql 8694 Apr 30 02:55 INSTALL-BINARY drwxr-xr-x 3 root mysql 4096 May 2 16:04 lib drwxr-xr-x 4 root mysql 4096 May 2 16:04 man drwxr-xr-x 11 root mysql 4096 May 2 16:04 mysql-test -rw-r--r-- 1 root mysql 108813 Apr 30 02:55 README drwxr-xr-x 2 root mysql 4096 May 2 16:04 scripts drwxr-xr-x 27 root mysql 4096 May 2 16:04 share drwxr-xr-x 4 root mysql 4096 May 2 16:04 sql-bench drwxr-xr-x 3 root mysql 4096 May 2 16:04 support-files
(3)爲mariadb提供主配置文件
[root@kingdom mysql]# cd /usr/local/mysql/support-files/ [root@kingdom support-files]# ls binary-configure my-large.cnf mysql-log-rotate magic my-medium.cnf mysql.server my-huge.cnf my-small.cnf SELinux my-innodb-heavy-4G.cnf mysqld_multi.server [root@kingdom support-files]# cp my-large.cnf /etc/my.cnf 並修改此文件中thread_concurrency的值爲CPU個數乘以2: [root@kingdom support-files]# vim /etc/my.cnf thread_concurrency = 2 另外還需要添加如下行指定mysql數據文件的存放位置: datadir = /mydata/data
(4)爲mariadb提供服務腳本
[root@kingdom support-files]# cp mysql.server /etc/rc.d/init.d/mysqld [root@kingdom support-files]# ll /etc/rc.d/init.d/mysqld -rwxr-xr-x 1 root root 12196 May 2 16:23 /etc/rc.d/init.d/mysqld
確保mysqld文件有執行權限,若沒有則用
# chmod +x /etc/rc.d/init.d/mysqld
添加至服務列表:
[root@kingdom support-files]# chkconfig | grep mysqld [root@kingdom support-files]# chkconfig --add mysqld [root@kingdom support-files]# chkconfig | grep mysqld mysqld 0:off1:off2:on3:on4:on5:on6:off
(5) 導出頭文件和man手冊、庫文件
[root@kingdom mysql]# vim /etc/man.config 添加下面這一行 MANPATH /usr/local/mysql/man [root@kingdom mysql]# ln -sv /usr/local/mysql/include/mysql/ /usr/include/mysql
注:前面必須得是絕對路徑,否則無效
[root@kingdom mysql]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf [root@kingdom mysql]# ldconfig [root@kingdom mysql]# vim /etc/profile.d/mysql.sh [root@kingdom mysql]# . /etc/profile.d/mysql.sh [root@kingdom mysql]# which mysqld /usr/local/mysql/bin/mysqld
(三)編譯安裝php-5.4.40
1、yum安裝 bzip2-devel 、libmcrypt-devel及包組Desktop Platform Development
[root@kingdom ~]# yum install @"Desktop Platform Development" [root@kingdom ~]# yum install -y bzip2-devel libmcrypt-devel
(因爲要調用其頭文件和庫文件)
(configure: error: mcrypt.h not found. Please reinstall libmcrypt. # yum whatprovides */*mcrypt.h
(這個會給出你應該安裝哪個程序包)
此處如果忘記安裝,則編譯php時會報錯提醒要求安裝上的。
2、 編譯php
# tar xf php-5.4.40.tar.bz2 # cd php-5.4.40 [root@kingdom php-5.4.40]# ./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
因爲http選的是worker線程模式,所需需要將php編譯成zts模式(--enable-maintainer-zts)
# make && make test && make intall
安裝最後出現如下提示:
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf You may want to add: /usr/local/php/lib/php to your php.ini include_path /root/php-5.4.40/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar Installing PDO headers: /usr/local/php/include/php/ext/pdo/
爲php提供配置文件:
[root@kingdom php-5.4.40]# cp php.ini-production /etc/php.ini
3、 編輯apache配置文件httpd.conf,以apache支持php
(1)、修改主配置文件
[root@kingdom php-5.4.40]# vim /etc/httpd24/httpd.conf 添加如下二行 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 定位至DirectoryIndex index.html 修改爲: DirectoryIndex index.php index.html
(2)、測試apache是否能支持php
重新啓動httpd,或讓其重新載入配置文件即可測試php是否已經可以正常使用。
測試頁面index.php示例如下:
# vim /usr/local/apache/htdocs/index.php <?php $link = mysql_connect('127.0.0.1','root',''); ——因爲剛纔安裝完mysql後沒設root用戶的密碼,所以這裏的密碼留空。 if ($link) echo "Success..."; else echo "Failure..."; mysql_close(); ?>
保存退出
[root@kingdom php-5.4.40]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] [root@kingdom php-5.4.40]# 連接失敗,顯示爲Failure ,見下圖 [root@kingdom php-5.4.40]# service mysqld start Starting MySQL.... [ OK ] [root@kingdom php-5.4.40]# 連接成功,顯示爲Success ,見下圖
(四) 構建虛擬機www.king.com並安裝 pma服務
1、 取消主服務器,啓用虛擬機
[root@kingdom php-5.4.40]# vim /etc/httpd24/httpd.conf
註釋掉(行首前加#號):
#DocumentRoot "/usr/local/apache/htdocs"
啓用虛擬主機:
# Virtual hosts Include /etc/httpd24/extra/httpd-vhosts.conf
2、 構建虛擬主機:
[root@kingdom htdocs]# vim /etc/httpd24/extra/httpd-vhosts.conf
添加如下行,其他的註釋或刪除:
<VirtualHost 172.16.20.150:80> ServerAdmin [email protected] DocumentRoot "/vhost/king.com/htdocs/" ServerName www.king.com ErrorLog "/var/log/httpd24/king.com/king.com-error_log" CustomLog "/var/log/httpd24/king.com/king.com-access_log" common <Directory "/vhost/king.com/htdocs/pma"> ——必須顯式指定可以訪問的目錄,否則默認是禁止訪問的 Options None AllowOverride None Require all granted </Directory> </VirtualHost> 保存退出 [root@kingdom htdocs]# mkdir /var/log/httpd24/king.com/ -p [root@kingdom htdocs]# mkdir /vhost/king.com/htdocs/ -p [root@kingdom htdocs]# httpd -t [root@kingdom htdocs]# service httpd restart
3、安裝pma並調試使用
將文件放置在/vhost/king.com/htdocs/下,解壓並創建一個軟連接pma:
[root@kingdom htdocs]# unzip phpMyAdmin-4.3.5-all-languages.zip [root@kingdom htdocs]# ln -s phpMyAdmin-4.3.5-all-languages pma
修改windows中的hosts文件,添加下面兩行地址解析:
C:\Windows\System32\drivers\etc
172.16.20.150 www.king.com
172.16.20.150 www.dom.com
打開網頁
[root@kingdom htdocs]# mysql MariaDB [(none)]> CREATE DATABASE pmaking; MariaDB [pmaking]> GRANT all ON pmaking.* TO 'king'@'localhost' IDENTIFIED BY 'k123'; Query OK, 0 rows affected (0.00 sec) MariaDB [pmaking]> GRANT all ON pmaking.* TO 'king'@'172.16.20.150' IDENTIFIED BY 'k123'; Query OK, 0 rows affected (0.00 sec) MariaDB [pmaking]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [pmaking]> quit Bye
pma安裝應用成功,可以正常使用了。
(五)構建虛擬機www.dom.com並安裝discuz服務
因爲上一步已經直接取消了主服務器的使用,開啓了虛擬主機,所以這次只需要從添加一個虛擬機開始就可以了
1、構建虛擬主機:
[root@kingdom htdocs]# vim /etc/httpd24/extra/httpd-vhosts.conf 在末尾添加如下行: <VirtualHost 172.16.20.150:80> ServerAdmin [email protected] DocumentRoot "/vhost/dom.com/htdocs/" ServerName www.dom.com ErrorLog "/var/log/httpd24/dom.com/dom.com-error_log" CustomLog "/var/log/httpd24/dom.com/dom.com-access_log" common <Directory "/vhost/dom.com/htdocs/"> Options None AllowOverride None Require all granted </Directory> </VirtualHost> [root@kingdom htdocs]# mkdir /var/log/httpd24/dom.com/ -p [root@kingdom htdocs]# mkdir /vhost/dom.com/htdocs/discuz -p [root@kingdom htdocs]# httpd -t [root@kingdom htdocs]# service httpd restart
2、安裝Discuz並調試使用
打開頁面時,出現瞭如下頁面:
查錯①:
重新修改配置文件
[root@kingdom htdocs]# vim /etc/httpd24/extra/httpd-vhosts.conf <VirtualHost 172.16.20.150:80> ServerAdmin [email protected] DocumentRoot "/vhost/dom.com/htdocs/" ServerName www.dom.com ErrorLog "/var/log/httpd24/dom.com/dom.com-error_log" CustomLog "/var/log/httpd24/dom.com/dom.com-access_log" common <Directory "/vhost/dom.com/htdocs/discuz"> ——並將加壓縮的文件放在這個目錄下結果還是不行;還將這改爲了/vhost/dom.com/htdocs/upload,都不行 Options None AllowOverride None Require all granted </Directory> </VirtualHost>
語法檢查,重啓httpd,但是結果還是隻能正常打開www.king.com/pma,但discuz還是forbidden。
查錯②:
移除配置文件/etc/httpd24/extra/httpd-vhosts.conf,從頭重新創建了一遍,重新解壓縮結果還是一樣。
查錯③:
刪除所有的discuz解壓縮的文件,網站根目錄設置爲 DocumentRoot "/vhost/dom.com/htdocs/",創建文件/vhost/dom.com/htdocs/index.php
# vim /vhost/dom.com/htdocs/index.php 添加如下內容: <?php phpinfo(); ?>
保存退出,語法檢查,重啓httpd,結果能正常顯示php信息頁面:
現象:①www.king.com/pma能正常打開,而僅僅是www.dom.com打不開;② 網頁根目錄下自建的index.php能正常打開,discuz打不開;③其他一切條件都相同。
推測:可能是discuz壓縮包經過壓縮--scp傳到另一個虛擬機--再傳回本虛擬機--解壓縮,壓縮文件已被損壞。
重新下載了一個discuz壓縮包,問題解決,能正常打開。
其他需要的文件如上圖一樣操作即可。
第三步需要先設置好數據庫再填信息點擊下一步:
最終配置結果如下:
具體網站應用可以根據需要自行設置了。
三、基於php 以fpm方式組建lamp
(一)、編譯httpd2.4.10
過程同上,用虛擬機安裝前設置的快照時刻如果是沒有安裝準備部分的開發環境,則需要從頭開始,包括Server Platform Development和Development tools等。
(二)、通用二進制mariadb的安裝初始化
過程同上
(三)、編譯安裝php5.4.40
1、安裝環境準備
①
[root@kingdom ~]# yum install libxml2-devel -y …… Installed: libxml2-devel.x86_64 0:2.7.6-14.el6_5.2 Complete!
②
[root@kingdom ~]# yum install libmcrypt-devel …… Installed: libmcrypt-devel.x86_64 0:2.5.8-9.el6 Dependency Installed: libmcrypt.x86_64 0:2.5.8-9.el6 Complete!
注:libmcrypt-devel.x86_64 0:2.5.8-9.el6安裝包在centos6的安裝包裏是沒有的,需要到epel源的鏡像裏找到並安裝,或者配置要相應的yum源安裝
編譯安裝php-5.4.26
③
[root@kingdom ~]# yum install bzip2-devel -y …… Installed: bzip2-devel.x86_64 0:1.0.5-7.el6_0 Complete!
2、編譯安裝php
首先下載源碼包至本地目錄,下載位置ftp://172.16.0.1/pub/Sources/new_lamp。
[root@kingdom ~]# tar xf php-5.4.26.tar.bz2 [root@kingdom ~]# cd php-5.4.26 [root@kingdom php-5.4.40]# ./configure --prefix=/usr/local/php5 --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 --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
說明:
① 如果使用PHP5.3以上版本,爲了鏈接MySQL數據庫,可以指定mysqlnd,這樣在本機就不需要先安裝MySQL或MySQL開發包了。mysqlnd從php 5.3開始可用,可以編譯時綁定到它(而不用和具體的MySQL客戶端庫綁定形成依賴),但從PHP 5.4開始它就是默認設置了。
# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
因爲本次裝機是在一臺虛擬機上,所以上面的選項不需要使用。
② 如果編譯過程的最後需要仔細查看說的是什麼,有報錯,則看具體是什麼情況。
如是“configure: WARNING: unrecognized options: --with-mcryt”,則表示選項的內容平錯了,改正後重新編譯就可以了
③ 編譯成功完成時最後顯示的內容應該爲:
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/fpm/php-fpm.conf config.status: creating sapi/fpm/init.d.php-fpm config.status: creating sapi/fpm/php-fpm.service config.status: creating sapi/fpm/php-fpm.8 config.status: creating sapi/fpm/status.html 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
[root@kingdom php-5.4.40]# make [root@kingdom php-5.4.40]# make intall
爲php提供配置文件:
[root@kingdom php-5.4.40]# cp php.ini-production /etc/php.ini
3、配置php-fpm
爲php-fpm提供SysV init腳本,並將其添加至服務列表:
[root@kingdom php-5.4.40]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm [root@kingdom php-5.4.40]# chmod +x /etc/rc.d/init.d/php-fpm [root@kingdom php-5.4.40]# chkconfig --add php-fpm [root@kingdom php-5.4.40]# chkconfig php-fpm on
爲php-fpm提供配置文件:
[root@kingdom etc]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
編輯php-fpm的配置文件:
[root@kingdom etc]# vim /usr/local/php/etc/php-fpm.conf 配置fpm的相關選項爲你所需要的值,並啓用pid文件(如下最後一行): error_log = /var/log/php-fpm.log pid = /usr/local/php/var/run/php-fpm.pid pm.max_children = 30 pm.start_servers = 5 pm.min_spare_servers = 2 pm.max_spare_servers = 5
(pm進程設置根據自己硬件設施情況設置)
接下來就可以啓動php-fpm了:
[root@kingdom etc]# service php-fpm start Starting php-fpm done
使用如下命令來驗正(如果此命令輸出中有幾個php-fpm進程就說明啓動成功了):
[root@kingdom etc]# ps aux | grep php root 124846 0.0 0.3 133256 3440 ? Ss 10:15 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) nobody 124847 0.0 0.3 133256 3072 ? S 10:15 0:00 php-fpm: pool www nobody 124848 0.0 0.3 133256 3072 ? S 10:15 0:00 php-fpm: pool www nobody 124849 0.0 0.3 133256 3072 ? S 10:15 0:00 php-fpm: pool www nobody 124850 0.0 0.3 133256 3072 ? S 10:15 0:00 php-fpm: pool www nobody 124851 0.0 0.3 133256 3076 ? S 10:15 0:00 php-fpm: pool www root 124861 0.0 0.0 103252 836 pts/3 S+ 10:17 0:00 grep php
默認情況下,fpm監聽在127.0.0.1的9000端口,也可以使用如下命令驗正其是否已經監聽在相應的套接字。
[root@kingdom etc]# ss -tnlp | grep 9000 LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",124846,7),("php-fpm",124847,0),("php-fpm",124848,0),("php-fpm",124849,0),("php-fpm",124850,0),("php-fpm",124851,0))
4、啓用httpd的相關模塊
在Apache httpd 2.4以後已經專門有一個模塊針對FastCGI的實現,此模塊爲mod_proxy_fcgi.so,它其實是作爲mod_proxy.so模塊的擴充,因此,這兩個模塊都要加載(去掉行首的#號即是)
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
(四)構建虛擬機www.king.com,並配置好pma
1、 取消主服務器,啓用虛擬機
[root@kingdom php-5.4.40]# vim /etc/httpd24/httpd.conf 註釋掉(行首前加#號): #DocumentRoot "/usr/local/apache/htdocs" 啓用虛擬主機: # Virtual hosts Include /etc/httpd24/extra/httpd-vhosts.conf
2、 構建虛擬主機:
[root@kingdom htdocs]# vim /etc/httpd24/extra/httpd-vhosts.conf 添加如下行,其他的註釋或刪除: <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/vhost/king.com/htdocs/" ServerName www.king.com ErrorLog "/var/log/httpd24/king.com-error_log" CustomLog "/var/log/httpd24/king.com-access_log" common ProxyRequests Off <Directory "/vhost/king.com/htdocs/pma"> Options None AllowOverride None Require all granted </Directory> </VirtualHost> [root@kingdom htdocs]# mkdir /var/log/httpd24/ -p [root@kingdom htdocs]# mkdir /vhost/king.com/htdocs/ -p [root@kingdom htdocs]# httpd -t Syntax OK [root@kingdom htdocs]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
3、安裝pma並調試使用
將文件放置在/vhost/king.com/htdocs/下,解壓並創建一個軟連接pma:
[root@kingdom ~]# unzip phpMyAdmin-4.3.5-all-languages.zip -d /vhost/king.com/htdocs/ [root@kingdom ~]# cd /vhost/king.com/htdocs/ [root@kingdom htdocs]# ls phpMyAdmin-4.3.5-all-languages [root@kingdom htdocs]# ln -s /vhost/king.com/htdocs/phpMyAdmin-4.3.5-all-languages/ pma
修改windows中的hosts文件,添加下面兩行地址解析:
C:\Windows\System32\drivers\etc
172.16.20.150 www.king.com
172.16.20.150 www.dom.com
打開網頁
[root@kingdom httpd24]# tail /var/log/httpd24/king.com-error_log [Sat May 09 11:04:29.036690 2015] [autoindex:error] [pid 125713:tid 140225527092992] [client 172.16.250.148:55796] AH01276: Cannot serve directory /vhost/king.com/htdocs/pma/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive
查看日誌,說明是沒有設置好配置文件去識別php,猜想應該是DirectoryIndex沒有設置好
[root@kingdom pma]# vim /etc/httpd24/httpd.conf <IfModule dir_module> DirectoryIndex index.php index.html </IfModule>
保存退出
[root@kingdom pma]# httpd -t Syntax OK [root@kingdom pma]# service httpd reload Reloading httpd:
(五)構建另一臺虛擬機www.dom.com並安裝discuz服務
1、構建虛擬主機:
[root@kingdom htdocs]# vim /etc/httpd24/extra/httpd-vhosts.conf 在末尾添加如下行: <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/vhost/dom.com/htdocs/upload/" ServerName www.dom.com ErrorLog "/var/log/httpd24/dom.com-error_log" CustomLog "/var/log/httpd24/dom.com-access_log" common ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/vhost/dom.com/htdocs/upload/$1 <Directory "/vhost/dom.com/htdocs/upload"> Options None AllowOverride None Require all granted </Directory> </VirtualHost> [root@kingdom htdocs]# mkdir /var/log/httpd24/dom.com/ -p [root@kingdom htdocs]# mkdir /vhost/dom.com/htdocs/discuz -p [root@kingdom htdocs]# httpd -t [root@kingdom htdocs]# service httpd restart
2、安裝Discuz並調試使用
[root@kingdom ~]# unzip Discuz_X3.2_SC_GBK.zip -d /vhost/dom.com/htdocs/
後面的步驟跟前面的一樣。參考前面操作就可以了。