CentOS 5.6(X64)下編譯安裝LAMP平臺

環境:mysql-5.1.51.tar.gz httpd-2.2.19.tar.bz2 php-5.3.6.tar.bz2
數據庫數據目錄:/data
Web目錄:/htmlphp

1 安裝必備的開發包
yum -y install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel \
ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel \
gettext-devel  pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel \
libxml2-devel curl-devel  libicu libicu-devel libmcrypt libmcrypt-devel libmhash libmhash-devel 
 
#yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd  -ycss


2 同步系統時間:
#vim /etc/ntp.conf  //添加下面三行內容(19行下面添加)
 
server 3.cn.pool.ntp.org
server 3.asia.pool.ntp.org
server 0.asia.pool.ntp.org
 
# service ntpd stop
#ntpdate  cn.pool.ntp.org  //更新時間
#service ntpd start
chkconfig ntpd onhtml


3 Install mysql編譯安裝mysql
cd mysql-5.1.51
./configure \
--prefix=/usr/local/mysql \
--exec-prefix=/usr/local/mysql \
--with-mysqld-user=mysql \
--with-charset=utf8 \
--with-extra-charsets=all \
--with-innodb \
--with-pthread \
--enable-assembler \
--enable-thread-safe-client \
--with-big-tables \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
make && make installmysql

添加用戶
groupadd –g 306 mysql
useradd –g mysql –u 306 –M –s /sbin/nologin
chown –R mysql:mysql /datalinux

/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/data
chown -R root:mysql /usr/local/mysql/
chown -R mysql /usr/local/mysql
chgrp -R mysql /usr/local/mysql/
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
編輯/etc/my.cnf,在[mysqld]加入 datadir = /data
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld  
chkconfig --level 3 mysqld on 
service mysqld startc++

測試數據庫服務器
/usr/local/mysql/bin/mysql -uroot
root用戶的默認密碼是空
如出現標識符
mysql>
說明MySQL數據庫安裝成功,而且已經啓動了!
爲root用戶設置密碼
mysql>use mysql;
mysql>set password for root@localhost=password("CentOSmysqla#"); 
mysql>set password for root@127.0.0.1=password("centosmysqla#"); 
刪除空賬戶,查看賬戶信息
mysql>delete from mysql.user where user='';
mysql>select user,host,password from mysql.user; 
容許root用戶遠程登陸
mysql>grant all privileges on *.* to root@'%' identified by 'centosmysqla#';
mysql>flush privileges;
mysql>quitsql

參考選項:Mysql 優化,在[mysqld]配置參數下面添加下面幾行(大概37行下面),根據服務器不一樣配置進行不一樣的設置
max_allowed_packet = 500M  //先找到這行內容,修改爲500
innodb_file_per_table
log-bin-trust-function-creators=1
skip-name-resolv//禁用DNS解析
sync-binlog=1
lower_case_table_names=1
max_connections = 1500 (默認100)
log-error=/data/mysql/log/mysql.err.log  //指定錯誤日誌位置
max_heap_table_size = 256M
join_buffer_size = 128M
thread_cache_size = 1200  //線程緩存
thread_concurrency = 4  //設置成cpu數x2,只有一個設置2
thread_stack = 256K  
query_cache_type = 1  //指定是否使用查詢緩衝,能夠設置爲0、一、2,該變量是SESSION級的變量
query_cache_size = 512M  //查詢緩衝大小
query_cache_limit = 4M  //單個查詢緩衝大小。默認1M
query_cache_min_res_unit = 4k    //指定分配緩衝區空間的最小單位,缺省爲4K        
tmp_table_size = 256M      
myisam_sort_buffer_size = 64M
back_log = 1024//設定緩存隊列數,節省鏈接開銷
long_query_time = 3  
open_files_limit    = 10240
interactive_timeout = 120
wait_timeout = 120
external-locking = FALSE//禁用文件系統外部鎖
table_cache = 1024//高速緩存大小,4G內存設置爲2048
修改配置文件裏下面的參數,去掉前面的#
innodb_buffer_pool_size = 2048M (默認16M,能夠爲系統內存50%~70%)
innodb_additional_mem_pool_size = 256M (默認2M)
innodb_log_file_size = 512M    (默認5M,innodb_buffer_pool_size的四分之一)
innodb_log_buffer_size = 16M  //設置位每秒的數據量
innodb_max_dirty_pages_pct = 90
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 0
innodb_flush_method=O_DIRECT
innodb_open_files=4096
innodb_lock_wait_timeout = 120
innodb_file_per_table=1
 
:wq //保存退出
service mysqld restart數據庫


4 apache安裝
cd ../httpd-2.2.19
cd srclib/apr
./configure --prefix=/usr/local/apr;make;make installapache

cd ../apr-util
./configure \
--prefix=/usr/local/apr-util \
--with-apr=/usr/local/apr/ \
--with-mysql=/usr/local/mysql;
make;make installvim

cd ../.. 
mkdir -p /usr/local/apache
./configure \
--prefix=/usr/local/apache \
--enable-mods-shared=all \
--with-mysql=/usr/local/mysql \
--enable-deflate \
--enable-cache \
--enable-file-cache \
--enable-mem-cache \
--enable-disk-cache \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-util/ \
--enable-rewrite \
--enable-expires \
--enable-authn-dbm \
--enable-vhost-alias \
--with-mpm=worker \
--with-ssl \
--enable-so \
--enable-ssl \
--enable-track-vars \
--with-z \
--disable-ipv6 \
--enable-dav \
make && make install

啓動apahce
/usr/local/apache/bin/apachectl -k start
用瀏覽器查看http://localhost,獲得it works,說明apache已經配置成功了.
中止apache
/usr/local/apache/bin/apachectl -k stop
設爲開機自動啓動
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
vi /etc/rc.d/init.d/httpd
找到:#!/bin/sh
另起一行,增長下面兩行:
#chkconfig:35 85 15
#description: Apache HTTP Server.
chkconfig --add httpd
啓動httpd服務
service httpd start

更改網站根目錄:
vi /usr/local/apache/conf/httpd.conf
查找:
DocumentRoot "/usr/local/apache/htdocs"
改成:
DocumentRoot "/html"

設置管理員郵箱和ServerName:
ServerAdmin zalifei@126.com
ServerName IP:80
創建虛擬主機

在httpd.conf末尾加入如下內容:
<VirtualHost *:80>
    DocumentRoot /html
    ServerName www.example.com
    ErrorLog /var/log/httpd/error.log
    CustomLog /var/log/httpd/access.log combined
    <Directory 「/html」>
        Options FollowSymLinks
        AllowOverride None/all
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

設置語言
查找下面關鍵詞並註釋掉
AddDefaultCharset

找到如下內容並去掉註釋:
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-info.conf
Include conf/extra/httpd-default.conf

service httpd restart 測試


5 安裝PHP[yum install php-snmp net-snmp net-snmp-libs net-snmp-utils net-snmp-devel libmcrypt mhash libevent]

./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-mysql=/usr/local/mysql/ \
--with-pdo-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-zip --enable-sqlite-utf8 --enable-sockets \
--enable-soap --enable-pcntl --enable-mbstring \
--enable-calendar --enable-bcmath \
--enable-exif --with-mhash --with-gd \
--with-png-dir --with-jpeg-dir --with-freetype-dir \
--with-libxml-dir --with-curl --with-curlwrappers \
--with-zlib \
--with-gettext=shared --with-xmlrpc=shared \
--with-libxslt \
--with-libxml-dir \
--with-iconv \
--with-snmp
--enable-gd-native-ttf  \
--disable-debug \
--with-mcrypt \
make && make install

# cp php.ini-development /usr/local/php/lib/php.ini  //拷貝配置文件
編輯/usr/local/php/lib/php.ini文件,date.timezone = 'Asia/Shanghai'
將short_open_tag = Off更改成short_open_tag = On

整合apache和php
vi /usr/local/apache/conf/httpd.conf
找到
LoadModule php5_module modules/libphp5.so
去掉註釋符
找到
AddType application/x-gzip .gz .tgz
在下面添加2行:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
找到
DirectoryIndex index.html
改爲 
DirectoryIndex index.html index.htm index.php

讓Apache 支持rewrite
找到下面的字段:
AllowOverride None
修改成:
AllowOverride All

讓頁面支持gzip

LoadModule php5_module        modules/libphp5.so
以後添加:
<IfModule mod_deflate.c>
DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE css js
</IfModule>

從新啓動Apache
service httpd restart

測試
/usr/local/apache/bin/apachectl configtest
顯示出
Syntax OK
表示正常
默認網站根目錄下創建phpinfo.php文件,輸入如下內容
<?php 
  phpinfo(); 
?>' 
用瀏覽器打開
http://127.0.0.1/phpinfo.php
若是頁面上出現了PHP的版權信息及系統配置狀況,說明你的PHP編譯裝配置確。

注意:1.若是訪問出現錯誤,因爲Linux自帶的安全策略致使的方法以下:
chcon –R –references=/var/www/html /html
setenforce 0
2. httpd restart出現錯誤 Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName 
這個問題應該是沒有在 /etc/httpd/conf/httpd.conf 中設定 ServerName 
vi /etc/httpd/conf/httpd.conf
找到 ServerName 可能已經被註解了,這時只要將註解符號拿掉,再取個適當的名稱便可解決!

在默認網站根目錄下創建dbtest.php,輸入如下內容
<?php 
$link=mysql_connect ('localhost','root','CentOSmysqla#');
if(!$link) echo "fail"; 
else echo "success"; 
mysql_close(); 
?>
chmod 755 /www/default/dbtest.php
http://127.0.0.1/dbtest.php
如頁面顯示success說明mysql+php配置正確

好了,到此基本服務架構以基本完成,繼續努力!!

相關文章
相關標籤/搜索