Linux下PHP開發環境搭建-php,mysql,apache

來源:互聯網
上載者:User
原文url: http://blog.sina.com.cn/s/blog_4b029ef301007xky.html

軟體安裝列表

zlib.

mysql

php

http

libpng

freetype

jpegsrc

libxml

我都採用原始碼安裝,因為這樣比較靈活,能自己指定安裝目錄並配置參數,或者進行特性的選取與最佳化。

說明:所有的包都安裝在/data目錄下。

(1):
安裝zlib
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/data/zlib
make
make install
然後在/etc/ld.so.conf中添加
/data/zlib/lib
儲存,執行ldconfig -v
(2)mysql installing.
#groupadd mysql
#useradd -g mysql mysql
# vi /home/mysql/.bash_profile
添加
export PATH=$PATH:/data/mysql/bin
儲存後,進入安裝包所在目錄,先安裝Mysql
解壓縮:
tar -zxvf mysql-5.0.45.tar.gz
cd mysql-5.0.45

接著要進行configure配置,在以前我只是制定了prefix沒有設定字型編碼,結果PHP後來不支援漢字編碼,只好重新安裝
才發現這個問題要注意,而且我們已經安裝了zlib,就可以給mysql來指明zlib的位置
[root@cme_box mysql-5.0.45]# ./configure --prefix=/data/mysql --with-zlib-dir=/data/zlib/ --with-charset=utf8 --with-extra-charsets=gbk,gb2312,utf8
make
make install
同樣,在/etc/ld.so.conf中添加一行
/data/mysql/lib/mysql
儲存,執行ldconfig -v
#./scripts/mysql_install_db
#chown -R root /data/mysql
#chown -R mysql /data/mysql/var
#chgrp -R mysql /data/mysql
# cp support-files/my-medium.cnf /etc/my.cnf
#/data/mysql/bin/mysqld_safe &
下來再init.d中設定mysql的自啟動。
# cp support-files/mysql.server /etc/init.d/mysql
cd /etc/rc3.d
ln -s ../init.d/mysql S85mysql
ln -s ../init.d/mysql K85mysql
cd ../rc5.d/
ln -s ../init.d/mysql S85mysql
ln -s ../init.d/mysql K85mysql
cd ../init.d
chmod 755 mysql
然後reboot查看mysql是否啟動。
(3)安裝apache
tar -zxvf httpd-2.2.6.tar.gz
cd httpd-2.2.6
./configure --prefix=/data/httpd/ --enable-so --enable-cgi --with-z=/data/zlib
make
make install
cp /data/httpd/bin/apachectl /etc/init.d/httpd
cp: overwrite `/etc/init.d/httpd'? y
cd /etc/rc3.d
rm -fr K15httpd
cd /etc/rc5.d
rm -fr K15httpd
cd /etc/rc3.d
ln -s ../init.d/httpd K85httpd
ln -s ../init.d/httpd S85httpd
cd /etc/rc5.d
ln -s ../init.d/httpd K85httpd
ln -s ../init.d/httpd S85httpd
chmod 755 /etc/init.d/httpd
(4)安裝GD庫
首先,我們要安裝各個圖形庫的支援,包括libpng, libjpeg,ttf等。
1)libpng
tar -zxvf libpng-1.2.23.tar.gz
./configure --prefix=/data/libpng
make
make install
然後將libpng的路徑(/data/libpng/lib)加到/etc/ld.so.conf下,執行ldconfig -v
能看到
/data/libpng/lib:
libpng.so.3 -> libpng.so.3.23.0
libpng12.so.0 -> libpng12.so.0.23.0
這一項。說明安裝成功。
2)freetype
tar -zxvf freetype-2.1.10.tar.gz
cd freetype-2.1.10
./configure --prefix=/data/freetype
make
make install
then add the path of freetype(/data/freetype/lib) to /etc/ld.so.conf and run command "ldconfig -v",we can get
the output
/data/freetype/lib:
libfreetype.so.6 -> libfreetype.so.6.3.8
3)jpeg
tar -zxvf jpegsrc.v6b.tar.gz
./configure --prefix=/data/jpeg --enable-shared
make
make install
提示:/usr/bin/install: cannot create regular file `/data/jpeg/include/jconfig.h': No such file or directory
nnd,在CU上查到了,原來是安裝程式沒有許可權在/data下自己建立目錄,需要手動建立
當我建立include目錄後,提示lib目錄不存在,建立lib目錄後,又提示man/man1目錄不存在,那就挨個建立吧。
cd /data/jpeg
mkdir include lib man bin
mkdir man/man1
然後make install就OK了。
然後在/etc/ld.so.conf中添加一行 /data/jpeg/lib,執行命令 ldconfig -v,可以看到
/data/jpeg/lib:
libjpeg.so.62 -> libjpeg.so.62.0.0
4)安裝fontconfig

tar -zxvf fontconfig-2.5.0.tar.gz

cd fontconfig-2.5.0
./configure --prefix=/data/fontconfig --with-freetype-config=/data/freetype/bin/freetype-config

make

make install

cd /data/fontconfig/lib

pwd >> /etc/ld.so.conf

ldconfig -v | grep fontconfig

安裝GD
tar -zxvf gd-2.0.33.tar.gz
./configure --prefix=/data/gd --with-png=/data/libpng --with-freetype=/data/freetype --with-jpeg=/data/jpeg --with-fontconfig=/data/fontconfig

(在以前沒有加fontconfig的時候,會報這個錯,但是2008-12-15日加了fontconfig後,卻沒有報錯,一路make,make install很順利,不過還是要寫上,以防再遇到:make時系統提示找不到png.h,手動修改makefile
在CPPFLAGS = 行末加上 -I/data/libpng/include
在CFLAGS = -g -O2 行末加上
-DHAVE_JPEG -DHAVE_LIBTTF -DHAVE_PNG
修改為
CFLAGS = -g -O2 -DHAVE_JPEG -DHAVE_LIBTTF -DHAVE_PNG
)

然後
make
make install
(4)安裝libxml
tar -zxvf libxml2-2.6.11.tar.gz
./configure --prefix=/data/xml --with-zlib=/data/zlib
make
make install
然後把xml的庫路徑【 /data/xml/lib/】添加到/etc/ld.so.conf檔案中儲存後執行ldconfig -v
看到
/data/xml/lib:
libxml2.so.2 -> libxml2.so.2.6.11
添加gd的庫路徑[/data/gd/lib]到etc/ld.so.conf檔案,執行ldconfig -v
(5)安裝php
tar -zxvf php-5.2.4.tar.gz
./configure --prefix=/data/php --with-zlib-dir=/data/zlib --with-mysql=/data/mysql --with-apxs2=/data/httpd/bin/apxs --with-config-file-path=/data/php --with-gd --enable-sysvmsg --enable-sockets --enable-sysvshm --enable-sysvsem --enable-gd-native-ttf --with-ttf=/usr/lib --with-jpeg-dir=/data/jpeg --with-png-dir=/data/libpng --with-iconv --with-libxml-dir=/data/xml
make
make install

cp php.ini-dist /data/php/php.ini


(6)在http.conf中設定php支援。
vi /data/httpd/conf/http.conf

# Example:
# LoadModule foo_module modules/mod_foo.so
LoadModule php5_module modules/libphp5.so
下添加一行
AddType application/x-httpd-php .php
並將

DirectoryIndex index.html

修改為

DirectoryIndex index.php index.html

設定預設首頁為index.php
然後在/data/php/php.ini中添加一行
default_charset = "gb2312"
儲存
service httpd restart
進行測試
在 /data/httpd/htdocs/下建立index.php
寫入內容為 儲存
開啟頁面輸入url地址
http://192.168.x.x/
就能看到phpinfo的輸出了。
如果想修改http的預設根目錄,或者說你不想把自己的檔案放在/data/httpd/htdoc目錄下
可以修改httpd.conf中的
DocumentRoot "/data/httpd/htdoc"為
DocumentRoot "/cme/web"
和為

然後還要給新的目錄加上能執行的許可權
chmod +x /cme
chmod +x /cme/web
重啟服務 service httpd restart
就OK了。

  • 聯繫我們

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