服务器篇--之 LAMP安装手记
ZendOptimizer:ZendOptimizer-3.3.0a-linux-glibc21-i386
进入目录/root
# tar -zvxf httpd-2.2.11.tar.gz
解压httpd-2.2.11.tar.gz
# cd httpd-2.2.11
进入httpd-2.2.11目录
生成/usr/local/apache2目录
# ./configure --prefix=/usr/local/apache2
或者
# ./configure --prefix=/usr/local/apache --enable-modules=so --enable-rewrite
安装apache
# vi /usr/local/apache2/conf/httpd.conf
设置DocumentRoot 的路径
# /usr/local/apache2/bin/apachectl -k start
启动apahce
用浏览器查看http://www.wengdo.com(这里写你自己网站,如http://localhost/),得到It works,说明apache已经配置成功了。
# /usr/local/apache2/bin/apachectl -k stop
停止apache
# tar -zvxf mysql-5.1.32-linux-i686-glibc23.tar.gz
# mkdir -p /usr/local/mysql (省略也可)
# cp -r mysql-5.1.32-linux-i686-glibc23/* /usr/local/mysql
# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
添加mysql用户及用户组
# groupadd mysql
# useradd -g mysql mysql
修改mysql目录权限
# chown -R root /usr/local/mysql
# chgrp -R mysql /usr/local/mysql
# chown -R mysql /usr/local/mysql/data
生成mysql系统数据库
# /usr/local/mysql/scripts/mysql_install_db --user=mysql&
启动mysql服务
# /usr/local/mysql/bin/mysqld_safe --user=mysql&
如出现 Starting mysqld daemon with databases from /usr/local/mysql/data
代表正常启动mysql服务了, 按Ctrl + C 跳出
修改 mysql 的 root 密码
# /usr/local/mysql/bin/mysqladmin -u root -p password "wengdo"
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
用ntsysv设置使mysql每次启动都能自动运行。
好了,至此mysql安装完毕,你可以这样起动你的mysql服务
# /etc/rc.d/init.d/mysqld start
下面这步比较关键,
# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
大家可以不做这步,大可以在编译其他软件的时候自定义myslq的库文件路径,但我还是喜欢把库文件链接到默认的位置,这样你在编译类似PHP,Vpopmail等软件时可以不用指定mysql的库文件地址。
- 安装 jpeg6
建立目录:
# mkdir -p /usr/local/jpeg6
# mkdir -p /usr/local/jpeg6/bin
# mkdir -p /usr/local/jpeg6/lib
# mkdir -p /usr/local/jpeg6/include
# mkdir -p /usr/local/jpeg6/man
# mkdir -p /usr/local/jpeg6/man1
# mkdir -p /usr/local/jpeg6/man/man1
# cd /root
# tar -zvxf jpegsrc.v6b.tar.gz
# cd jpeg-6b
# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
# make
# make install
- 安装libpng
# cd /root
# tar -zvxf libpng-1.2.35.tar.gz
# cd libpng-1.2.35
# cp scripts/makefile.std makefile
# make
# make install
- 安装 freetype
# cd /root
# tar -zvxf freetype-2.3.9.tar.gz
# cd freetype-2.3.9
# mkdir -p /usr/local/freetype
# ./configure --prefix=/usr/local/freetype
# make
# make install
- 安装GD库
# cd /root
# tar -zvxf gd-2.0.35.tar.gz
# mkdir -p /usr/local/gd2
# cd gd-2.0.35
# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6/ --with-png=/usr/local/lib/ --with-zlib=/usr/local/lib/ --with-freetype=/usr/local/freetype/ --enable-m4_pattern_allow
# make
# make install
安装libxml2
# cd /root
# tar -zxvf libxml2-2.6.19.tar.gz
# cd libxml2-2.6.19
# mkdir -p /usr/local/libxml2
# ./configure --prefix=/usr/local/libxml2
# make
# cd /root
# tar -zvxf php-5.2.9.tar.gz
# mkdir -p /usr/local/php
# cd php-5.2.9
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
--with-mysql=/usr/local/mysql/
--with-curl=/usr/local/curl --enable-ftp
--with-libxml-dir=/usr/local/libxml2
--with-expat-dir=/usr/lib --enable-soap
--with-xsl=/usr/local/libxslt --enable-xslt
--with-gd=/usr/local/gd2/
--with-jpeg-dir=/usr/local/jpeg6/
--with-zlib-dir=/usr/local/lib/
--with-png=/usr/local/lib/
--with-freetype-dir=/usr/local/freetype/
# make
# make install
# cp php.ini-dist /usr/local/php/lib/php.ini (别忘记了)
其中./configure 后的
--prefix=/usr/local/php
--with-apxs2=/usr/local/apache2/bin/apxs
--with-mysql=/usr/local/mysql/
--with-libxml-dir=/usr/local/libxml2
是必要的选项
--with-gd=/usr/local/gd2/
--with-jpeg-dir=/usr/local/jpeg6/
--with-png=/usr/local/lib
--with-zlib-dir=/usr/lib
--with-freetype-dir=/usr/local/freetype
这是让PHP支持GD库的配置选项
--with-curl=/usr/local/curl 支持CURL库
--enable-ftp 打开FTP库函数支持
--enable-soap --with-xsl=/usr/local/libxslt --enable-xslt
让PHP支持SOAP, 上面这些一般用得少, 可以去掉
配置 httpd.conf 让apache支持PHP
# vi /usr/local/apache2/conf/httpd.conf
找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
重启apache
# /usr/local/apache2/bin/apachectl restart
在你设置的目录里建一内容为 <? phpinfo(); ?> PHP文件, 输入URL地址查看PHP配置是否正确
- 问题一:
编译最新的GD库2.0.35版本,用默认的 ./configure编译
当make的时候,出现以下错误
configure.ac:64: error: possibly undefined macro: AM_ICONV
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
make: *** [configure] Error 1
解决方法:
编译加m4_pattern_allow参数,上面已添加
# ./configure --enable-m4_pattern_allow
- 问题二
数据库可能会出现这样的错误
"Can't connect to local MySQL server through socket '/tmp/mysql.sock'"
检查是否存在那个socket文件,可以在/etc/my.cnf 中指定 socket = /tmp/mysql.sock
使用.mysqld_safe --socket=/tmp/mysql.sock & 启动mysql进程,
有时pam_mysql使用/var/lib/mysql/mysql.sock
所以做个连接 ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
或者是修改/etc/my.cnf
有可能是权限问题,看看mysql的错误日志,一步一步调整
- 问题三
重启Apache出错
重新启动apache报如下错误:
httpd: Syntax error on line 53 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
原因:是Linux有一个SELinux保护模式引起的。
解决办法:
1关闭SELINUX的方法:
# vi /etc/selinux/config
将SELINUX=enforcing 改成SELINUX=disabled 需要重启
这个方法可能会对服务器带来风险。
2不关闭SELINUX的方法:
# setenforce 0
# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache2/modules/libphp5.so
# service httpd restart
# setenforce 1
- 问题四
PHP 在Make 或者Make install的时候出错,报错信息:
Installing PEAR environment: /usr/local/lib/php/
/usr/local/php-5.2.5/sapi/cli/php: error while loading shared libraries: /usr/local/gd2/lib/libgd.so.2: cannot restore segment prot after reloc: Permission denied
make[1]: *** [install-pear-installer] Error 127
make: *** [install-pear] Error 2
安装出错,这时候输入 tail /var/log/messages 查看错误日志
# tail /var/log/messages
...
Mar 3 06:40:46 localhost setroubleshoot: SELinux is preventing /usr/local/php-5.2.5/sapi/cli/php from loading /usr/local/gd2/lib/libgd.so.2.0.0 which requires text relocation. For complete SELinux messages. run sealert -l 6e29749f-3908-480d-bcc1-9042f8a9e846
你可以找到 run sealert -l 6e29749f-3908-480d-bcc1-9042f8a9e846,执行它
# sealert -l 6e29749f-3908-480d-bcc1-9042f8a9e846
...
The following command will allow this access:
chcon -t textrel_shlib_t /usr/local/gd2/lib/libgd.so.2.0.0
找到 following command chcon -t textrel_shlib_t /usr/local/gd2/lib/libgd.so.2.0.0
# chcon -t textrel_shlib_t /usr/local/gd2/lib/libgd.so.2.0.0
再次运行make install 或make
- 问题五
忘了mysql的root口令怎么办
# /usr/local/mysql/support-files/mysql.server stop
# mysqld_safe --skip-grant-tables &
# mysqladmin -u user password 'newpassword'
# mysqladmin flush-privileges