歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> Linux文化 >> apache2 php5 mysql5安裝配置

apache2 php5 mysql5安裝配置

日期:2017/2/27 12:00:37   编辑:Linux文化

redhat linux 9下 +++++++++++++++++++++++++++++++++++ 產看更多請浏覽: linux學習筆記 請支持原創,有錯誤請指正! +++++++++++++++++++++++++++++++++++ apache2.2.0+php5.1.2+mysql5.0.21+gd配置,安裝GD庫(讓PHP支持GIF,PNG,JPEG) 其中安裝中見到的問題見文章最後!

一:准備軟件包,存放/home/xiutuo/software/目錄下。

主要軟件包, (這裡沒有選擇mysql-standard-5.0.20-linux-i686.tar.gz, 呆會再說明原因。) httpd-2.2.0.tar.gz mysql-max-5.0.21-linux-i686-glibc23.tar.gz php-5.1.2.tar.gz

安裝php所需的軟件包 (其中libxml2是安裝php5必須的,為什麼還需要perl呆會說明原因。) libxml2-2.6.19.tar.gz libxslt-1.1.15.tar.gz ActivePerl-5.8.8.817-i686-linux-2.2.17-gcc-257965.rpm curl-7.15.0.tar.gz

GD庫所需要軟件包 (有人說PHP源碼包裡自帶了GD2.0.28和zlib, 只要安裝GD的三個支持包:jpg,png和freetype,但是我們還是下載) gd-2.0.33.tar.gz freetype-2.1.10.tar.gz jpegsrc.v6b.tar.gz libpng-1.2.8.tar.gz zlib-1.2.3.tar.gz

相關下載 (根據自己的linux版本下載相應的包, 查看操作系統版本: # uname -r )

http://ftp.gnome.org/pub/GNOME/s ... bxml2-2.6.19.tar.gz http://ftp.gnome.org/pub/GNOME/s ... bxslt-1.1.15.tar.gz http://downloads.activestate.com ... .638-i686-linux.rpm http://curl.haxx.se/download/curl-7.15.0.tar.gz

http://www.boutell.com/gd/http/gd-2.0.33.tar.gz http://keihanna.dl.sourceforge.n ... etype-2.1.10.tar.gz http://www.ijg.org/files/jpegsrc.v6b.tar.gz http://nchc.dl.sourceforge.net/s ... libpng-1.2.8.tar.gz http://www.zlib.net/zlib-1.2.3.tar.gz

把以上所有軟件包下載到:/home/xiutuo/software/目錄下。

二:安裝apache2。 # cd /home/xiutuo/software/ 進入目錄/home/xiutuo/software/ # tar -zvxf httpd-2.2.0.tar.gz 解壓httpd-2.2.0.tar.gz # cd httpd-2.2.0 進入httpd-2.2.0目錄 # mkdir -p /usr/local/apache2 生成/usr/local/apache2目錄 # ./configure --prefix=/usr/local/apache 或者 # ./configure --prefix=/usr/local/apache --enable-modules=so --enable-rewrite # make; make install 安裝apache # vi /usr/local/apache/conf/httpd.conf #ServerName www.example.com:80 在其下增加 ServerName www.xiutuo.com:80 保存退出,現在就這麼簡單配置apache。

# /usr/local/apache/bin/apachectl -k start 啟動apahce, 用浏覽器查看http://www.xiutuo.com,得到it works,說明apache已經配置成功了。 # /usr/local/apache/bin/apachectl -k stop 停止apache。

三:安裝mysql # cd /home/xiutuo/software/ # tar -zvxf mysql-max-5.0.21-linux-i686-glibc23.tar.gz # mkdir -p /usr/local/mysql (省略也可) # cp -r mysql-max-5.0.21-linux-i686-glibc23.tar.gz /usr/local/mysql # 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"

四:安裝GD庫(讓PHP支持GIF,PNG,JPEG) a.安裝 jpeg6 建立目錄: # mkdir -p /usr/local/jpeg6 # mkdir -p /usr/local/jpeg6/bin # mkdir -p /usr/local/jpeg6/lib # mkdir -p /usr/local/jpeg6/include # mkdir -p /usr/local/jpeg6/man # mkdir -p /usr/local/jpeg6/man1 # mkdir -p /usr/local/jpeg6/man/man1

# cd /home/xiutuo/software/ # tar -zvxf jpegsrc.v6b.tar.gz # cd jpeg-6b # ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static # make; make install

b.安裝libpng # cd /home/xiutuo/software/ # tar -zvxf libpng-1.2.8.tar.gz # cd libpng-1.2.8 # cp scripts/makefile.std makefile # make; make install

c.安裝 freetype # cd /home/xiutuo/software/ # tar -zvxf freetype-2.1.10.tar.gz # cd freetype-2.1.10 # mkdir -p /usr/local/freetype # ./configure --prefix=/usr/local/freetype # make;make install

d.:安裝zlib # cd /home/xiutuo/software/ #tar -zxvf zlib-1.2.3.tar.gz #cd zlib.1.2.3 # ./configure # make;make install

e.安裝GD庫 # cd /home/xiutuo/software/ # tar -zvxf gd-2.0.33.tar.gz # mkdir -p /usr/local/gd2 # cd gd-2.0.33 # ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6/ --with-png=/usr/local/lib/ --with-zlib=/usr/local/lib/ --with-freetype=/usr/local/freetype/ # make; make install

e.安裝Curl庫 # cd /home/xiutuo/software/ # tar -zxf curl-7.15.0.tar.gz # mkdir -p /usr/local/curl # ./configure --prefix=/usr/local/curl # make; make install

五:安裝php5,php5必須有libxml2支持! a.安裝libxml2 # cd /home/xiutuo/software/ # tar -zxf libxml2-2.6.19.tar.gz # cd libxml2-2.6.19 # mkdir -p /usr/local/libxml2 # ./configure --prefix=/usr/local/libxml2 # make; make install

b.安裝 libxslt(可選安裝,你可以不安裝) # cd /home/xiutuo/software/ # tar -zxf libxslt-1.1.15.tar.gz # mkdir -p /usr/local/libxslt # cd libxslt-1.1.15 # ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2 # make; make install

c.安裝php5 # cd /home/xiutuo/software/ # tar -zvxf php-5.1.2.tar.gz # mkdir -p /usr/local/php # 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/local/lib/ --with-png=/usr/local/lib/ --with-freetype-dir=/usr/local/freetype/ # make # make install # cp php.ini-dist /usr/local/php/lib/php.ini (別忘記了呵呵)

其中./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=/usr/local/lib --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, 上面這些一般用得少, 可以去掉

六:重新配置apache2讓他支持php。

配置 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 在htdocs目錄裡建一內容為 PHP文件, 輸入URL地址查看PHP配置是否正確

ok,web環境apache2+mysql5+php5就介紹到這裡。 更詳細的apache2的配置和mysql配置和php.ini的配置參考相應文檔。 -------------------------------------------------------- 安裝時候遇到的問題:

由於本人的系統是redhat9,自定義安裝了php,mysql,apache。 所以在安裝最新的php,mysql,apache版本時候,本人對相關的rpm進行了 卸載,忽略依賴關系強制卸載apache;由於php,mysql與perl的bt依賴關系, 一氣之下刪除了所有的相關文件。

問題

1.當你看到mysql有很多版本,如: mysql-max-5.0.21-linux-i686-glibc23.tar.gz和 mysql-max-5.0.21-linux-i686.tar.gz 這倆個到底選哪個呢,請你使用如下命令來決定 # rpm -qa | grep glibc glibc-kernheaders-2.4-8.10 glibc-common-2.3.2-11.9 glibc-2.3.2-11.9 glibc-devel-2.3.2-11.9 如果出現以上信息,請選擇mysql-max-5.0.21-linux-i686-glibc23.tar.gz版本

2:編譯php時出現

./configure: /usr/local/apache2/bin/apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directory 這是找不到perl解釋器的緣故。 修改/usr/local/apache2/bin/apxs文件中: /replace/with/path/to/perl/interpreter 把他替換成perl所在的路徑如/opt/ActivePerl-5.8/bin/perl, (如果你下載的是active perl5.8的rpm,他默認安裝路徑是/opt/ActivePerl-5.8/bin/perl)

3.安裝了perl後,發現所有的文本編輯器都不能用了。 運行vi或者gedit時候,提示找不到libperl.so 到perl的安裝目錄下找一個libperl.so放到/usr/lib目錄下就解決問題了 我的libperl.so在/opt/ActivePerl-5.8/lib/5.8.8/i686-linux-thread-multi-CORE/目錄下。 如果不知道libperl.so在什麼地方,可以用 # locate libperl.so 查找,或者用find命令

4.當我使用mysql-standard-5.0.20,編譯php時出現mysql錯誤:

checking for mSQL support... no checking for MSSQL support via FreeTDS... no checking for MySQL support... yes checking for specified location of the MySQL UNIX socket... no checking for MySQL UNIX socket location... /tmp/mysql.sock checking for mysql_close in -lmysqlclient... no checking for mysql_error in -lmysqlclient... no configure: error: mysql configure failed. Please check config.log for more information.

網查找說:安裝PHP的時候沒有指定一下mysql的安裝目錄。但是我已經指定了,所以這個說法是錯誤的,其實主要原因是 mysql-level沒有裝,也就是mysql的版本不對,應該換 mysql-max-5.0.21版本(包含所有mysql相關內容的軟件包)

5.編譯php時出現 configure: error: freetype2 not found! 沒有安裝freetype-level

configure: error: libpng.(a|so) not found. 沒有安裝libpng-devel

6忘了mysql的root口令怎麼辦 # /usr/local/mysql/support-files/mysql.server stop # mysqld_safe --skip-grant-tables & # mysqladmin -u user password 'newpassword' # mysqladmin flush-privileges

Copyright © Linux教程網 All Rights Reserved