云霄飞车视频:CentOS 5.5搭建PHP环境安装笔记

来源:百度文库 编辑:中财网 时间:2024/05/04 12:27:27
1、安装系统
使用最小化安装,除了VI编辑器和中文支持以外,不安装任何附加组件。
PS:分区方案~~
/ 根分区 5000MB
/boot 一般划分100MB 强制为主分区
/swap 一般是物理内存的2倍
/home 用户目录50000MB
/usr 程序目录,分配剩余空间
/var 一般划分20000MB
/tmp 一般划分1000MB2、设置静态IP以及DNS
vi /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0
BOOTPROTO=static
HWADDR= MAC地址,这个一般都识别出来了,不用改
IPADDR= IP地址
NETMASK= 子网掩码
GATEWAY= 网关重启网络配置
service network restartvi /etc/resolv.confnameserver 第一DNS
nameserver 备用DNS重启网络配置
service network restartB.修改/etc/hosts里面的名字
# vi /etc/hosts
127.0.0.1              localhost.localdomain localhost
192.168.1.121          yourname //在这修改hostname
//有时候只有这一行
127.0.0.1              yourname localhost.localdomain localhost4、安装wget/ntsysv/patch/make
yum install wget
yum install ntsysv
yum install patch
yum install make5、关闭不需要的服务# ntsysv以下仅列出需要启动的服务,未列出的服务一律推荐关闭:atd
crond
irqbalance
microcode_ctl
network
sendmail
sshd
syslog关闭SElinux:修改/etc/selinux/config文件中的SELINUX= 为 disabled6、更换yum国内源# cd /etc/yum.repos.d# mv CentOS-Base.repo CentOS-Base.repo.save# wget http://centos.ustc.edu.cn/CentOS-Base.repo.5# mv CentOS-Base.repo.5 CentOS-Base.repo# yum clean all7、服务器时间检查和设置#date (检查时间是否正确,是否是中国时间CST)#cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime (如果时区不对,则执行,时间正常的跳过)#yum install ntp (安装ntp对时工具)#ntpdate us.pool.ntp.org#chkconfig ntpd on (让对时服务开机启动) #clock -w #这个命令强制把系统时间写入CMOS。8、使用 yum 对系统进行更新并且安装必要软件包
#yum update
#yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel重启服务器
init 69、下载相关软件
#cd /usr/local/src
#wget http://sysoev.ru/nginx/nginx-0.7.63.tar.gz
#wget http://download.scientificlinux.net/nginx
#wget http://download.scientificlinux.net/php-fpm.conf
#wget http://download.scientificlinux.net/nginx.conf
#wget http://download.scientificlinux.net/fcgi.conf
#wget http://download.scientificlinux.net/php-5.2.10.tar.gz
#wget http://download.scientificlinux.net/php-5.2.10-fpm-0.5.13.diff.gz
#wget http://download.scientificlinux.net/ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz (32位系统)
#wget http://cdnetworks-kr-2.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
#wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz
#wget http://cdnetworks-kr-2.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
#wget http://cdnetworks-kr-2.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
#wget http://pecl.php.net/get/memcache-2.2.5.tgz
#wget http://jaist.dl.sourceforge.net/sourceforge/pcre/pcre-7.8.tar.gz
#wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
#wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
#wget http://darkstar.ist.utl.pt/mysql/Downloads/MySQL-5.1/mysql-5.1.54-linux-i686-glibc23.tar.gz
安装vsftpd
第一步:yum安装vsftpd yum -y install vsftpd 第二步:配置vsftpd.conf vi /etc/vsftpd/vsftpd.conf 修改下面几个参数anonymous_enable=YES    /*是否允许匿名用户上传*/#chroot_list_enable=YES#chroot_list_file=/etc/vsftpd/chroot_list修改成:anonymous_enable=NOchroot_list_enable=YESchroot_list_file=/etc/vsftpd/chroot_list 第三步创建要ftp的目录mkdir -p /home/wwwroot/添加权限chmod 777 /home/wwwroot/ setsebool -P ftpd_disable_trans on 添加名为user的ftp帐号useradd -d /home/wwwroot/ -g ftp -s /sbin/nologin user设置帐号user的密码passwd user 创建chroot_listvi /etc/vsftpd/chroot_list再把user添加到chroot_listVi /etc/vsftpd/chroot_list按s编辑添加user按:wq退出保存 修改selinux参数:setsebool -p ftpd_disable_trans 1service vsftpd restart这就样简单。可以去用ftp软件登陆10、安装PHP所需组件【安装PHP 5.2.8(FastCGI模式)】
tar zxvf libiconv-1.13.tar.gzcd libiconv-1.13/./configure --prefix=/usr/localmakemake installcd ../tar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configuremakemake install/sbin/ldconfigcd libltdl/./configure --enable-ltdl-installmakemake installcd ../../tar zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9/./configuremakemake installcd ../ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
11、安装MySQLcd /usr/local/srctar zxvf mysql-5.1.54-linux-i686-glibc23.tar.gzmv mysql-5.1.54-linux-i686-glibc23 /usr/local/ln -s /usr/local/mysql-5.1.54-linux-i686-glibc23/ /usr/local/mysqlgroupadd mysqluseradd -g mysql mysqlchown -R mysql:mysql /usr/local/mysqlchown -R mysql:mysql /usr/local/mysql-5.1.54-linux-i686-glibc23/cd /usr/local/mysql./scripts/mysql_install_db --user=mysqlcp ./support-files/mysql.server /etc/rc.d/init.d/mysqldchmod 755 /etc/rc.d/init.d/mysqldchkconfig --add mysqldchkconfig --level 3 mysqld oncp ./support-files/my-huge.cnf /etc/my.cnfmv /usr/local/mysql/data /var/lib/mysqlchown -R mysql:mysql /var/lib/mysql编辑/etc/my.cnf在 [mysqld] 段增加datadir = /var/lib/mysql
skip-innodb
wait-timeout = 10
max_connections = 512
max_connect_errors = 10000000在 [mysqld] 段修改max_allowed_packet = 16Mthread_cache_size = CPU个数*2将 log-bin 注释service mysqld startbin/mysqladmin -u root password 'password_for_root'其中引号内的password_for_root是要设置的root密码12、安装Nginx以及所需的pcre库
cd /usr/local/srctar zxvf pcre-7.8.tar.gzcd pcre-7.8/./configuremake make installcd ../
tar zxvf nginx-0.7.63.tar.gzcd nginx-0.7.63./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --with-http_random_index_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_modulemakemake installcp /usr/local/src/nginx /etc/init.d/nginxchmod 755 /etc/init.d/nginxchkconfig --add nginxchkconfig nginx on13、编译安装PHP、Zend、eAccelerator(FastCGI模式)
cd /usr/local/srctar zxvf php-5.2.10.tar.gzgzip -cd php-5.2.10-fpm-0.5.13.diff.gz | patch -d php-5.2.10 -p1cd php-5.2.10./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/etc/cgi --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --enable-magic-quotes --with-mysql=/usr/local/mysql --with-pear --enable-sockets --with-ttf --with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib --enable-sysvsem --enable-sysvshm --with-libxml-dir=/usr --enable-force-cgi-redirect --enable-fastcgi --with-xmlrpc --enable-zip --enable-fpm --with-mcrypt --with-mhashmake ZEND_EXTRA_LIBS='-liconv' (不加载liconv模块)make installmkdir -p /usr/local/etc/cgi/cp php.ini-dist /usr/local/etc/cgi/php.inimv -f /usr/local/src/php-fpm.conf /usr/local/php5/etc/php-fpm.confgroupadd wwwuseradd -g www wwwecho 'ulimit -SHn 65535' >> /etc/rc.localecho '/usr/local/php5/sbin/php-fpm start' >> /etc/rc.local  14、编译安装PHP5扩展模块
cd /usr/local/srctar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8//sbin/ldconfig./configuremakemake install----------------------------------------------------------cd /usr/local/srctar zxvf memcache-2.2.5.tgzcd memcache-2.2.5//usr/local/php5/bin/phpize./configure --with-php-config=/usr/local/php5/bin/php-configmakemake installcd ../---------------------------------------------------------------tar zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gzcd ZendOptimizer-3.3.3-linux-glibc23-i386./install(注意第一个要填的路径是Zend安装路径,第二个是php.ini所在的路径,即/usr/local/etc/cgi)(不要选重启apache)---------------------------------------------------------------cd ../tar jxvf eaccelerator-0.9.6.1.tar.bz2cd eaccelerator-0.9.6.1//usr/local/php5/bin/phpize./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php5/bin/php-configmakemake installcd ../得到路径/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/---------------------------------------------------------------tar zxvf PDO_MYSQL-1.0.2.tgzcd PDO_MYSQL-1.0.2//usr/local/php5/bin/phpize./configure --with-php-config=/usr/local/php5/bin/php-config --with-pdo-mysql=/usr/local/mysqlmakemake installcd ../
15、设置Nginx和phpmv -f /usr/local/src/fcgi.conf /usr/local/nginx/conf/cp -f /usr/local/src/nginx.conf /usr/local/nginx/conf/nginx.confmkdir -p /home/www/wwwrootulimit -SHn 65535修改php.ini文件vi /usr/local/etc/cgi/php.ini手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"
修改为extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/"
并在此行后增加以下几行,然后保存:
extension = "memcache.so"
extension = "pdo_mysql.so"再查找output_buffering = Off
修改为output_buffering = Oneaccelerator即可以安装为PHP扩展,也可以安装为zend扩展,以下安装为PHP扩展。
  
在最后一行加入以下内容(一定要放在Zend配置文件之前)[eaccelerator] 
extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.Optimizer="1"
eaccelerator.check_mttime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
  
建立缓存目录:
# mkdir -p /tmp/eaccelerator
# chmod 777 /tmp/eaccelerator修改配置文件:vi /etc/sysctl.conf
kernel.shmmax = 134217728
然后执行以下命令使配置生效:/sbin/sysctl -p
16、设置系统防火墙编辑/usr/local/sbin/fw.sh复制以下内容进去#!/bin/bash# Stop iptables service firstservice iptables stop# Load FTP Kernel modules/sbin/modprobe ip_conntrack_ftp/sbin/modprobe ip_nat_ftp# Inital chains default policy/sbin/iptables -F -t filter/sbin/iptables -P INPUT DROP/sbin/iptables -P OUTPUT ACCEPT# Enable Native Network Transfer/sbin/iptables -A INPUT -i lo -j ACCEPT# Accept Established Connections/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT# ICMP Control/sbin/iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT# WWW Service/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT# FTP Service/sbin/iptables -A INPUT -p tcp --dport 21 -j ACCEPT# SSH Service/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT退出编辑,执行以下命令#c# echo '/usr/local/sbin/fw.sh' >> /etc/rc.local# /usr/local/sbin/fw.sh修改$PATH下php/mysql路径cd /etcvi /etc/profile在适当位置添加PATH=$PATH:/usr/local/php5/bin
PATH=$PATH:/usr/local/mysql/bin保存退出后执行source profile 重启系统
init 617、检查配置是否正确cd /home/www/wwwrootvi index.php保存退出打开浏览器输入IP地址查看18、配置虚拟主机vi /usr/local/nginx/conf/nginx.conf建立主机文件夹mkdir /home/www/wwwroot/www.1.commkdir /home/www/wwwroot/www.2.com给文件夹赋予权限chmod -R 777 /home/www/wwwroot/www.1.comchmod -R 777 /home/www/wwwroot/www.2.com配置文件内容如下:user  www www;worker_processes 4;error_log  logs/nginx_error.log  crit;pid        logs/nginx.pid;worker_rlimit_nofile 65535;events
{
  use epoll;
  worker_connections 65535;
}http
{
  include       mime.types;
  default_type  application/octet-stream;  #charset  gb2312;  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;  sendfile on;
  tcp_nopush     on;  keepalive_timeout 60;  tcp_nodelay on;  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;--------------------------------------------
#将server部分修改为一下内容
server {
  listen         80;
  server_name     _;
  access_log  off;
  server_name_in_redirect  off;
  location / {
  root  /usr/local/nginx/html;
  index index.html;
     }
  }  # 包含所有的虚拟主机的配置文件
  include /usr/local/nginx/vhosts/*;--------------------------------------
}#在 /usr/local/nginx 下创建 vhosts 目录mkdir /usr/local/nginx/vhosts#在 /usr/local/nginx/vhosts/ 里创建一个名字为 www.1.com.conf 的文件,把以下内容拷进去vi /usr/local/nginx/vhosts/www.1.com.confserver {
        listen  80;
        server_name  www.1.com;        access_log  off;        location / {
            root   /home/www/wwwroot/www.1.com;
            index  index.php index.html index.htm;
        }        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/nginx/html;
        }       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /home/www/wwwroot/www.1.com/$fastcgi_script_name;
            include        fastcgi_params;
        }        location ~ /\.ht {
            deny  all;
        }
}#如果建立多个主机,就相应的建立多个*.conf配置文件带DZ论坛伪静态的设置server {
        listen  80;
        server_name bbs.gougou101.com;        access_log  off;        location / {
            root   /home/www/wwwroot/gougou101/bbs;
            index  index.php index.html index.htm;
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
rewrite ^([^\.]*)/([a-z]+)-(.+)\.html$ $1/$2.php?rewrite=$3 last;
if (!-e $request_filename) {
        return 404;
}
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/nginx/html;
        }       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /home/www/wwwroot/gougou101/bbs/$fastcgi_script_name;
            include        fastcgi_params;
        }        location ~ /\.ht {
            deny  all;
        }
} 配置文件修改完以后重启Nginx/usr/local/php5/sbin/php-fpm restartservice nginx restart
分别在两个主机文件夹下建立文件测试虚拟主机vim /home/www/wwwroot/www.1.com/index.html输入内容www.1.com保存退出在浏览器输入www.1.com查看(需要修改查看机的host记录)重复以上操作创建www.2.com
20、安装phpmyadmin管理mysql将phpmyadmin下载到需要管理mysql网站目录下cd /usr/local/srcwget http://unmp.googlecode.com/files/phpMyAdmin-3.3.3-all-languages.tar.gz解压缩到当前目录下tar zxvf phpMyAdmin-3.3.3-all-languages.tar.gz修改目录名并移动到网站目录下mv /usr/local/src/phpMyAdmin-3.3.3-all-languages /home/www/wwwroot/这里要根据网站所在目录所定修改配置文件vi /home/www/wwwroot/网站目录名称/mysqladmin/libraries/config.default.php$cfg['PmaAbsoluteUri'] = 'url'; //访问myphpadmin的网址$cfg['blowfish_secret'] = '随便填一个'; //短密码验证$cfg['Servers'][$i]['host'] = 'localhost';$cfg['Servers'][$i]['port'] = '';$cfg['Servers'][$i]['auth_type'] = 'cookie'; //指定登录模式$cfg['Servers'][$i]['user'] = 'root'; //指定登录用户------------------------------------------------------------------------------------------------一、Mysql重要目录
1、数据库目录/var/lib/mysql
2、配置文件/usr/share/MySQL CentOS(MySQL CentOS.server命令及配置文件)
3、相关命令/usr/bin(MySQL CentOSadmin MySQL CentOSdump等命令)
4、启动脚本/etc/rc.d/init.d/(启动脚本文件MySQL CentOS的目录)