linux下配置apache2+php5+mysql5

來源:互聯網
上載者:User

首先我在 /root 目錄下建了一個 soft 檔案夾來儲存我要安裝的源碼包
mkdir /root/soft
cd /root/soft

先找到 apache php mysql proftpd 源碼包下載的URL地址
請瀏覽
http://www.apache.org
http://www.php.net
http://www.mysql.com
http://www.proftpd.org/

第一步:安裝apache
註:目前的目錄為/root/soft ,
目錄下有
httpd-2.0.55.tar.gz, php-5.0.5.tar.gz
等二進位源碼包
#號代表為root 根許可權,#後是輸入的一條命令

執行下列命令
解壓源碼包
# tar -zxf httpd-2.0.55.tar.gz
進入安裝目錄
# cd httpd-2.0.55
配置apache安裝資訊
# ./configure --prefix=/usr/local/apache --enable-modules=so --enable-rewrite
執行make安裝
# make; make install
安裝完後
# vi /usr/local/apache/conf/httpd.conf
找到 prefork.c 下的
MaxClients 150
改為
ServerLimit 2000
MaxClients 1000
apache預設工作在prefork.c模式下,並發進程為150,超過後就無法訪問,150是遠遠不夠的,所以這裡按自己網站的需求改, 如1000
由於apache預設最大並發進程是 256 所以要先設定 ServerLimit 2000 將伺服器可設的最大並發數設為2000, 然後再設定最大並發數 MaxClients 1000

找到 #ServerName www.example.com:80 在其下設定 ServerName 如下
ServerName www.mysite.com
基中 www.mysite.com 為你網站名,也可用IP代替
找到 DocumentRoot "/usr/local/apache/htdocs"
設定你的 WEB 伺服器的根目錄 如
DocumentRoot "/myweb"
找到 DirectoryIndex index.html index.html.var 改為
DirectoryIndex index.html index.php index.htm
找到 ForceLanguagePriority Prefer Fallback 在其下加上
AddDefaultCharset gb2312
改完後儲存(vi 的用法請查 Linux vi 命令)
用下面命令啟動WEB伺服器
# /usr/local/apache/bin/apachectl start
查看自己的網站是否正常 http://www.mysite.com 也可用IP
用 # /usr/local/apache/bin/apachectl stop 可停止服務

安裝MYSQL
# tar -zxf mysql-standard-5.0.15-linux-i686.tar.gz
# cp -r mysql-standard-5.0.15-linux-i686 /usr/local/mysql
# vi /usr/local/mysql/support-files/my-medium.cnf
在後面加上
max_connections = 1000
log-slow-queries
long_query_time = 5
注 max_connections 為允許的最大串連數
log-slow-queries 開啟低速查詢日誌
long_query_time 低速查詢的秒數(運行一句sql達到此時間記錄在日誌裡)
然後COPY 它為 /etc/my.cnf 檔案
# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
添加mysql使用者及使用者組
# groupadd mysql
# useradd -g mysql mysql
修改mysql目錄許可權
# chown -R root /usr/local/mysql
# chgrp -R mysql /usr/local/mysql
# chown -R mysql /usr/local/mysql/data
產生mysql系統資料庫
# /usr/local/mysql/scripts/mysql_install_db --user=mysql&
啟動mysql服務
# /usr/local/mysql/bin/mysqld_safe --user=mysql&
如出現 Starting mysqld daemon with databases from /usr/local/mysql/data
代表正常啟動mysql服務了, 按Ctrl + C 跳出
修改 mysql 的 root 密碼
# /usr/local/mysql/bin/mysqladmin -u root -p password 123456
斷行符號出現 Enter password: 最開始密碼預設為空白 繼續斷行符號即可
123456 即為你的新密碼

安裝GD庫(讓PHP支援GIF,PNG,JPEG)
首先下載 jpeg6,libpng,freetype 並安裝模組
wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz
wget http://nchc.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.8.tar.gz
wget http://keihanna.dl.sourceforge.net/sourceforge/freetype/freetype-2.1.10.tar.gz
wget http://www.boutell.com/gd/http/gd-2.0.33.tar.gz

安裝 jpeg6
建立目錄
# mkdir /usr/local/jpeg6
# mkdir /usr/local/jpeg6/bin
# mkdir /usr/local/jpeg6/lib
# mkdir /usr/local/jpeg6/include
# mkdir /usr/local/jpeg6/man
# mkdir /usr/local/jpeg6/man/man1
# cd /root/soft
# tar -zxf jpegsrc.v6b.tar.gz
# cd jpeg-6b
# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
# make; make install

安裝libpng
# cd /root/soft
# tar -zxf libpng-1.2.8.tar.gz
# cd libpng-1.2.8
# cp scripts/makefile.std makefile
# make; make install

安裝 freetype
# cd /root/soft
# tar -zxf freetype-2.1.10.tar.gz
# cd freetype-2.1.10
# ./configure --prefix=/usr/local/freetype
# make;make install

安裝最新的GD庫
# cd /root/soft
# tar -zxf gd-2.0.33.tar.gz
# cd gd-2.0.33
# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6/ --with-png --with-zlib --with-freetype=/usr/local/freetype/
# make; make install

安裝最新的Curl庫
# cd /root/soft
# wget http://curl.haxx.se/download/curl-7.15.0.tar.gz
# tar -zxf curl-7.15.0.tar.gz
# ./configure --prefix=/usr/local/curl
# make; make install

安裝PHP

由於php5需libxml2的支援, 所以先下載並安裝libxml2
# cd /root/soft
# wget http://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/libxml2-2.6.19.tar.gz
# tar -zxf libxml2-2.6.19.tar.gz
# cd libxml2-2.6.19
# ./configure --prefix=/usr/local/libxml2
# make; make install

安裝 libxslt
# cd /root/soft
# wget http://ftp.gnome.org/pub/GNOME/sources/libxslt/1.1/libxslt-1.1.15.tar.gz
# tar -zxf libxslt-1.1.15.tar.gz
# cd libxslt-1.1.15
# ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
# make; make install

# tar -zxf php-5.0.5.tar.gz
# cd php-5.05
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql/ --with-curl=/usr/local/curl --enable-ftp --with-libxml-dir=/usr/local/libxml2 --with-expat-dir=/usr/lib --enable-soap --with-xsl=/usr/local/libxslt --enable-xslt --with-gd=/usr/local/gd2/ --with-jpeg-dir=/usr/local/jpeg6/ --with-zlib-dir=/usr/lib --with-png --with-freetype-dir=/usr/local/freetype
# make
# make install

其中./configure 後的
--prefix=/usr/local/php
--with-apxs2=/usr/local/apache/bin/apxs
--with-mysql=/usr/local/mysql/
--with-libxml-dir=/usr/local/libxml2
是必要的選項

--with-gd=/usr/local/gd2/
--with-jpeg-dir=/usr/local/jpeg6/
--with-png
--with-zlib-dir=/usr/lib
--with-freetype-dir=/usr/local/freetype
這是讓PHP支援GD庫的配置選項

--with-curl=/usr/local/curl 支援CURL庫
--enable-ftp 開啟FTP庫函數支援

--enable-soap --with-xsl=/usr/local/libxslt --enable-xslt
讓PHP支援SOAP, 上面這些一般用得少, 可以去掉

配置 httpd.conf 讓apache支援PHP
# vi /usr/local/apache/conf/httpd.conf
找到 AddType application/x-gzip .gz .tgz 在其下添加如下內容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

重啟apache
# /usr/local/apache/bin/apachectl restart
在你Web目錄裡建一內容為 <? phpinfo(); ?> PHP檔案, 輸入URL地址查看PHP配置是否正確

安裝 phpmyadmin
下載
# cd /root/soft
# wget http://nchc.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-2.6.4-pl3.tar.gz
# tar -zxf phpMyAdmin-2.6.4-pl3.tar.gz
# vi phpMyAdmin-2.6.4-pl3/config.inc.php
找到 $cfg['Servers'][$i]['auth_type'] = 'config'; 將config 改為 http
儲存後
mv phpMyAdmin-2.6.4-pl3 /你的phpmyadmin目錄
關於mysql4.1-4移植4.0舊資料庫中文亂碼問題的解決方案
進入phpmyadmin管理
建立你資料庫名並選上 gb2312_bin 的編碼
然後匯入你先前備份好的SQL檔案, 匯入時選擇 檔案的字元集:gb2312
完成後就OK了
注: PHP串連mysql4.1和5.0 資料庫後需指定字元集 需執行如 mysql_query("SET NAMES 'gb2312' ");
否則會產生中文亂碼問題! 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.