萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

CentOS 6.0 x64 編譯安裝 LAMP 環境完整步驟實錄

環境確認與基礎工具安裝

# 檢查編譯工具
rpm -q make gcc gcc-c++ zlib-devel libaio
# 缺失則安裝
yum install make gcc gcc-c++ zlib-devel libaio -y
# 移除可能衝突的預裝套件
rpm -q httpd mysql php
# 若存在則 rpm -e 卸載

依賴庫編譯安裝序列

  1. libxml2(XML 解析器,支援多語言綁定)
    ./configure --prefix=/usr/local/libxml2/ && make && make install
  2. libmcrypt(加密演算法庫:DES, 3DES, RIJNDAEL, Twofish...)
    ./configure --prefix=/usr/local/libmcrypt/ && make && make install
  3. zlib(資料壓縮庫)
    ./configure --prefix=/usr/local/zlib/ && make && make install
  4. libpng(PNG 圖形庫)
    ./configure --prefix=/usr/local/libpng/ --enable-shared && make && make install
  5. jpeg(JPEG 圖形庫,需手動建立安裝目錄結構)
    mkdir -p /usr/local/jpeg/{bin,lib,include,man/man1}
    ./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static && make && make install
  6. freetype(字型渲染庫)
    ./configure --prefix=/usr/local/freetype/ --enable-shared && make && make install
  7. autoconf(自動配置工具)
    ./configure && make && make install
  8. GD(圖形繪製庫,串聯上述庫)
    ./configure --prefix=/usr/local/gd/ --with-zlib=/usr/local/zlib/ --with-jpeg=/usr/local/jpeg/ --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype/ && make && make install

Apache 編譯安裝

./configure --prefix=/usr/local/apache/ --enable-so --enable-rewrite
make && make install
/usr/local/apache/bin/apachectl start
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
chmod +x /etc/init.d/httpd
chkconfig --add httpd
# 若提示不支援 chkconfig,編輯 /etc/rc.d/init.d/httpd 第二行加入:
# chkconfig: 2345 10 90
# description: Activates/Deactivates Apache Web Server
chkconfig --level 2345 httpd on
service httpd restart

或修改 /etc/rc.local 加入啟動命令。

MySQL 編譯安裝(使用預編譯二進位包)

groupadd mysql
useradd -r -g mysql mysql
cd /usr/local
ln -s /tmp/LAMP/mysql-5.5.15-linux2.6-x86_64 mysql
cd mysql
chown -R mysql . ; chgrp -R mysql .
./scripts/mysql_install_db --user=mysql
chown -R root . ; chown -R mysql data
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
service mysqld restart
/usr/local/mysql/bin/mysqladmin -u root password '123456'
/usr/local/mysql/bin/mysql -u root -p

PHP 編譯安裝

./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache/bin/apxs \
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-config-file-path=/usr/local/php/etc --with-zlib --with-libxml-dir=/usr \
--enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem \
--enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex \
--enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl \
--with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
copyright © 萬盛學電腦網 all rights reserved