您的位置:首页 > 运维架构 > Linux

LAMP 全功能编译安装 for CentOS6.3笔记

2013-01-19 17:53 429 查看
操作系统版本:centOS6.3 64bit
模块:全功能编译安装
一.配置yum本地安装源:
# su - root
# mkdir /mnt/cdrom
# mount -t iso9660 /dev/sr0 /mnt/cdrom
# cd /etc/yum.repos.d
查看本目录是否有.repo后缀文件,有则将本目录所有*.repo删除或者转移到其他目录,并创建一个.repo文件,
文件名随意。
# vi local.repo
[LOCAL]
name=local
baseurl=file:///mnt/cdrom
enable=1
gpgcheck=0
保存退出
# yum clean all
二.安装开发包:
yum install gcc* -y
如果遇到错误 checking for termcap functions library… configure: error: No curses/termcap library found
表示ncurses-devel包没有安装。
如果遇到错误 configure: error: ...No recognized SSL/TLS toolkit detected,那么需要安装openssl-devel
建议安装系统的时候选择,最小桌面安装,然后再开发包选项中,把5个包全点安装.
三.关闭iptables防火墙
service iptables stop
四.安装mysql数据库
# wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.72.tar.gz # useradd -d /usr/local/mysql/ mysql 创建一个Mysql用户,指定家目录到/use/local目录下。
# mkdir /usr/local/mysql/data
# mkdir /usr/local/mysql/log 新建一个目录
# chown -R mysql:mysql /usr/local/mysql/data/
# chown -R mysql:mysql /usr/local/mysql/log/
# chmod 750 /usr/local/mysql/data
# chmod 750 /usr/local/mysql/log 修改目录的所属者以及所属组
# tar -zxvf mysql-5.1.71.tar.gz 解包
# cd mysql-5.1.71
# ./configure --prefix=/usr/local/mysql --sysconfdir=/etc --localstatedir=/usr/local/mysql/data -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=gbk --with-extra-charsets=gbk -with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap
> --prefix=/usr/local/mysql \指定安装目录
> --sysconfdir=/etc \配置文件的路径
> --localstatedir=/usr/local/mysql/data \数据库存放的路径
> --enable-assembler \使用一些字符函数的汇编版本
> --with-mysqld-ldflags=-all-static \以纯静态方式编译服务端
> --with-charset=gbk \添加GBK字符支持
> --with-extra-charsets=gbk \添加GBK字符集
> --with-extra-charsets=all \添加所有字符支持
> --with-plugins=csv,innobase,myisam,heap \添加数据库引擎
注:若在系统中安装多个mysql,可按照如下编译,单mysql无视以下配置
==============================================================
./configure --prefix=/usr/local/mysql3307 --with-mysqld-user=mysql --sysconfdir=/usr/local/mysql3307/etc --localstatedir=/usr/local/mysql3307/data --with-tcp-port=3307 -enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --with-extra-charsets=gbk -with-extra-charsets=all --with-plugins=csv,innobase,myisam,heap --with-unix-socket-path=/tmp/mysql3307.sock
==============================================================
# make
# make install

# vi /etc/my.cnf
-------------------
[mysqld]
port = 3306
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
max_connections = 32000
#内存参数
skip-locking
key_buffer = 256M
max_allowed_packet = 32M
table_cache = 4096
thread_cache_size = 512
sort_buffer_size = 16M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
net_buffer_length = 256M
thread_stack = 8M
query_cache_size = 128M
query_cache_limit = 2M
#禁止sql读取本地文件
local-infile=0
#log
log-error=/usr/local/mysql/log/error.log
log=/usr/local/mysql/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql/log/slowquery.log
log-update=/usr/local/mysql/log/update.log
#二进制日志文件
log-bin= /usr/local/mysql/log/bin.log
#删除30天之前的二进制日志
expire_logs_days = 30
#同步二进制日志
sync_binlog = 1
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
--------------------
低配配置文件:
-----------------------
[mysqld]
port= 3306
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
max_connections = 32000
skip-external-locking

key_buffer = 16K
query_cache_limit = 256K
query_cache_size = 4M
max_allowed_packet = 50M
table_cache = 8

thread_concurrency = 2

sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 131072

log-error=/usr/local/mysql/log/error.log
log=/usr/local/mysql/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql/log/slowquery.log

[mysqldump]
quick
max_allowed_packet = 50M

[mysql]
no-auto-rehash
#safe-updates

[isamchk]
key_buffer = 8M
sort_buffer_size = 8M

[myisamchk]
key_buffer = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout
-----------------------

注:若安装多个mysql,需到对应的mysql配置文件中更改port,socket,datadir等相应参数,单mysql无视以下配置
==============================================================
# mkdir -p /usr/local/mysql3307/etc
# chown -R mysql.mysql /usr/local/mysql3307/etc
# mkdir -p /var/run/mysqld3307
# chown -R mysql.mysql /var/run/mysqld3307
# mkdir -p /var/lib/mysqld3307
# chown -R mysql.mysql /var/lib/mysqld3307
# cp /etc/my.cnf /usr/local/mysql3307/etc
# vi /usr/local/mysql3307/etc/my.cnf
--------------------------------------------
[mysqld]
datadir=/usr/local/mysql3307/data
socket=/tmp/mysql3307.sock
user=mysql
port=3307
pid-file=/var/lib/mysqld3307/mysql.pid
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

max_connections= 16384
skip-name-resolve
skip-locking
key_buffer = 256M

max_allowed_packet = 32M

table_cache = 3072

thread_cache_size = 256

sort_buffer_size = 16M

read_buffer_size = 4M

read_rnd_buffer_size = 16M

net_buffer_length = 256M

thread_stack = 8M

query_cache_size = 128M

query_cache_limit = 2M

wait_timeout=7200
interactive_timeout=7200

#log
log-error=/usr/local/mysql3307/log/error.log
log=/usr/local/mysql3307/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql3307/log/slowquery.log
#log-update=/usr/local/mysql3307/log/update.log
log-bin= /usr/local/mysql3307/log/bin.log
expire_logs_days = 15
sync_binlog = 1
max_binlog_cache_size = 4294967295

local-infile=0

[mysqld_safe]
log-error=/var/log/mysqld3307.log
pid-file=/var/run/mysqld3307/mysqld.pid
--------------------------------------------
===============================================================

# /usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data #初始化数据库
注: 多个mysql则需单独初始化,单mysql无视以下配置
===============================================================
/usr/local/mysql3307/bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql3307/data
===============================================================

# cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
注:这里若安装多个mysql,则需要从新复制一份mysql系统启动文件,并进行参数修改,单mysql无视以下配置
===============================================================
# cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld3307
# vi /etc/init.d/mysqld3007
添加如下加红参数
---------------------------------------------
basedir=/usr/local/mysql3307
datadir=/usr/local/mysql3307/data
conf=/usr/local/mysql3307/etc/my.cnf
$bindir/mysqld_safe --defaults-file=$conf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
--------------------------------------------

# chkconfig --add mysqld #添加开机启动服务
# chkconfig --level 35 mysqld on #设置mysql启动
注: 多个mysql则需创建独立的启动服务,单mysql无视以下配置
===============================================================
chkconfig --add mysqld3307
chkconfig --level 35 mysqld3307 on
===============================================================
# /etc/init.d/mysqld start #启动数据库
注: 多个mysql启动,单mysql无视以下操作
===============================================================
# /etc/init.d/mysqld3307 start #启动数据库
===============================================================
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock 创建一个mysql接口的软链接
# /usr/local/mysql/bin/mysqladmin -u root password 123456 #设置密码
注: 多个mysql初始密码设置,单mysql无视以下配置
===============================================================
/usr/local/mysql3307/bin/mysqladmin -u root password 123456
===============================================================
# /usr/local/mysql/bin/mysql -u root -p123456 #连接数据库
注: 多个mysqld登录,单mysql无视以下操作
===============================================================
/usr/local/mysql3307/bin/mysql -P3307 -S/tmp/mysql3307.sock -uroot -p123456
===============================================================
mysql> create database phpwind; #---创建数据库
mysql> grant all privileges on *.* to root@'%' identified by '123456' with grant option; #给root用户非本地链接所有权限,并改密码和赋予其给其他人下发权限.
mysql> show variables; #查看mysql设置.
# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
# 这里是把mysql文件链接到默认位置,必须做这步,在编译其他软件的时候自定义mysql的库文件路径。
# 安装过程中遇到一点小错误,就是gcc没有安装,大家不要犯这么弱的错误,呵呵。
如果安装论坛报错,
方法一:
vi /etc/my.cnf
#找到此处:
[mysqld]
socket=/var/lib/mysql/mysql.sock
#修改为
[mysqld]
socket=/tmp/mysql.sock
方法二:
vi /etc/init.d/mysqld

末行添加:

rm -rf /tmp/mysql.sock
ln -d /var/lib/mysql/mysql.sock /tmp/mysql.sock 创建一个mysql接口的硬链接
注:从启MYSQL也可使用以下命令开启此服务
cd /usr/local/mysql
./bin/safe_mysqld
如果不设置chkconfig启动项,也可在/etc/rc.local下添加如下命令,使mysql服务利用系统启动脚本运行.




五. 安装apache网站服务

1.下载pcre安装包:
# wget http://sourceforge.net/projects/pcre/files/pcre/8.32/pcre-8.32.tar.gz/download # tar -xzvf pcre-8.32.tar.gz
# cd pcre-8.32
# ./configure --prefix=/usr/local/pcre
# make && make install
2.下载httpd包:
下载地址:
# wget http://archive.apache.org/dist/httpd/httpd-2.4.2-deps.tar.bz2 # wget http://archive.apache.org/dist/httpd/httpd-2.4.2.tar.bz2 解压安装 已集成APR,需安装pcre支持,操作1已安装
# tar jxvf httpd-2.4.2.tar.bz2
# tar jxvf httpd-2.4.2-deps.tar.bz2
# cd httpd-2.4.2
# ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --with-pcre=/usr/local/pcre/bin/pcre-config
加载mod_ssl可按照如下编译(不添加https访问可略过)
-------------------------
# ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite -enable-ssl=static -with-ssl=/usr/local/ssl -enable-mods-shared=all --with-pcre=/usr/local/pcre/bin/pcre-config

编译过程中如果报错:
checking for OpenSSL version >= 0.9.7… FAILED
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl… configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
解决办法(更新源为centos6.3或redhat6.3光盘源)
# yum install openssl-devel
# yum update openssl
-------------------------
# make && make install
# 防止apache启动报错.
vi /usr/local/apache2/conf/httpd.conf
添加: ServerName localhost:80
# /usr/local/apache2/bin/apachectl start 启动apache
注: 在/etc/rc.local下添加如下命令,使apache服务开机运行



配置apache:
1.禁止地址目录访问和索引:
#vi /usr/local/apache2/conf/httpd.conf
搜索 Options Indexes FollowSymLinks
将其前面加#注释
# Options Indexes FollowSymLinks
2.隐藏版本号:
#vi /usr/local/apache2/conf/httpd.conf
加入以下两行:
ServerTokens ProductOnly
ServerSignature Off
3.优化线程数:
如果apche访问量过大,将会导致页面打开迟缓,下载速度也降低,如果由于经费和环境问题,集群方案没有得以应用。可以通过对Apache2增加模块MPM来进行优化, 这里我选择线程型MPM加以优化:
注:此方法仅对编译安装apache有效:
a.开启mpm:
#vi /usr/local/apache2/conf/httpd.conf
找到以下这行内容,去掉注释.
Include conf/extra/httpd-mpm.conf (如果没有此段代码可以新加。没有此文件httpd-mpm.conf可以新建,也可以直接加代码到)
b.优化配置:
#vi /usr/local/apache2/conf/extra/httpd-mpm.conf
找到如下代码,修改成以下参数即可.
<IfModule mpm_prefork_module>
StartServers 200
MinSpareServers 100
MaxSpareServers 200
MaxRequestWorkers 800
MaxConnectionsPerChild 4000
</IfModule>
4.关闭TRACE Method.
#vi /usr/local/apache2/conf/httpd.conf
TraceEnable off

----------加载mod_ssl实现https功能后续(不加载可略过)------------

#vi /usr/local/apache2/conf/httpd.conf
搜索"Include conf/extra/httpd-ssl.conf", 并将这行前面的"#"去掉
#vi /usr/local/apache2/conf/extra/httpd-ssl.conf
搜索"shmcb:/usr/local/apache2/logs/ssl_scache(512000)",并将这行加"#"注释掉
# cd /usr/local/apache2/conf
# wget http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz # tar zxvf ssl.ca-0.1.tar.gz
# cd ssl.ca-0.1
# ./new-root-ca.sh (生成根证书)
No Root CA key round. Generating one
Generating RSA private key, 1024 bit long modulus
………………………++++++
….++++++
e is 65537 (0×10001)
Enter pass phrase for ca.key: (输入一个密码)
Verifying – Enter pass phrase for ca.key: (再输入一次密码)
……
Self-sign the root CA… (签署根证书)
Enter pass phrase for ca.key: (输入刚刚设置的密码)
……..
…….. (下面开始签署)
Country Name (2 letter code) [MY]:CN
State or Province Name (full name) [Perak]:JiangSu
Locality Name (eg, city) [Sitiawan]:NanJing
Organization Name (eg, company) [My Directory Sdn Bhd]:Wiscom System Co.,Ltd
Organizational Unit Name (eg, section) [Certification Services Division]:ACSTAR
Common Name (eg, MD Root CA) []:WISCOM CA
Email Address []:acmail@wiscom.com.cn
这样就生成了ca.key和ca.crt两个文件,下面还要为我们的服务器生成一个证书:
# ./new-server-cert.sh server (这个证书的名字是server)
……
……
Country Name (2 letter code) [MY]:CN
State or Province Name (full name) [Perak]:JiangSu
Locality Name (eg, city) [Sitiawan]:NanJing
Organization Name (eg, company) [My Directory Sdn Bhd]:Wiscom System Co.,Ltd
Organizational Unit Name (eg, section) [Secure Web Server]:ACSTAR
Common Name (eg, www.domain.com) []:acmail.wiscom.com.cn
Email Address []:acmail@wiscom.com.cn
这样就生成了server.csr和server.key这两个文件。
还需要签署一下才能使用的:
# ./sign-server-cert.sh server
CA signing: server.csr -> server.crt:
Using configuration from ca.config
Enter pass phrase for ./ca.key: (输入上面设置的根证书密码)
Check that the request matches the signature
Signature ok
The Subject’s Distinguished Name is as follows
countryName

RINTABLE:’CN’
stateOrProvinceName

RINTABLE:’JiangSu’
localityName

RINTABLE:’NanJing’
organizationName

RINTABLE:’Wiscom System Co.,Ltd’
organizationalUnitName:PRINTABLE:’ACSTAR’
commonName

RINTABLE:’acmail.wiscom.com.cn’
emailAddress :IA5STRING:’acmail@wiscom.com.cn’
Certificate is to be certified until Jul 16 12:55:34 2005 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
CA verifying: server.crt <-> CA cert
server.crt: OK
(如果这里出现错误,最好重新来过,删除ssl.ca-0.1这个目录,从解压缩处重新开始。)
下面要按照ssl.conf里面的设置,将证书放在适当的位置。
# pwd
/usr/local/apache2/conf/ssl.ca-0.1
# chmod 400 server.key
# cd ..
# mv ssl.ca-0.1/server.key .
# mv ssl.ca-0.1/server.crt .

加载需要https加密访问的虚拟主机
例如:让www.example.com虚拟主机实现https访问
# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf
添加如下内容:
----------------------
<VirtualHost *:443>
DocumentRoot "/usr/local/apache2/htdocs/www.example.com/"
ServerAlias www.example.com
SSLEngine on
SSLCertificateFile "/usr/local/apache2/conf/server.crt"
SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"
</VirtualHost>
-----------------------
然后就可以启动啦!
# cd /usr/local/apache2
# ./bin/apachectl start
对于这个提示:
httpd: Could not determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName
只需要编辑httpd.conf,找到ServerName xxxx这一行,去掉前面的注释即可。
------------------------------------------

六.安装php模块
1.处理依赖包
----------------------
注: http2.4.1 目前不再支持php5.2.* 可用的php为5.3.10,否则php5.2*重启apachectl会报错.
httpd: Syntax error on line 163 of httpd.conf: Cannot load modules/libphp5.so into server: modules/libphp5.so: undefined symbol: unixd_config
执行之前,请检查是否安装了libxml2 libxml2-devel zlib libpng-devel libpng-devel.i686否则会报错。
注:配置php的时候出现以下问题的解决方案
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
checking for MySQL UNIX socket location... no
configure: error: Cannot find libmysqlclient_r under /usr/local/mysql. Note that the MySQL client library is not bundled anymore!
编译之前,先处理一下mysql的库,默认查找libmysqlclient_r.so,可是mysql默认为libmysqlclient.so,内容完全一样,做个链接即可
# cd /usr/local/mysql/lib/mysql/
# ln -s libmysqlclient.so.15.0.0 libmysqlclient_r.so
----------------------
2.安装PHP
# wget http://www.php.net/get/php-5.3.21.tar.gz/from/cn2.php.net/mirror # tar -zxvf php-5.3.21.tar.gz
# cd php-5.3.21
#./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --enable-libxml --with-libxml-dir=/usr/local/lib --with-zlib --with-zlib-dir=/usr/local/lib --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd --enable-soap --enable-sockets --enable-mbstring --with-png-dir=/usr/local --with-jpeg-dir=/usr/local --with-curl=/usr/lib --with-freetype-dir=/usr/include/freetype2/freetype/
#优化
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/local/lib --with-zlib-dir=/usr/local/lib --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd --enable-soap --enable-sockets --enable-xml --enable-mbstring --with-png-dir=/usr/local --with-jpeg-dir=/usr/local --with-curl=/usr/lib --with-freetype-dir=/usr/include/freetype2/freetype/ --enable-bcmath
# make
# make install
安装结束了,
#添加php配置文件,需要CP 一个源码里面的php.ini-development或php.ini-production到/usr/local/php/lib 为 php.ini
#cd ~/php-5.3.21
#cp php.ini-development /usr/local/php5/lib/php.ini
然后配置APACHE的PHP模块:
编辑Apache配置文件,即/usr/local/apache2/conf/httpd.conf,
并添加以下一行:AddType application/x-httpd-php .php
并在 DirectoryIndex 一行后面加上 index.php
如果PHP无法加载,添加以下一行,重启服务,(若提示重复,可删除)
LoadModule php5_module modules/libphp5.so
注: 编译安装的apache 网页存放路径跟rpm包安装的不一样。编译安装的路径在/usr/local/apache2/htdocs/
可添加以下内容test.php到/usr/local/apache2/htdocs/下,测试php模块是否加载.
<?php
echo phpinfo();
?>
浏览器输入 http://localhost/test.php 显示有测试页面内容,那么恭喜你大功告成.



PHP配置: (修改php.ini,默认目录/usr/local/php5/lib/php.ini)
1.隐藏PHP版本信息:
expose_php = Off
2.关闭警告及错误信息,爆路径:
display_errors = Off
3.调整时区,防止phpinfo()函数报错.
date.timezone =PRC
4.开启php错误日志并设置路径.

log_errors = On

error_log = /usr/local/apache2/logs/php_error.log

--------------大功告成-----------------
后续PHP补充模块备注:

刚编译了一个lamp,上线后发现验证码无法显示, 和网站沟通后,说是imagettftext()。
函数同时需要 GD 库和 FreeType 库。 通过产查看phpinfo();后发现没有freetype的支持,
下面是添加freetype支持的方法
cd /usr/src/php.5.4.4
cat config.nice -->这个是你上次成功编译的参数
我的系统是centos6.2 X86_64的 freetype的位置在 /usr/include/freetype2/freetype/
不知道的同学, 可以通过find / -name freetype* 进行查找,
之后在编译配置的参数上添加上 --with-freetype-dir=/usr/include/freetype2/freetype/ 就ok了
另外贴一下我的配置参数
'./configure' \
'--prefix=/usr/local/php' \
'--enable-mbstring' \
'--with-apxs2=/usr/local/apache/bin/apxs' \
'--with-mysql=/usr/local/mysql' \
'--with-config-file-path=/usr/local/php' \
'--enable-session' \
'--with-bz2' \
'--with-gd' \
'--enable-sockets' \
'--with-freetype-dir=/usr/include/freetype2/freetype/' \
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php linux mysql apache