yangcctv 发表于 2015-8-19 10:50:43

LAMP 和 LNMP(LEMP) 编译安装

一、Apache2.2+PHP5.3(module) + MariaDB5.5
    1.1 编译安装Apache2.2
    1.2 编译安装MariaDB5.5
    1.3 编译安装 PHP-5.3.29
    1.4 mysql测试
二、Apache 2.4+PHP5.4(fpm)+MariaDB5.5
    2.1 编译安装Apache2.4
    2.2 编译安装MariaDB5.5
    2.3 编译安装 PHP-5.4
2.4 mysql 测试
三、nginx1.6+ PHP5.3(fpm)+ MariaDB5.5
    3.1 编译安装nginx1.6
    3.2 编译安装MariaDB5.5
    3.3 编译安装PHP5.3
    3.4 mysql 测试
四、编译安装后的编译参数查询
五、PHP的缓存加速 xcache

六、数据库缓存与优化模块memcache客户端扩展模块安装


基础环境准备
http://www.iyunv.com/kwstars/p/4626598.html


一、Apache2.2+PHP5.3(module) + MariaDB5.5
1.1 编译安装Apache2.2

# 1.1.1 下载Apache2.2
wget http://apache.fayea.com//httpd/httpd-2.2.29.tar.gz

tar xf httpd-2.2.29.tar.gz
cd httpd-2.2.29


# 1.1.2 安装依赖包
yum install zlib-devel openssl-devel pcre-devel -y


# 1.1.3 编译安装

./configure \
--prefix=/application/httpd-2.2.29 \
--enable-so \
--enable-ssl \
--enable-cgi\
--enable-rewrite \
--with-zlib \
--with-pcre\
--enable-modules=most \
--enable-deflate \
--enable-expires \
--enable-headers \
--with-mpm=worker
echo $?

make && make install
echo $?

cd



问题:libtool: install: error: cannot install `libaprutil-1.la' to a directory
http://lxsym.blog.iyunv.com/1364623/739509/



# 1.1.4 创建软连接
ln -s /application/httpd-2.2.29/ /application/httpd



# 1.1.5 启动httpd并测试

/application/httpd/bin/apachectl start

# lsof -i:80
COMMANDPID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   1541   root    4uIPv611067      0t0TCP *:http (LISTEN)
httpd   2148 daemon    4uIPv611067      0t0TCP *:http (LISTEN)
httpd   2149 daemon    4uIPv611067      0t0TCP *:http (LISTEN)
httpd   2151 daemon    4uIPv611067      0t0TCP *:http (LISTEN)
httpd   2232 daemon    4uIPv611067      0t0TCP *:http (LISTEN)




出现以上界面说明httpd工作正常


1.2 编译安装MariaDB5.5

http://www.iyunv.com/kwstars/p/4f82462b7fb8c6106e662ebc6549e0c6.html



# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!



# /application/mariadb/bin/mysql
Welcome to the MariaDB monitor.Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB-log Source distribution


Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


能登陆msyql 说明mysql正常

1.3 编译安装 PHP-5.3.29

1.3.1 安装PHP的一些图形相关的lib库

yum install zlib libxml libjpeg freetype libpng gdcurl libiconvzlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel openssl-devel libxslt-devel -y



1.3.2 安装libiconv 字符编码转换的库


wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
echo $?

make && make install
echo $?

cd


1.3.3 下载php5.3.29
wget http://cn2.php.net/distributions/php-5.3.29.tar.gz

tar xf php-5.3.29.tar.gz
cd php-5.3.29


1.3.4 编译安装php5.3.29
./configure \
--prefix=/application/php-5.3.29 \
--with-apxs2=/application/httpd/bin/apxs \
--with-mysql=/application/mariadb \
--with-xmlrpc \
--with-openssl \
--with-zlib \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-iconv=/usr/local/libiconv \
--enable-short-tags \
--enable-sockets \
--enable-zend-multibyte \
--enable-soap \
--enable-mbstring \
--enable-static \
--enable-gd-native-ttf \
--with-curl \
--with-xsl \
--enable-ftp \

--with-libxml-dir=/usr
echo $?

make -j 4 && make install
echo $?

cd


# 1.3.5 创建软连接

ln -s /application/php-5.3.29/ /application/php


# 1.3.6 提供php配置文件
cp php-5.3.29/php.ini-production /application/php/lib/



查找php配置文件php.ini所在路径的二种方法   

http://www.iyunv.com/article/50406.htm




# 1.3.7 在httpd的主配置文件添加如下2行,用于解析php(如没有一打开就会下载)

# vim /application/httpd/conf/httpd.conf +311
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps


# 1.3.8 在httpd的主配置文件将添加 index.php

# vim /application/httpd/conf/httpd.conf +168
<IfModule dir_module>
    DirectoryIndexindex.php index.html
</IfModule>


# 1.3.9 添加php测试文件

cat > /application/httpd/htdocs/index.php << EOF
<?php
    phpinfo();
?>
EOF


# 1.3.10 重启apache服务
/application/httpd/bin/apachectl restart



# 1.3.11 PHP测试


出现以上界面说明php工作正常

1.4 mysql测试

1.4.1 mysql的测试文件
cat > /application/httpd/htdocs/tm.php << EOF
<?php
    \$conn = mysql_connect('localhost','root','');
    if(\$conn)
      echo "succ";
    else
      echo "failure";
    mysql_close();
?>
EOF


1.4.2 开启mysql测试




1.4.3 关闭mysql测试

# /etc/init.d/mysqld stop
Shutting down MySQL. SUCCESS!



二、Apache 2.4+PHP5.4(fpm)+MariaDB5.5
2.1 编译安装Apache2.4

# 2.1.1 编译安装apr
wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.2.tar.gz


tar xf apr-1.5.2.tar.gz

cd apr-1.5.2
./configure --prefix=/usr/local/apr-1.5.2
echo $?

make && make install
echo $?
cd


# 2.1.2 编译安装apr-util
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.gz


tar xf apr-util-1.5.4.tar.gz

cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util-1.5.4 --with-apr=/usr/local/apr-1.5.2
echo $?

make && make install
echo $?

cd


# 2.1.3下载httpd-2.4.12
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.12.tar.gz


# 2.1.4 安装相关的包
yum install -y pcre-devel zlib-devel openssl-devel



# 2.1.5 编译安装httpd-2.4.12
tar xf httpd-2.4.12.tar.gz


cd httpd-2.4.12

./configure \
--prefix=/application/httpd-2.4.12 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr-1.5.2 \
--with-apr-util=/usr/local/apr-util-1.5.4 \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=event \
--enable-deflate \
--enable-expires
echo $?
make -j 4 && make install
echo $?

cd



# 2.1.6 创建软链接
ln -s/application/httpd-2.4.12/ /application/httpd



# 2.1.7 启动httpd,并测试

/application/httpd/bin/apachectl start




出现以上界面说明httpd服务正常

2.2 编译安装MariaDB5.5


http://www.iyunv.com/kwstars/p/4f82462b7fb8c6106e662ebc6549e0c6.html



# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!



# /application/mariadb/bin/mysql
Welcome to the MariaDB monitor.Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB-log Source distribution


Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


能登陆msyql 说明mysql正常

2.3 编译安装 PHP-5.4

# 2.3.1 安装必要的包
yum install libxml2-devel libmcrypt-devel bzip2-devel libcurl-devellibjpeg-devel libpng-devel freetype-devel libxslt-devel -y
# gd可能需要gd的包


# 2.3.2 编译安装 PHP-5.4.41
wget http://cn2.php.net/distributions/php-5.4.41.tar.gz
tar xf php-5.4.41.tar.gz
cd php-5.4.41


./configure \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--prefix=/application/php-5.4.41 \
--enable-mysqlnd \
--with-openssl \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-sockets \
--with-bz2 \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--with-curlwrappers \
--enable-fpm \
--with-gd \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-zip \
--enable-soap \
--enable-ftp \
--enable-inline-optimization \
--enable-short-tags \
--enable-mbregex \
--enable-xml \
--with-xsl \
--with-xmlrpc \
--with-mhash \
--with-gd \
--with-mcrypt \
--with-curl
echo $?

make -j 4 && make install
echo $?


# 2.3.3 软件软链接

ln -s /application/php-5.4.41/ /application/php



# 2.3.4 在httpd的主配置文件添加如下2行,用于解析php(如没有一打开就会下载)
# vim /application/httpd/conf/httpd.conf +379
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps


# 2.3.5 在httpd的主配置文件添加访问时的主页
# vim /application/httpd/conf/httpd.conf +250


<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>


# 2.3.6 在httpd的主配置文件开启反代模块,fcgi模块模块
# vim /application/httpd/conf/httpd.conf +115

115 LoadModule proxy_module modules/mod_proxy.so

119 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so



# 2.3.7 在httpd的主配置文件添加反代规则

echo 'ProxyRequests Off' >> /application/httpd/conf/httpd.conf
echo 'ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/application/httpd/htdocs/$1' >> /application/httpd/conf/httpd.conf


# 2.3.8 添加php的配置文件

cp php-5.4.41/php.ini-production /application/php/lib/php.ini


# 2.3.9 fcgi的配置文件
cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf



# 2.3.10 fcgi 配置文件测试

/application/php/sbin/php-fpm -t



# 2.3.11 httpd 服务重新reload



/application/httpd/bin/apachectl graceful


# 2.3 12 开启php-fpm



cp php-5.4.41/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
# 或者
# /application/php/sbin/php-fpm
# ss -tnlp
State       Recv-Q Send-Q                   Local Address:Port                     Peer Address:Port
LISTEN      0      128                        127.0.0.1:9000                              *:*      users:(("php-fpm",77934,7),("php-fpm",77935,0),("php-fpm",77936,0))
LISTEN      0      128                                 :::58888                              :::*      users:(("sshd",1113,4))
LISTEN      0      128                                  *:58888                               *:*      users:(("sshd",1113,3))
LISTEN      0      50                                 *:3306                              *:*      users:(("mysqld",58169,14))
LISTEN      0      511                                 :::80                                 :::*      users:(("httpd",37244,4),("httpd",37245,4),("httpd",37246,4),("httpd",37247,4))


# 2.3.13 添加php的测试文件



cat > /application/httpd/htdocs/index.php << EOF
<?php
    phpinfo();
?>
EOF




出现以上界面php工作正常


# 2.3.14 (非必须)



2.4 mysql 测试


cat > /application/httpd/htdocs/tm.php << EOF
<?php
    \$conn = mysql_connect('127.0.0.1','root','');
    if(\$conn)
      echo "succ";
    else
      echo "failure";
    mysql_close();
?>
EOF


经过测试:以上php的编译参数,当连接本地mysql时,需要地址为127.0.0.1,不能用localhost。连接其他主机的mysql也能正常。

三、nginx1.6+ PHP5.3(fpm)+ MariaDB5.5
3.1 编译安装nginx1.6

3.1.1 下载nginx
wget http://nginx.org/download/nginx-1.6.3.tar.gz
tar xf nginx-1.6.3.tar.gz


cd nginx-1.6.3


3.1.2 编译安装nginx
yum install pcre pcre-devel openssl openssl-devel -y


./configure \
--user=nginx \
--group=nginx \
--prefix=/application/nginx-1.6.3 \
--with-http_stub_status_module \
--with-http_ssl_module
echo $?
make -j 2 && make install
echo $?
cd


3.1.3 添加nginx账户

useradd -M -s /sbin/nologin nginx


3.1.4 启动nginx

# /application/nginx/sbin/nginx
# ss -tnl
State       Recv-Q Send-Q                   Local Address:Port                     Peer Address:Port
LISTEN      0      128                                 :::58888                              :::*   
LISTEN      0      128                                  *:58888                               *:*   
LISTEN      0      511                                  *:80                                  *:*




出现以上网页nginx工作正常

3.2 编译安装MariaDB5.5


http://www.iyunv.com/kwstars/p/4f82462b7fb8c6106e662ebc6549e0c6.html



# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!



# /application/mariadb/bin/mysql
Welcome to the MariaDB monitor.Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB-log Source distribution


Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


能登陆msyql 说明mysql正常


3.3 编译安装PHP5.3


3.3.1 安装PHP的一些图形相关的lib库
yum install zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel openssl-devel libxslt-devel libmcrypt-devel libtool-ltdl-devel -y
#zlib libxml libjpeg freetype libpng gdcurllibiconv    ==>这些参数去掉后安装的编译安装未测试

3.3.2 下载php5.3.29
wget http://cn2.php.net/distributions/php-5.3.29.tar.gz
tar xf php-5.3.29.tar.gz
cd php-5.3.29



3.3.3 编译安装php5.3.29

./configure \
--prefix=/application/php-5.3.29 \
--with-mysql=/application/mysql \
--with-mysqli=/application/mysql/bin/mysql_config \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp
echo $?
make -j 4 && make install
echo $?
cd


# 3.3.4 创建软连接

ln -s /application/php-5.3.29/ /application/php

# 3.3.5 提供php配置文件
cp /root/php-5.3.29/php.ini-production /application/php/lib/php.ini

查找php配置文件php.ini所在路径的二种方法   
http://www.iyunv.com/article/50406.htm


# 3.3.6 fcgi的配置文件
cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf


# 3.3.7 修改nginx的主配置文件

cat > /application/nginx/conf/nginx.conf << EOF
worker_processes1;
events {
    worker_connections1024;
}
http {
    include       mime.types;
    default_typeapplication/octet-stream;
    sendfile      on;
    keepalive_timeout65;
    server {
      listen       80;
      server_namewww.test.com;
      index index.php index.html index.htm;
      location / {
            root   html;
            indexindex.php index.html index.htm;
      }
      error_page   500 502 503 504/50x.html;
      location = /50x.html {
            root   html;
      }
      location ~.*\.(php|php5)?$
      {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_indexindex.php;
            include      fastcgi.conf;
      }
    }
}
EOF


# 3.3.8 重新加载nginx配置文件

# /application/nginx/sbin/nginx -t    ==>测试配置文件


/application/nginx/sbin/nginx -s reload



# 3.3 9 开启php-fpm

cp php-5.3.29/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
# 或者
# /application/php/sbin/php-fpm

# 3.3.10 添加php测试文件
cat > /application/nginx/html/index.php << EOF
<?php
    phpinfo();
?>
EOF


# 3.3.11 测试 php

当出现以上网页时php工作正常

3.4 mysql 测试


cat >/application/nginx/html/tm.php << EOF
<?php
    \$conn = mysql_connect('127.0.0.1','root','');
    if(\$conn)
      echo "succ";
    else
      echo "failure";
    mysql_close();
?>
EOF




测试于另一台数据库连接

cat > /application/nginx/html/tm.php << EOF
<?php
    \$conn = mysql_connect('172.16.0.118','test','test');
    if(\$conn)
      echo "succ";
    else
      echo "failure";
    mysql_close();
?>
EOF



# /application/mysql/bin/mysql -h172.16.0.118 -utest -ptest
Welcome to the MariaDB monitor.Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.44-MariaDB-log Source distribution


Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]>


经过测试:用以上参数编译的php,localhost和IP都可以连接mysql,连接其他主机的mysql也能正常。

四、编译安装后的编译参数查询


编译参数查询如下示:

[*]查看nginx编译参数:/application/nginx/sbin/nginx -V
[*]查看apache编译参数: cat /application/apache/build/config.nice
[*]查看mysql编译参数:grep CONFIGURE_LINE /application/mysql/bin/mysqlbug
[*]查看php编译参数:/application/php/bin/php -i|grep configure


五、PHP缓存加速软件 xcache

php缓存加速种类:xcache,eaccelerator,Zend,apc


phpize是用来扩展php模块的,通过phpize可以建立php的外挂模块


wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz

tar xf xcache-3.2.0.tar.gz
cd xcache-3.2.0

/application/php/bin/phpize
./configure --enable-xcache   --with-php-config=/application/php/bin/php-config
echo $?
make
echo $?
make install
ll /application/php5.3.29/lib/php/extensions/no-debug-non-zts-20090626/
# 修改模块的目录
sed -i 's#; extension_dir = "./#extension dir = "/application/php5.3.29/lib/php/extensions/no-debug-non-zts-20090626/"#g'

echo “extension = memcache.so” >> /application/php/lib/php.ini




六、数据库缓存与优化模块memcache客户端扩展模块安装

wget http://pecl.php.net/get/memcache-2.2.7.tgz
gunzip -d memcache-2.2.7.tgz


tar xf memcache-2.2.7.tar
cd memcache-2.2.7
/application/php/bin/phpize


./configure --with-php-config=/application/php/bin/php-config
make && make install

ll /application/php5.3.29/lib/php/extensions/no-debug-non-zts-20090626/
echo “extension = xcache.so” >> /application/php/lib/php.ini

页: [1]
查看完整版本: LAMP 和 LNMP(LEMP) 编译安装