在同一主机上基于编译实现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 webmaster@king.com 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 webmaster@dom.com 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 webmaster@dom.com 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 webmaster@king.com 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 webmaster@dom.com 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/
后面的步骤跟前面的一样。参考前面操作就可以了。
在同一主机上基于编译实现lamp并构建虚拟机使用pma和discuz
原文地址:http://ctrry.blog.51cto.com/9990018/1650007