LAMP 服务器配置
1.安装编译环境
yum -y install gcc gcc-c++ autoconf libjpeglibjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-develzlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncursesncurses-devel curl curl-devel
yum -y install fonts-chinese scim-chewingscim-pinyin scim-tables-chinese
yum -y install libtool
2.安装Apache
下载
http://httpd.apache.org/
http://labs.xiaonei.com/apache-mirror/httpd/httpd-
安装Apache
tar xvzfhttpd-
cd httpd-
./buildconf
./configure --prefix=/usr/local/apache2--enable-so --with-mpm=worker
#./configure --prefix=/usr/local/apache2--enable-so --with-mpm=worker --enable-rewrite --enable-mods-shared=most
make
make install
创建www用户和组
/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
vi/etc/passwd
www:x:48:48::/home/www:/sbin/nologin
配置Apache
cd/usr/local/apache2/conf
vihttpd.conf
#Userdaemon 用#注释掉
#Groupdaemon 用#注释掉
#Add ByAsen 2009-04-04 23:24
User www
Group www
Includeconf/extra/httpd-mpm.conf
Include conf/extra/httpd-languages.conf
Include conf/extra/httpd-vhosts.conf
<Directory "/home/micole/php">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
vi extra/httpd-mpm.conf
先用#注释掉原有的 mpm_worker_module,然增加以下内容
#Add By Asen 2009-04-04 23:31
<IfModule mpm_worker_module>
StartServers 10
ServerLimit 2000
MaxClients 1500
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
vi extra/httpd-languages.conf
#Add By Asen 2009-04-04 23:31
DefaultLanguage zh-CN
vi extra/httpd-vhosts.conf
先用#注释掉所有内容,然后增加以下内容
#Add By Asen 2009-04-04 23:34
NameVirtualHost *
<VirtualHost *>
ServerAdmin asen2000@21cn.com
DocumentRoot /home/micole/php
ServerName www.php.com
</VirtualHost>
编辑C:\WINDOWS\system32\drivers\etc\hosts
192.168.3.2 www2.php.com
启动
/usr/local/apache2/bin/apachectl start
访问
setup
防火墙配置-打开80端口
http://www.php.com/
查看已安装模块
/usr/local/apache2/bin/httpd -M
安装mod_rewrite 模块(如果加了--enable-rewrite就不需要再做这一步)
cd httpd-
/usr/local/apache2/bin/apxs -cmod_rewrite.c
/usr/local/apache2/bin/apxs -i -a -nmod_rewrite mod_rewrite.la
vi/usr/local/apache2/conf/httpd.conf
LoadModule rewrite_modulemodules/mod_rewrite.so
重启
/usr/local/apache2/bin/apachectl restart
3.安装MySQL
下载
http://www.mysql.com/
http://dev.mysql.com/downloads/mysql/5.1.html
http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.1/mysql-
asen2000@21cn.com/raebiagaka
创建mysql用户和组
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
vi /etc/passwd
mysql:x:501:501::/home/mysql:/sbin/nologin
安装MySQL
tar xvzf mysql-
cd mysql-
./configure \
--prefix=/usr/local/mysql \
--localstatedir=/usr/local/mysql/data \
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock\
--with-extra-charsets=all \
--with-charset=utf8 \
--with-client-ldflags=-all-static \
--with-mysqld-ldflags=-all-static \
--with-plugins=all \
--with-pthread \
--enable-thread-safe-client \
--enable-assembler \
--with-big-tables \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile
make
make install
配置MySQL
chmod +w /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql/
cp support-files/my-medium.cnf /etc/my.cnf
初始化MySQL
/usr/local/mysql/bin/mysql_install_db--user=mysql
启动
/usr/local/mysql/bin/mysqld_safe--user=mysql &
设置root密码
/usr/local/mysql/bin/mysqladmin -urootpassword '123456'
命令登陆
/usr/local/mysql/bin/mysql -u root –p
查看进程
ps ax|grep mysql
杀进程 kill -92911
以下命令用于设置mysql开机自动运行
cd mysql-VERSION
再次进入解压后的目录,即源码目录。
cp support-files/mysql.server /etc/init.d/mysql
将mysql.server这个文件copy到/etc/init.d/目录下,并更名为mysql
chmod 755 /etc/init.d/mysql
给/etc/init.d/mysql这个文件赋予“执行”权限
chkconfig --level 345 mysql on
加入到开机自动运行,运行级别为3 4 5
service mysql restart
重启mysql服务
4.安装PHP
下载
http://www.php.net/
http://downloads.sourceforge.net/mcrypt/
http://downloads.sourceforge.net/mhash/
http://php-fpm.anight.org/
http://eaccelerator.net/
http://pecl.php.net/package/memcache/
http://www.phpmyadmin.net/
http://cn.php.net/distributions/php-
http://cn.php.net/distributions/php-
http://downloads.sourceforge.net/mcrypt/libmcrypt-
http://downloads.sourceforge.net/mcrypt/mcrypt-
http://downloads.sourceforge.net/mhash/mhash-
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz
http://php-fpm.anight.org/downloads/head/php-
http://bart.eaccelerator.net/source/
http://pecl.php.net/get/memcache-
http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-
安装PHP所需的支持库
tar zxvflibiconv-1.13.tar.gz
cdlibiconv-1.13/
./configure --prefix=/usr/local
make
make install
tar zxvf libmcrypt-
cd libmcrypt-
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure--enable-ltdl-install
make
make install
tar xvzf mhash-
cd mhash-
./configure
make
make install
cp /usr/local/lib/libmcrypt.* /usr/lib
ln -s /usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2
tar zxvf mcrypt-
cd mcrypt-
./configure
make
make install
安装PHP+Apache
tar zxvf php-
cd php-
./configure \
--prefix=/usr/local/php5 \
--with-apache2=/usr/local/apache2 \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/apache2/conf\
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config\
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-discard-path \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-sockets \
--enable-roxen-zts \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl
sed -i 's#-lz -lm -lxml2 -lz -lm -lxml2 -lz-lm -lcrypt#& -liconv#' Makefile
make
make install
tar zxvf memcache-
cd memcache-
/usr/local/php5/bin/phpize
./configure--with-php-config=/usr/local/php5/bin/php-config
make
make install
tar jxvf eaccelerator-
cd eaccelerator-
/usr/local/php5/bin/phpize
./configure --enable-eaccelerator=shared--with-php-config=/usr/local/php5/bin/php-config
make
make install
配置PHP
cp php.ini-dist /usr/local/apache2/conf/php.ini
vi /usr/local/apache2/conf/php.ini
修改
extension_dir = "./"
为
extension_dir ="/usr/local/php5/lib/php/extensions/no-debug-zts-20060613/"
添加以下行
extension = "memcache.so"
修改output_buffering = Off 为 output_buffering = On
配置eAccelerator加速PHP
mkdir -p /usr/local/php5/eaccelerator_cache
vi /usr/local/apache2/conf/php.ini
在最末尾加入以下行
extension = "eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/usr/local/php5/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
配置Apache
vi/usr/local/apache2/conf/httpd.conf
AddType application/x-httpd-php .php .php3 .phtml
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.htmindex.php
关闭SELINUX
vi /etc/selinux/config 将SELINUX=enforcing 改成SELINUX=disabled 重启
重启Apache
/usr/local/apache2/bin/apachectl restart
安装phpMyAdmin
cd /home/asen/php/
tar xvzf /home/asen/soft/PHP/phpMyAdmin-
mv phpMyAdmin-
cd phpMyAdmin
cp libraries/config.default.php config.inc.php
这里只需要将$cfg['Servers'][$i]['host'] = 'localhost' 改为 '127.0.0.1' 就可以了。或者改成localhost.localdomain,这样改的依据是more /etc/hosts,可以看到localhost和localhost.localdomain被解析为127.0.0.1的,而mysql的 my.cnf里面大家都加了bind-address = 127.0.0.1,所以要修改$cfg['Servers'][$i]['host']。
安装memcached
tar -zxvf libevent-
cd libevent-
./configure --prefix=/usr
make
make install
ls -al /usr/lib | grep libevent
cd ..
tar -zxvf memcached-
cd memcached-
./configure --prefix=/usr/local/memcached--with-libevent=/usr
make
make install
#安装好了以后,先建立memcached运行临时目录:
mkdir -pv /var/run/memcached
chown -R nobody:nobody /var/run/memcached
#启动memcached
/usr/local/memcached/bin/memcached -p 11211-l 127.0.0.1 -d -u nobody -P /var/run/memcached/memcached.pid -m
其它
改编码
vi /etc/sysconfig/i18n
LANG="zh_CN.UTF-8"
改成
LANG="zh_CN.GB18030"
重远程链接
让apache 开机启动
vi /etc/rc.local
加上/usr/local/apache2/bin/apachectlstart