LAMP组合的编译安装:
httpd+php
modules:把php编译成httpd的DSO对象:
prefor:libphp5
event, worker:libphp5-zts
cgi
fpm(fastcgi):php作为独立的服务
httpd对fastcgi协议的支持
httpd-2.2:需要额外安装fcgi模块;
httpd-2.4:自带fcgi模块;
安装次序:
httpd, MariaDB, php
编译成httpd2.4
# yum groupinstall "Development tools" "Server Platform Development" -y
# yum install lftp -y
# lftp http://archive.apache.org/dist/apr/?C=S;O=A
lftp archive.apache.org:/dist/apr/?C=S> get apr-1.5.0.tar.bz2
lftp archive.apache.org:/dist/apr/?C=S> get apr-util-1.5.3.tar.bz2
lftp archive.apache.org:/dist/apr/?C=S> cd ..
lftp archive.apache.org:/dist> cd httpd
lftp archive.apache.org:/dist/httpd> get httpd-2.4.10.tar.bz2
lftp archive.apache.org:/dist/httpd> bye
# wget -c https://files.phpmyadmin.net/phpMyAdmin/4.4.14.1/phpMyAdmin-4.4.14.1-all-languages.zip
# yum install pcre-devel -y
# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install
# cd ..
# tar 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
# cd ..
# 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
从其它地方拷一个/etc/rc.d/init.d/下拷一个httpd2.2的httpd文件过来,改名为httpd24
#vim httpd24
改以下几项
===========================================================================================
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=/usr/local/appache/bin/httpd
prog=httpd
pidfile=${PIDFILE-/usr/local/apahce/logs/httpd.pid} #这项一定要和你的httpd.conf里的配置一样。
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
===========================================================================================
# chkconfig --add httpd24 #添加启动级别
# chkconfig --list httpd24 #查看启动级另
# hash -r #移除所有缓存
# cd /etc/profile.d/
# vim httpd.sh
===========================================================================================
export PATH=/usr/local/apache/bin:/usr/local/apache/sbin:$PATH
===========================================================================================
# . /etc/profile.d/httpd.sh #重载路径文件
# httpd -t #配置文件检查
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message #这种主机名错误可以不用理
Syntax OK #配置文件正常
# hash #只是查看一些缓存
# service httpd24 start #开启服务
# ss -tunl #查看进程是否在监听端口
# ps aux | grep httpd #查看有几个进程被启用了。
# httpd -M #查看装载的模块
mpm_event_module (shared) #若有这项,代表工作在event模式中。
# cd /etc/httpd24
# vim httpd.conf #编辑主配置文件
安装MariaDB
下载mariadb-5.5.44-linux-x86_64.tar.gz
# lftp http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-5.5.44/bintar-linux-x86_64/
lftp ftp.hosteurope.de:/mirror/archive.mariadb.org/mariadb-5.5.44/bintar-linux-x86_64> get mariadb-5.5.44-linux-x86_64.tar.gz
# tar xf mariadb-5.5.44-linux-x86_64.tar.gz -C /usr/local #解压缩
# mkdir -pv /mydata/data #创建数据存放目录。
# groupadd -r -g 3600 mysql #创建一个系统组名叫mysql,组ID号为3600
# useradd -r -g mysql -u 3600 mysql #创建一个系统用户名也叫mysql,并加入组mysql,UID号也是3600
# chown -R mysql.mysql /mydata/data/ #修改/mydata/data/的属主及属组。
# /usr/local
# ln -sv mariadb-5.5.44-linux-x86_64/ mysql #创建软件链接
# cd mysql
# chown -R root.mysql ./* #把当前文件夹的所有属主改为root,属组为mysql
# ll #查看一下
# scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql #数据库初始化。
# mkdir /etc/mysql #创建配置文件目录
# cp support-files/my-large.cnf /etc/mysql/my.cnf #拷贝配置文件
# vim /etc/mysql/my.cnf
==========================================================================================
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
datadir = /mydata/data #数据存放目录
innodb_file_per_table = on #可以修改InnoDB为独立表空间模式
skip_name-resolve = on #跳过名称反解
==========================================================================================
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld #拷贝启动服务文件到init.d里面
# chkconfig --add mysqld #设置启动级别
# service mysqld start #启动服务
Starting MySQL.. [ OK ]
# ss -tnl #查看进程监听
# /usr/local/mysql/bin/mysql #打开客户mysql
查看是否能连上。
再执行数据库的安全初始化
# /usr/local/mysql/bin/mysql_secure_installation #安全初始化
==================================================================================
Enter current password for root (enter for none): #默认为空密码,敲回车即可
Set root password? [Y/n] Y #是否要给root设密码,是
New password: #输入密码
Re-enter new password: #再输密码
Password updated successfully!
Remove anonymous users? [Y/n]Y #是否删除匿名用户,是
Remove test database and access to it? [Y/n] n #是否删除test数据库,否
Reload privilege tables now? [Y/n] Y #是否重载文件,是
==================================================================================
编译php
# wget -c https://www.php.net/distributions/php-5.4.45.tar.bz2
# tar xf php-5.4.45.tar.bz2
# cd php-5.4.45/
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm #安装epel源
# yum install bzip2-devel.x86_64 -y
# yum install libmcrypt-devel.x86_64 -y
# yum install libxml2-devel -y
# ./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
==========================================================================================================
./configure --prefix=/usr/local/php #默认安装路径
--with-mysql=/usr/local/mysql #说明MySQL的所在路径
--with-openssl #
--with-mysqli=/usr/local/mysql/bin/mysql_config #MySQL另外的一个访问接口(对数据库接口的另一种交互)
--enable-mbstring #开启对多字节字符串支持,中文的话,这项必开。
--with-freetype-dir #支持freetype字体格式
--with-jpeg-dir #直接处理JPG图片
--with-png-dir #直接处理png图片
--with-zlib #压缩库
--with-libxml-dir=/usr #处理xml文档的。
--enable-xml #支持xml
--enable-sockets #能通过sockets通信。
--with-apxs2=/usr/local/apache/bin/apxs ***#把php编译成httpd的模块***
--with-mcrypt #加解密库
--with-config-file-path=/etc #php的配置文件放哪
--with-config-file-scan-dir=/etc/php.d #其它的ini配置文件存放路径
--with-bz2 #支持bz2格式加密
--enable-maintainer-zts ***#编译成zts模块,若http为even或worker,这条必须加上***
=========================================================================================================
# make && make install
编辑apache配置文件httpd.conf,以apache支持php
# cd /etc/httpd24
# vim httpd.conf
====================================================================================
#在原有的AddType ...下面加上这两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
在下面插入index.php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
====================================================================================
在解压的编译目录里找到PHP的配置文件模板,拷到/etc下做为配置文件
# cd /root/php-5.4.45/
# cp php.ini-production /etc/php.ini
# service httpd24 start
# httpd -M #检查PHP是否有装载
php5_module (shared) #有这项代表装载成功
#制作测试页,测试PHP和MySQL
# cd /usr/local/apache/htdocs
# mv index.html index.php
# vim index.php
#里面的内容改为如下
======================================================================================
<?php
$conn=mysql_connect('127.0.0.1','root','');
if ($conn)
echo "OK";
else
echo "not OK";
phpinfo();
?>
======================================================================================
最后测试
# service iptables stop #关闭防火墙
# setenforce 0 #关闭SeLinux
#浏览器访问 http://192.168.31.150
安装phpMyAdmin
# wget https://files.phpmyadmin.net/phpMyAdmin/4.4.14/phpMyAdmin-4.4.14-all-languages.tar.bz2
# tar xf phpMyAdmin-4.4.14.1-all-languages.tar.bz2 -C /usr/local/apache/htdocs/pma
# cd /usr/local/apache/htdocs/pma
# tr -dc a-zA-Z0-9 < /dev/urandom | head -c 30 |xargs
SWM6ZDsvkgdFP36BL9m4P8019GFwHk
# vim config.inc.php
=============================================================================================
把新生成的随机字符串加到这里
$cfg['blowfish_secret'] = 'SWM6ZDsvkgdFP36BL9m4P8019GFwHk'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
=============================================================================================
更改MySQL的密码
# mysql
=============================================================================================
MariaDB [(none)]> use mysql
MariaDB [mysql]> UPDATE user SET password=PASSWORD('P@ss123') WHERE User='root'; #另类改密码方法
MariaDB [mysql]> SELECT User,Host,Password FROM user;
MariaDB [mysql]> DROP USER ''@'localhost' #删除匿名用户
MariaDB [(none)]> FLUSH PRIVILEGES; #以上这种方式修改密码,MySQL是不会重读的,需要FLUSH刷新一下。
MariaDB [(none)]> exit
=============================================================================================
浏览器器访问http://192.168.31.150/pma/ 成功
压力测试
# ab -c 20 -n 1000 http://192.168.31.150/pma/index.php
编译xcache
# wget https://src.fedoraproject.org/repo/pkgs/php-xcache/xcache-3.2.0.tar.gz/md5/8b0a6f27de630c4714ca261480f34cda/xcache-3.2.0.tar.gz
# tar xf xcache-3.2.0.tar.gz
# cd xcache-3.2.0
# /usr/local/php/bin/phpize #xcache需要借助这个工具生成,不然看不到configure
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config #指明PHP的安装目录。
# make & make install
make install 最后会提示xcache.so文件所在路径,复制下来:/usr/local/php/lib/php/extensions/no-debug-zts-20100525/
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d
# vim /etc/php.d/xcache.ini
=================================================================================================
把地址加进去。
;; non-Windows example:
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
xcache.admin.enable_auth = Off
xcache.admin.user = "mOo"
xcache.admin.pass = "md5 encrypted password" #若这里懒得配MD5密码的话,就上面的admin设为Off
==================================================================================================
# killall httpd #估计这里的httpd24的服务有问题是无法reload或
# service httpd24 start #
再做一次压力测试
# ab -c 20 -n 1000 http://192.168.31.150/pma/index.php
明显加快了。
报错:configure: error: xml2-config not found. Please check your libxml2 installation.
安装:# yum install libxml2-devel -y
目前发现的问题是,这个httpd service无法重启和重载
PHP的fpm模式编译
# cd /root
# rm -rf php-5.4.45
# tar xf php-5.4.45.tar.bz2
# cd php-5.4.45
# ./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-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
--prefix=/usr/local/php5 #避免和原安装路径冲突的。
--with-apxs2=/usr/local/apache/bin/apxs #原有这项不能要了,这是编译进模块的。
--enable-fpm #能监听的服务进程程序
--with-config-file-path=/etc/php5/
--with-config-file-scan-dir=/etc/php5.d
# make -j 4 && make install #4线程编译
# cd /etc/httpd24
# cp httpd.conf httpd.conf.mod_bak #配置原有配置文件
为php提供配置文件
# cd /root/php-5.4.45
# mkdir /etc/php5{,.d} #创建两个目录
# cp php.ini-production /etc/php5/php.ini
# 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 --list php-fpm
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# cd /usr/local/php5/etc/
# cp php-fpm.conf.default php-fpm.conf #拷贝配置文件并改名
# vim php-fpm.conf
=============================================================================
listen = 127.0.0.1:9000 #监听在哪个套接字上,如果只有本机,就不用改。0.0.0.0:9000所有主机
pm.max_children = 50 #能同时最多有几个并发子进程。
pm.start_servers = 5 #开始时,启动几个
pm.max_spare_servers = 10 #允许空闲几个
;pid = run/php-fpm.pid #参考
pid = /usr/local/php5/var/run/php-fpm.pid #指去PHP安装的目录下的/var/run/php-fpm.pid
==============================================================================
# service php-fpm start #启动服务
# ss -tunl #查看监听
# ps aux | grep php-fpm #查看进程
启动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
配置虚拟主机支持使用fcgi
在相应的虚拟主机中添加类似如下两行,
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
http://www.magedu.com/admin/index.php
/web/host1/admin/index.php
fcgi://127.0.0.1:9000/web/hosts/admin/index.php
例如:
<VirtualHost *:80>
DocumentRoot "/www/magedu.com"
ServerName magedu.com
ServerAlias www.magedu.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/magedu.com/$1
<Directory "/www/magedu.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
ProxyRequests Off:关闭正向代理
ProxyPassMatch:把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URL,所以这里直接在fcgi://127.0.0.1:9000后指明了这两个参数,其它的参数的传递已经被mod_proxy_fcgi.so进行封闭,不需要手动指定。
# vim httpd.conf
====================================================================================
#在原有的AddType ...下面加上这两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
在下面插入index.php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
#LoadModule php5_module modules/libphp5.so 把原有的modules注释掉。
<VirtualHost *:80>
DocumentRoot /virtual/web1/
ServerName www.test1.com
CustomLog logs/web1_access_log combined
<Directory "/virtual/web1">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
#这个是有php
<VirtualHost *:80>
DocumentRoot /virtual/web2/
ServerName www.test2.com
CustomLog logs/web1_access_log combined
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/virtual/web2/$1
<Directory "/virtual/web2">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
====================================================================================