通过编译php为httpd的模块实现lamp
简单罗列基础命令,只分享我的想法!
要求:把php编译成为httpd的模块,实现lamp,并且在httpd上面建立两个虚拟机,一个用于PHPAdmin,另外一个实现discuz。
环境:httpd-2.4.10,apr-1.5.0,apr-until-1.4.1,PHP-5.4.40,mariaDB-5.5.43和CentOS 6.6
一、首先编译httpd
编译2.4版本以上的httpd需要首先安装1.4版本以上的apr和apr-until
1)编译apr-1.5.0,这个软件类似于一个php的“虚拟机”,使用同一种php的代码都可以在上面运行。
./configure--prefix=/usr/local/aprmake&&makeinstall
2)编译apr-until-1.4.1。
./configure--prefix=/usr/local/apr-util–with-apr=/usr/local/apr
make&&makeinstall
3)编译httpd。
如果启用pcre功能,需要安装pcre-devel包。
yuminstallpcre-devel./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
(--enable-so:支持DSO机制,动态装卸载模块;--with-zlib:网上实施压缩的压缩库;--enable-cgi:启动cgi模块,主要用于httpd与php之间的通信;--enable-modules:启用哪些模块;--enable-ssl:支持ssl功能;--enable-mpms-shared:启用共享mpm模块;--with-mpm默认启动的MPM模块;)
httpd的管理命令加入到PATH
vim/etc/profile.d/httpd.shPATH=/usr/local/apache/bin:$PATH./etc/profile.d/httpd.sh
对httpd的include进行处理
ln-sv/usr/local/apache/include//usr/include/httpd
更新man.config
vim/etc/man.config
添加一行
MANPATH/usr/local/apache/man
创建apache用户
useradd-rapache
编译/etc/httpd24/httpd.conf主要配置文件
修改以下两行,把用户变为apache
userapachegroupapache
因为我原来安装过httpd的rpm包,所以,直接复制启动脚本之后进行修改
cp/etc/init.d/httpd/etc/init.d/httpd24vim/etc/init.d/httpd24
修改以下三项即可
apachectl=/usr/local/apache/bin/apachectlhttpd=${HTTPD-/usr/local/apache/bin/httpd}pidfile=${PIDFILE-/var/run/httpd.pid}
检验一下/etc/init.d/httpd24start,看80端口是否启动。
把httpd24添加到服务启动项中
chkconfig--addhttpd24chkconfighttpd24on
httpd服务启动,截图如下。
图1
二、通用二进制格式安装MariaDB-5.4.43
1)有的是空间,直接分区,然后把数据文件放到新的分区中,如果想要充分利用空间,可以做LVM,新分区/dev/sda7,命令如下
pvcreate/dev/sda7vgcreatemyvg/dev/sda7lvcreate-L10G-nmylv2myvg2
格式化
mkfs.ext4/dev/myvg2/mylv2
挂载,然后可以添加到/etc/fstab中,开机自动启动
mount/dev/myvg2/mylv2/mariadb/mydata/mdat
2)解压缩MariaDB的安装包,需要创建一个链接/user/local/mysql指向解压缩后的安装包(因为压缩包中的脚本指向的目录就是/usr/local/mysql)。
ln-sv/root/mariadb-5.5.43-linux-x86_64/usr/local/mysql
mysql的管理命令加入到PATH
vim/etc/profile.d/mysqld.shPATH=/usr/local/mysql/bin:$PATH./etc/profile.d/mysqld.sh
对httpd的include进行处理
ln-sv/usr/local/mysql/include//usr/include/mysqld
更新man.config
vim/etc/man.config
添加一行
MANPATH/usr/local/mysql/man
把函数库添加到系统自动搜索的路径下面
vim/etc/ld.so.conf.d/mysql.conf
添加一行
/usr/local/mysql/lib
编辑完毕,退出,ldconfig,之后可以通过ldconfig-p | grep "/usr/local/mysql"看是否已经加载。
更改安装目录的属主和属组
cd/usr/local/mysqlchown-Rroot:mysql./*
更改存放数据目录的属主和属组
chown-Rmysql:mysql/mariadb/mydata/
安装mysql的配置文件,mysql搜索的配置文件依次是/etc/my.cnf->/etc/mysql/my.cnf->~/.my.cnf
mkdir/etc/mysql
cpsupport-files/my-large.cnf/etc/mysql/my.cnf
初始化数据库到指定的目录
cd/user/local/mysql./scripts/mysql_install_db--user=mysql--datadir=/mariadb/mydata/
编辑/etc/mysql/my.cnf
vim/etc/mysql/my.cnf
添加以下两行
datadir=/mariadb/mydatainnodb_file_per_table=on
根据cpu个数修改以下一行,线程并发个数由来:CPU个数乘以2
thread_concurrency=4
添加启动脚本
cd/usr/local/mysqlcp./support-files/mysql.server/etc/init.d/mysqld43
添加到开机启动的服务中
chkconfig--addmysqld43chkconfigmysqld43on
检验是否启动,截图如下
/etc/init.d/mysqld43start
图2
三、把php-5.4.40编译安装成为httpd的模块,从而实现lamp的组合。
1)安装依赖包(devel子包主要是包含一些include文件)
yuminstalllibxml2-devellibmcrypt-develbzip2-devel–y
2)编译
./configure--prefix=/user/local/php--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-apxs2=/usr/local/apache/bin/apxs--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-zlib--with-libxml-dir=/usr--enable-xml--enable-sockets--with-mcrypt--with-bz2--with-config-file-path=/etc/php/php.ini--with-config-file-scan-dir=/etc/php.d/make&&makeinstall
3)安装主配置文件
mkdir/etc/phpcpphp.ini-production/etc/php/php.ini
四、编辑/etc/httpd24/httpd.conf,支持php
vim/etc/httpd24/httpd.conf
添加以下三行
DirectoryIndexindex.phpindex.htmlAddTypeapplication/x-httpd-php.phpAddTypeapplication/x-httpd-php-source.phps
五、测试php
1)编辑index.php
vim/usr/local/apache/htdocs/index.php<?phpinfo();?>
重新启动httpd24
刷新网页即可,截图如下
图3
图4
六、httpd中创建虚拟机
打开虚拟机配置文件
vim/etc/httpd24/httpd.conf
修改以下一行
Include/etc/httpd24/extra/httpd-vhosts.conf
编辑httpd-vhosts.conf配置文件
vim/etc/httpd24/extra/httpd-vhosts.conf<VirtualHost172.16.49.1:80>#ServerAdminwebmaster@dummy-host.example.comDocumentRoot"/usr/local/apache/vhost1"ServerNamewww.a.com#ServerAliaswww.dummy-host.example.comErrorLog"logs/error_log"CustomLog"logs/access_log"combine<Directory"/usr/local/apache/vhost1">AllowOverrideNoneRequireallgranted</Directory></VirtualHost><VirtualHost172.16.49.1:80>#ServerAdminwebmaster@dummy-host.example.comDocumentRoot"/usr/local/apache/vhost2"ServerNamewww.b.com#ServerAliaswww.dummy-host.example.comErrorLog"logs/error22_log"CustomLog"logs/access22_log"combine<Directory"/usr/local/apache/vhost2">AllowOverrideNoneRequireallgranted</Directory></VirtualHost>
七、phpAdmin配置(省略,上一篇博客有写到),此次实验是通过vhost1显示,只有截图。
图5
八、discuz在vhost2中显示
1)查看README,如下图:
图6
2)修改upload目录中config和data目录的权限
chmod –R 777 config/ data/ uc_client/ uc_server/
3)通过浏览器访问http://www.b.com/upload/install/,如下图
图7
4)继续下一步进行配置
图8
图9
有志同道合的“战友”可以加我qq:865765761。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。