linux下配置php環境____linux

來源:互聯網
上載者:User


一.系統
系統版本                   centos5.0
軟體原始碼包存放位置      /usr/local/src
源碼包編譯安裝位置(prefix)   /usr/local/software_name
指令碼以及維護程式存放位置   /usr/local/sbin
MySQL 資料庫位置          /var/lib/mysql
Apache 網站根目錄          /home/www/wwwroot
Apache 虛擬機器主機日誌根目錄  /home/www/logs
Apache 運行帳戶            www:www


關閉不需要的服務
   # ntsysv
   以下僅列出需要啟動的服務,未列出的服務一律關閉:
   atd
   crond
   irqbalance
   microcode_ctl
   network
   sendmail
   sshd
   syslog

重新啟動系統
   # reboot

使用yum程式安裝所需軟體包(以下為標準的RPM包名稱)
   # yum install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel kernel

定時校正伺服器時鐘,定時與中國國家授時中心授時伺服器同步
# crontab -e
加入一行:
*/30 * * * * ntpdate 210.72.145.44

原始碼編譯安裝所需包
(1) GD2
       # cd /usr/local/src
       # wget http://www.libgd.org/releases/oldreleases/gd-2.0.34.tar.gz
       # tar xzvf gd-2.0.34.tar.gz
       # cd gd-2.0.34
       # ./configure --prefix=/usr/local/gd2
       # make
       # make install
(2) LibXML2
       # cd /usr/local/src
       # wget ftp://xmlsoft.org/libxml2/libxml2-2.6.29.tar.gz
       # tar xzvf libxml2-2.6.29.tar.gz
       # cd libxml2-2.6.29
       # ./configure --prefix=/usr/local/libxml2
       # make
       # make install
(3) LibMcrypt
       # cd /usr/local/src
       #wget http://jaist.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.bz2
       # tar xjvf libmcrypt-2.5.8.tar.bz2
       # cd libmcrypt-2.5.8
       # ./configure --prefix=/usr/local/libmcrypt
       # make
       # make install
(4) Apache 日誌截斷程式
        # cd /usr/local/src
       # wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
       # tar xzvf cronolog-1.6.2.tar.gz
       # cd cronolog-1.6.2
       # ./configure --prefix=/usr/local/cronolog
       # make
       # make install

8.升級OpenSSL和OpenSSH
    # cd /usr/local/src
    # wget http://www.openssl.org/source/openssl-0.9.8e.tar.gz
    # wget http://mirror.mcs.anl.gov/openssh/portable/openssh-4.6p1.tar.gz
    # tar xzvf openssl-0.9.8e.tar.gz
    # cd openssl-0.9.8e
    # ./config --prefix=/usr/local/openssl
    # make
    # make test
    # make install
    # cd ..
    # tar xzvf openssh-4.6p1.tar.gz
    # cd openssh-4.6p1
    # ./configure  \
"--prefix=/usr" \
"--with-pam" \
"--with-zlib" \
"--sysconfdir=/etc/ssh" \
"--with-ssl-dir=/usr/local/openssl" \
"--with-md5-passwords"
    # make
    # make install


(5)禁用用戶端 GSSAPI
# vi /etc/ssh/ssh_config
找到:
GSSAPIAuthentication yes
將這行注釋掉。

最後,確認修改正確後重新啟動 SSH 服務
# service sshd restart
# ssh -v 
確認 OpenSSH 以及 OpenSSL 版本正確。

編譯安裝主控環境
1. 下載軟體

2. 編譯安裝MySQL
    # tar xzvf mysql-5.0.27.tar.gz
    # cd mysql-5.0.27
    # ./configure \
        "--prefix=/usr/local/mysql" \
        "--localstatedir=/var/lib/mysql" \                (注意:/var 分區是否適合。)
         "--with-comment=Source" \
        "--with-server-suffix=-lanmang" \
        "--with-mysqld-user=mysql" \
        "--without-debug" \
        "--with-big-tables" \
        "--with-charset= gbk" \                (此處設定MySQL預設字元集)
         "--with-collation= gbk_chinese_ci" \        (此處設定MySQL校正字元集)
         "--with-extra-charsets=all" \
        "--with-pthread" \
        "--enable-static" \
        "--enable-thread-safe-client" \
        "--with-client-ldflags=-all-static" \
        "--with-mysqld-ldflags=-all-static" \
        "--enable-assembler" \
        "--without-isam" \
        "--without-innodb" \
        "--without-ndb-debug"
    # make
    # make install
    # useradd mysql
    # cd /usr/local/mysql
    # bin/mysql_install_db --user=mysql
    # chown -R root:mysql .
    # chown -R mysql /var/lib/mysql
    # cp share/mysql/my-huge.cnf /etc/my.cnf
    # cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
    # chmod 755 /etc/rc.d/init.d/mysqld
    # chkconfig --add mysqld
    # chkconfig --level 3 mysqld on
    # /etc/rc.d/init.d/mysqld start
    # bin/mysqladmin -u root password 'password_for_root'  (指定mysqlroot密碼)

編譯安裝Apache
    # cd /usr/local/src
    # tar xjvf httpd-2.2.4.tar.bz2
    # cd httpd-2.2.4
    # ./configure \
        "--prefix=/usr/local/apache2" \
        "--with-included-apr" \
        "--enable-so" \
        "--enable-deflate=shared" \
        "--enable-expires=shared" \
        "--enable-rewrite=shared" \
        "--enable-static-support" \
        "--disable-userdir"
    # make
    # make install
    # echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local

4. 編譯安裝PHP
    # cd /usr/local/src
    # tar xjvf php-5.2.3.tar.bz2
    # cd php-5.2.3
    # ./configure \
        "--prefix=/usr/local/php" \
          "--with-config-file-path=/etc" \
        "--with-mysql=/usr/local/mysql" \
        "--with-libxml-dir=/usr/local/libxml2" \
        "--with-gd=/usr/local/gd2" \
        "--with-jpeg-dir" \
        "--with-png-dir" \
        "--with-bz2" \
        "--with-freetype-dir" \
        "--with-iconv-dir" \
        "--with-zlib-dir " \
        "--with-openssl=/usr/local/openssl" \
        "--with-mcrypt=/usr/local/libmcrypt" \
        "--enable-soap" \
        "--enable-gd-native-ttf" \
        "--enable-memory-limit" \
        "--enable-ftp" \
        "--enable-mbstring" \
        "--enable-exif" \
        "--disable-ipv6" \
        "--enable-fastcgi" \
        "--enable-force-cgi-redirect"\
        "--disable-cli"
      "--with-apxs2=/usr/local/apache2/bin/apxs" \ 
    # make
    # make install
    # mkdir /usr/local/php/etc
    # cp php.ini-dist /usr/local/php/etc/php.ini

安裝Zend Optimizer
    # cd /usr/local/src
    # tar xzvf ZendOptimizer-3.2.8-linux-glibc21-i386.tar.gz
    # ./ZendOptimizer-3.2.8-linux-glibc21-i386/install.sh
    安裝Zend Optimizer過程的最後不要選擇重啟Apache。

整合Apache與PHP
    # vi /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在該行下面添加
AddType application/x-httpd-php .php

找到:
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
將該行改為
<IfModule dir_module>
    DirectoryIndex index.html index.htm index.php
</IfModule>

找到:
#Include conf/extra/httpd-mpm.conf
#Include conf/extra/httpd-info.conf
#Include conf/extra/httpd-vhosts.conf
#Include conf/extra/httpd-default.conf
去掉前面的“#”號,取消注釋。

注意:以上 4 個擴充設定檔中的設定請按照相關原則進行合理配置。

修改完成後儲存退出。
# /usr/local/apache2/bin/apachectl restart

7. 查看確認環境資訊、提升 PHP 安全性
   在網站根目錄放置 phpinfo.php 指令碼,檢查phpinfo中的各項資訊是否正確。
   #vi phpinfo.php
   <?php
   phpinfo();
   ?>

   確認 PHP 能夠正常工作後,在 php.ini 中進行設定提升 PHP 安全性。
   # vi /etc/php.ini
        找到:
        disable_functions =
        設定為:
        phpinfo,system,chroot,escapeshellcmd,escapeshellarg,proc_open,proc_get_status,socket_create,socket_bind,
        socket_listen,socket_accept,socket_write,socket_read


8. eaccelerator
     # tar -jxf eaccelerator-0.9.5.tar.bz2
     # cd eaccelerator-0.9.5
     # /usr/local/php/bin/phpize
     # ./configure     --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
     # make && make install


三、伺服器安全性設定
1. 設定系統防火牆
    # touch /usr/local/sbin/fw.sh
        將以下指令碼命令(綠色部分)粘貼到 fw.sh 檔案中。

#!/bin/bash

# Stop iptables service first
service 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

   # chmod 755 /usr/local/sbin/fw.sh
   # echo '/usr/local/sbin/fw.sh' >> /etc/rc.local
   # /usr/local/sbin/fw.sh

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.