trsgw 发表于 2015-5-7 08:38:21

通过编译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-until1)编译apr-1.5.0,这个软件类似于一个php的“虚拟机”,使用同一种php的代码都可以在上面运行。
1
2
./configure --prefix=/usr/local/apr
make && make install




2)编译apr-until-1.4.1。
1
./configure --prefix=/usr/local/apr-util –with-apr=/usr/local/apr





1
make && make install




3)编译httpd。如果启用pcre功能,需要安装pcre-devel包。
1
2
yum install pcre-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
1
2
3
vim /etc/profile.d/httpd.sh
PATH=/usr/local/apache/bin:$PATH
. /etc/profile.d/httpd.sh




对httpd的include进行处理
1
ln -sv /usr/local/apache/include/ /usr/include/httpd




更新man.config
1
vim /etc/man.config




添加一行
1
MANPATH /usr/local/apache/man




创建apache用户
1
useradd -r apache




编译/etc/httpd24/httpd.conf主要配置文件修改以下两行,把用户变为apache
1
2
user apache
group apache




因为我原来安装过httpd的rpm包,所以,直接复制启动脚本之后进行修改
1
2
cp /etc/init.d/httpd /etc/init.d/httpd24
vim /etc/init.d/httpd24




修改以下三项即可
1
2
3
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/var/run/httpd.pid}




检验一下/etc/init.d/httpd24start,看80端口是否启动。把httpd24添加到服务启动项中
1
2
chkconfig --add httpd24
chkconfig httpd24 on




httpd服务启动,截图如下。图1二、通用二进制格式安装MariaDB-5.4.431)有的是空间,直接分区,然后把数据文件放到新的分区中,如果想要充分利用空间,可以做LVM,新分区/dev/sda7,命令如下
1
2
3
pvcreate /dev/sda7
vgcreate myvg /dev/sda7
lvcreate -L 10G -n mylv2 myvg2




格式化
1
mkfs.ext4 /dev/myvg2/mylv2




挂载,然后可以添加到/etc/fstab中,开机自动启动
1
mount /dev/myvg2/mylv2 /mariadb/mydata/mdat




2)解压缩MariaDB的安装包,需要创建一个链接/user/local/mysql指向解压缩后的安装包(因为压缩包中的脚本指向的目录就是/usr/local/mysql)。
1
ln -sv /root/mariadb-5.5.43-linux-x86_64 /usr/local/mysql




mysql的管理命令加入到PATH
1
2
3
vim /etc/profile.d/mysqld.sh
PATH=/usr/local/mysql/bin:$PATH
. /etc/profile.d/mysqld.sh




对httpd的include进行处理
1
ln -sv /usr/local/mysql/include/ /usr/include/mysqld




更新man.config
1
vim /etc/man.config




添加一行
1
MANPATH /usr/local/mysql/man




把函数库添加到系统自动搜索的路径下面
1
vim /etc/ld.so.conf.d/mysql.conf




添加一行
1
/usr/local/mysql/lib




编辑完毕,退出,ldconfig,之后可以通过ldconfig-p | grep "/usr/local/mysql"看是否已经加载。更改安装目录的属主和属组
1
2
cd /usr/local/mysql
chown -R root:mysql ./*




更改存放数据目录的属主和属组
1
chown -R mysql:mysql /mariadb/mydata/




安装mysql的配置文件,mysql搜索的配置文件依次是/etc/my.cnf->/etc/mysql/my.cnf->~/.my.cnf
1
mkdir /etc/mysql





1
cp support-files/my-large.cnf /etc/mysql/my.cnf




初始化数据库到指定的目录
1
2
cd /user/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/mariadb/mydata/




编辑/etc/mysql/my.cnf
1
vim /etc/mysql/my.cnf




添加以下两行
1
2
datadir = /mariadb/mydata
innodb_file_per_table = on




根据cpu个数修改以下一行,线程并发个数由来:CPU个数乘以2
1
thread_concurrency = 4




添加启动脚本
1
2
cd/usr/local/mysql
cp ./support-files/mysql.server /etc/init.d/mysqld43




添加到开机启动的服务中
1
2
chkconfig --add mysqld43
chkconfig mysqld43 on




检验是否启动,截图如下
1
/etc/init.d/mysqld43 start




图2三、把php-5.4.40编译安装成为httpd的模块,从而实现lamp的组合。1)安装依赖包(devel子包主要是包含一些include文件)
1
yum install libxml2-devel libmcrypt-devel bzip2-devel –y




2)编译
1
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 && make install




3)安装主配置文件
1
2
mkdir /etc/php
cp php.ini-production /etc/php/php.ini




四、编辑/etc/httpd24/httpd.conf,支持php
1
vim /etc/httpd24/httpd.conf




添加以下三行
1
2
3
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps




五、测试php1)编辑index.php
1
2
3
4
vim /usr/local/apache/htdocs/index.php
<?
         phpinfo();
?>




重新启动httpd24刷新网页即可,截图如下图3图4六、httpd中创建虚拟机打开虚拟机配置文件
1
vim /etc/httpd24/httpd.conf




修改以下一行
1
Include /etc/httpd24/extra/httpd-vhosts.conf




编辑httpd-vhosts.conf配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
vim /etc/httpd24/extra/httpd-vhosts.conf
<VirtualHost 172.16.49.1:80>
    #ServerAdminwebmaster@dummy-host.example.com
    DocumentRoot"/usr/local/apache/vhost1"
    ServerName www.a.com
    #ServerAliaswww.dummy-host.example.com
    ErrorLog"logs/error_log"
    CustomLog"logs/access_log" combine
    <Directory"/usr/local/apache/vhost1">
             AllowOverride None
         Require all granted
    </Directory>
</VirtualHost>
<VirtualHost 172.16.49.1:80>
    #ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot"/usr/local/apache/vhost2"
    ServerName www.b.com
    #ServerAliaswww.dummy-host.example.com
    ErrorLog"logs/error22_log"
    CustomLog"logs/access22_log" combine
    <Directory"/usr/local/apache/vhost2">
             AllowOverride None
         Require all granted
    </Directory>
</VirtualHost>




七、phpAdmin配置(省略,上一篇博客有写到),此次实验是通过vhost1显示,只有截图。图5八、discuz在vhost2中显示1)查看README,如下图:图62)修改upload目录中config和data目录的权限chmod –R 777 config/ data/ uc_client/ uc_server/3)通过浏览器访问http://www.b.com/upload/install/,如下图图74)继续下一步进行配置图8
图9有志同道合的“战友”可以加我qq:865765761。
页: [1]
查看完整版本: 通过编译php为httpd的模块实现lamp