lamp编译
LAMP组合安装:
http+php
modules: 把php编译成httpd的DSO对象;
prefork:libphp
event,worker:libphp5-zts
cgi
fpm:php作为独立的服务
http对fastcgi协议的支持:
http-2.2:需要额外安装fcgi
http-2.4:自带fcgi:
安装次序:
http mariadb php
安装环境centos6.6_x86
安装组件:"Development tools" "Server Platform Development"
安装软件:
1
2
3
http: apr-1.5.2.tar.gz apr-util-1.5.3.tar.bz2 httpd-2.4.10.tar.bz2 pcre依赖包(可yum安装)
mysql: mariadb-5.5.43-linux-x86_64.tar.gz
php: php-5.4.40.tar.bz2 php-mbstring-5.3.3-22.el6.x86_64.rpm xcache-3.2.0.tar.bz2
安装过程:
1
2
3
4
5
6
7
8
[iyunv@centos6 soft]# tar xf apr-1.5.2.tar.gz
[iyunv@centos6 soft]# cd apr-1.5.2
#./configure --prefix=/usr/local/apr
#make && make install
#tat xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
#make && make install
安装httpd
1
2
3
4
5
6
7
8
9
10
11
12
# tar xf httpd-2.4.10.tar.bz2
# cd httpd-2.4.10
# ./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
# make && make install
[iyunv@centos6 apache]# cd /etc/rc.d/init.d/
[iyunv@centos6 init.d]# cp httpd httpd24 #给新安装的httpd做个启动脚本
给httpd24此文件修改项:
apachectl=/usr/local/apachce/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/apachectl}
prog=httpd
pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
配置环境变量:
1
2
3
4
5
6
7
8
#vim /etc/profile.d/httpd.sh
添加内容为:export PATH=/usr/local/apache/bin:$PATH
重读环境变量:./etc/profile.d/httpd.sh
开机启动httpd24:
#checkconfig --add httpd24
# services httpd24 start
#httpd -M #是否有env模型
env_module (shared)
安装MariaDB:
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@centos6 ~]# mkdir -pv /mydata/data
[iyunv@centos6 run]# groupadd -r mysql
[iyunv@centos6 run]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
[iyunv@centos6 soft]# chown -R mysql:mysql /mydata/data/
[iyunv@centos6 soft]# tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/
[iyunv@centos6 soft]# cd /usr/local/
[iyunv@centos6 local]# ln -sv mariadb-5.5.43-linux-x86_64 mysql
[iyunv@centos6 local]# cd mysql
[iyunv@centos6 mysql]# chown -R root:mysql ./*
[iyunv@centos6 mysql]# scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql # 安全初始化
[iyunv@centos6 mysql]# mkdir /etc/mysql
[iyunv@centos6 mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf
编辑配置文件/etc/mysql/my.cnf
添加如下3行
1
2
3
datadir = /mydata/data
innodb_file_per_table = on
skip_name_resolve = on
1
2
3
4
5
6
7
[iyunv@centos6 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld #提供服务脚本
[iyunv@centos6 mysql]# chkconfig --add mysqld
[iyunv@centos6 mysql]# service mysqld start
Starting MySQL.... [ OK ]
[iyunv@centos6 mysql]# /usr/local/mysql/bin/mysql_secure_installation # #生产环境建议禁 止root远程登录
[iyunv@centos6 mysql]# /usr/local/mysql/bin/mysql #数据库的专用客户端
MariaDB [(none)]>
安装php:
解决依赖关系: bzip2-devel libmcrypt-devel
1
2
3
4
5
6
7
[iyunv@centos6 yum.repos.d]# yum -y install bzip2-devel
libmcrypt-devel 需通过epel来安装
[epel]
name=epel
baseurl=http://mirrors.aliyun.com/epel/6/x86_64/
gpgcheck=0
[iyunv@centos6 soft]# tar xf php-5.4.40.tar.bz2
1
2
[iyunv@centos6 soft]# cd php-5.4.40
[iyunv@centos6 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
#安装时,提示有依赖包时,需提前安装
1
[iyunv@centos6 php-5.4.40]# make && make install
注:默认情况下,httpd是不支持phpd的,然后需要配置
在/etc/httpd24/httpd.conf文件中,能找到LoadModule php5_module modules/libphp5.so
既表示以模块编译进来了。
在配置文件 /etc/httpd24/httpd.conf中添加
1
2
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
另外一处修改主页配置
1
2
3
4
5
6
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.php index.html # 添加index.php
</IfModule>
为php添加配置文件:
1
2
3
4
5
[iyunv@centos6 httpd24]# cd /root/soft/php-5.4.40
[iyunv@centos6 php-5.4.40]# cp php.ini-production /etc/php.ini
[iyunv@centos6 php-5.4.40]# http -M #查看是否有php5模块
[iyunv@centos6 apache]# cd /usr/local/apache/htdocs/ #主页文件在此目录
[iyunv@centos6 htdocs]# mv index.html index.php
做个测试界面,是否安装正常 注:做的过程中,忘记关闭iptables selinux 导致界面打不开
1
2
3
4
5
6
7
8
9
[iyunv@centos6 htdocs]# cat index.php
<?php
$conn=mysql_connect('127.0.0.1','root','123');
if ($conn)
echo "OK";
else
echo "false";
phpinfo();
?>
在浏览器输入服务器的IP:显示php的界面表示成功。。。。
安装phpadmin
1
2
3
4
[iyunv@centos6 soft]# unzip phpMyAdmin-4.4.14.1-all-languages.zip
[iyunv@centos6 soft]# cp -a phpMyAdmin-4.4.14.1-all-languages /usr/local/apache/htdocs/
[iyunv@centos6 htdocs]# ls -sv phpMyAdmin-4.4.14.1-all-languages phpadmin
[iyunv@centos6 phpadmin]# cp config.sample.inc.php .config.inc.php
浏览器输入 http://ip/phpadmin
安装xcache 加速php
1
2
3
4
5
6
7
8
9
10
11
[iyunv@centos6 soft]# tar xf xcache-3.2.0.tar.bz2
[iyunv@centos6 soft]# cd xcache-3.2.0
[iyunv@centos6 xcache-3.2.0]# /usr/local/php/bin/phpize
[iyunv@centos6 xcache-3.2.0]# ./configure --enable-xcache --with-php- config =/usr/local/php/bin/php-config
[iyunv@centos6 xcache-3.2.0]# make &&make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts- 20100525/ #对 应的xcache模块的生成目录
[iyunv@centos6 xcache-3.2.0]# ll /usr/local/php/lib/php/extensions/no-debug-zts-2010052 5/
total 580
-rwxr-xr-x. 1 root root 593301 Jul 22 09:38 xcache.so
[iyunv@centos6 xcache-3.2.0]# mkdir /etc/php.d
[iyunv@centos6 xcache-3.2.0]# cp xcache.ini /etc/php.d/
重启httpd24服务;
在浏览器输入http://192.168.1.112 的界面有Xcache 则成功。。。
-------------------------------------------------------------------------------------------
配置apache2.4以fpm方式安装php(软件版本同上)
1
2
3
4
5
6
7
8
[iyunv@centos6 soft]# rm -rf php-5.4.40
[iyunv@centos6 soft]# tar xf php-5.4.40.tar.bz2
[iyunv@centos6 soft]# cd 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/php5 --with-config-file-scan-dir=/etc/php5.d --with-bz2
[iyunv@centos6 php-5.4.40]# service httpd24 stop #突然无法关闭,只能用apachectl stop
[iyunv@centos6 php-5.4.40]# cd /etc/httpd24/
[iyunv@centos6 httpd24]# mv httpd.conf httpd.conf.mod_php
[iyunv@centos6 httpd24]# cp httpd.conf.bak httpd.conf
为php提供配置文件:
1
2
[iyunv@centos6 httpd24]# mkdir /etc/php5{,.d}
[iyunv@centos6 php-5.4.40]# cp php.ini-production /etc/php5/php.ini
配置php-fpm
为php-fpm提供SysV init脚本,并将其添加至服务列表:
1
2
3
4
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
为php-fpm提供配置文件:
1
# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
编辑php-fpm的配置文件:
# vim /usr/local/php5/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):
1
2
3
4
5
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php5/var/run/php-fpm.pid
配置httpd-2.4
启用httpd的相关模块
# cd /etc/httpd24/
在Apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它 其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载
1
2
3
4
5
6
7
8
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
增加两行
AddType application/x-httpd-php .php
AddType application/x-httpd-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
配置虚拟主机支持使用fcgi
在相应的虚拟主机中添加类似如下两行。
1
2
3
4
5
ProxyRequests Off #关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1 #对php的请求转向fpm服 务器
用httpd -M 是否加载了
proxy_module (shared)
proxy_fcgi_module (shared)
#重启httpd24
1
2
3
4
5
[iyunv@centos6 soft]# rm -rf xcache-3.2.0
[iyunv@centos6 soft]# tar xf xcache-3.2.0.tar.bz2
[iyunv@centos6 soft]# cd xcache-3.2.0
[iyunv@centos6 xcache-3.2.0]# /usr/local/php5/bin/php
php php-cgi php-config phpize
1
2
3
4
5
[iyunv@centos6 xcache-3.2.0]# /usr/local/php5/bin/phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
1
2
3
4
5
[iyunv@centos6 xcache-3.2.0]# ./configure --enable-xcache --with-php- config=/usr/local/ php5/bin/php- config
[iyunv@centos6 xcache-3.2.0]# cp xcache.ini /etc/php5.d/
[iyunv@centos6 xcache-3.2.0]# vim /etc/php5.d/xcache.ini
extension = /usr/local/php5/lib/php/extensions/no-debug-non-zts-20100525/xcache.so
[iyunv@centos6 xcache-3.2.0]# service php-fpm restart
浏览器输入http://192.168.1.112 是否有xcache
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com