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"
安装软件:
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
安装过程:
[root@centos6 soft]# tar xf apr-1.5.2.tar.gz [root@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
# 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 [root@centos6 apache]# cd /etc/rc.d/init.d/ [root@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}
配置环境变量:
#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:
[root@centos6 ~]# mkdir -pv /mydata/data [root@centos6 run]# groupadd -r mysql [root@centos6 run]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql [root@centos6 soft]# chown -R mysql:mysql /mydata/data/ [root@centos6 soft]# tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/ [root@centos6 soft]# cd /usr/local/ [root@centos6 local]# ln -sv mariadb-5.5.43-linux-x86_64 mysql [root@centos6 local]# cd mysql [root@centos6 mysql]# chown -R root:mysql ./* [root@centos6 mysql]# scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql # 安全初始化 [root@centos6 mysql]# mkdir /etc/mysql [root@centos6 mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf 编辑配置文件/etc/mysql/my.cnf
添加如下3行
datadir = /mydata/data innodb_file_per_table = on skip_name_resolve = on
[root@centos6 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld #提供服务脚本 [root@centos6 mysql]# chkconfig --add mysqld [root@centos6 mysql]# service mysqld start Starting MySQL.... [ OK ] [root@centos6 mysql]# /usr/local/mysql/bin/mysql_secure_installation # #生产环境建议禁 止root远程登录 [root@centos6 mysql]# /usr/local/mysql/bin/mysql #数据库的专用客户端 MariaDB [(none)]>
安装php:
解决依赖关系: bzip2-devel libmcrypt-devel
[root@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 [root@centos6 soft]# tar xf php-5.4.40.tar.bz2
[root@centos6 soft]# cd php-5.4.40 [root@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
#安装时,提示有依赖包时,需提前安装
[root@centos6 php-5.4.40]# make && make install
注:默认情况下,httpd是不支持phpd的,然后需要配置
在/etc/httpd24/httpd.conf文件中,能找到LoadModule php5_module modules/libphp5.so
既表示以模块编译进来了。
在配置文件 /etc/httpd24/httpd.conf中添加
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
另外一处修改主页配置
# 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添加配置文件:
[root@centos6 httpd24]# cd /root/soft/php-5.4.40 [root@centos6 php-5.4.40]# cp php.ini-production /etc/php.ini [root@centos6 php-5.4.40]# http -M #查看是否有php5模块 [root@centos6 apache]# cd /usr/local/apache/htdocs/ #主页文件在此目录 [root@centos6 htdocs]# mv index.html index.php
做个测试界面,是否安装正常 注:做的过程中,忘记关闭iptables selinux 导致界面打不开
[root@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
[root@centos6 soft]# unzip phpMyAdmin-4.4.14.1-all-languages.zip [root@centos6 soft]# cp -a phpMyAdmin-4.4.14.1-all-languages /usr/local/apache/htdocs/ [root@centos6 htdocs]# ls -sv phpMyAdmin-4.4.14.1-all-languages phpadmin [root@centos6 phpadmin]# cp config.sample.inc.php .config.inc.php
浏览器输入 http://ip/phpadmin
安装xcache 加速php
[root@centos6 soft]# tar xf xcache-3.2.0.tar.bz2 [root@centos6 soft]# cd xcache-3.2.0 [root@centos6 xcache-3.2.0]# /usr/local/php/bin/phpize [root@centos6 xcache-3.2.0]# ./configure --enable-xcache --with-php- config =/usr/local/php/bin/php-config [root@centos6 xcache-3.2.0]# make &&make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts- 20100525/ #对 应的xcache模块的生成目录 [root@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 [root@centos6 xcache-3.2.0]# mkdir /etc/php.d [root@centos6 xcache-3.2.0]# cp xcache.ini /etc/php.d/
重启httpd24服务;
在浏览器输入http://192.168.1.112 的界面有Xcache 则成功。。。
-------------------------------------------------------------------------------------------
配置apache2.4以fpm方式安装php(软件版本同上)
[root@centos6 soft]# rm -rf php-5.4.40 [root@centos6 soft]# tar xf php-5.4.40.tar.bz2 [root@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 [root@centos6 php-5.4.40]# service httpd24 stop #突然无法关闭,只能用apachectl stop [root@centos6 php-5.4.40]# cd /etc/httpd24/ [root@centos6 httpd24]# mv httpd.conf httpd.conf.mod_php [root@centos6 httpd24]# cp httpd.conf.bak httpd.conf
为php提供配置文件:
[root@centos6 httpd24]# mkdir /etc/php5{,.d} [root@centos6 php-5.4.40]# cp php.ini-production /etc/php5/php.ini
配置php-fpm
为php-fpm提供SysV init脚本,并将其添加至服务列表:
# 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提供配置文件:
# 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文件(如下最后一行):
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模块的扩充,因此,这两个模块都要加载
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
在相应的虚拟主机中添加类似如下两行。
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
[root@centos6 soft]# rm -rf xcache-3.2.0 [root@centos6 soft]# tar xf xcache-3.2.0.tar.bz2 [root@centos6 soft]# cd xcache-3.2.0 [root@centos6 xcache-3.2.0]# /usr/local/php5/bin/php php php-cgi php-config phpize
[root@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
[root@centos6 xcache-3.2.0]# ./configure --enable-xcache --with-php- config=/usr/local/ php5/bin/php- config [root@centos6 xcache-3.2.0]# cp xcache.ini /etc/php5.d/ [root@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 [root@centos6 xcache-3.2.0]# service php-fpm restart
浏览器输入http://192.168.1.112是否有xcache