使用源代碼編譯安裝基於LAMP的網站架構

先檢查編譯環境

[root@station39 ~]# yum grouplist

需要安裝的幾組工具

Development Libraries (開發庫)

Development Tools (開發工具)

Legacy Software Development (傳統軟件開發工具)

X Software Development(有些組件在編譯過程中要依賴於圖形界面,需要用到這裏提供的庫)

PS:如果某些軟件基於圖形界面開發,就要考慮此軟件是基於KDE開發還是GNOME開發。如果是基於KDE開發,一般使用C++語言,就要調用QT的庫 。所對應的開發組件KDE Software Development。如果是基於GNOME開發,一般使用C語言,依賴於GTK2。所對應的開發組件GNOME Software Development。

構建編譯環境,我們這裏不需要用到圖形界面,所以我只需三個開發組件,使用yum安裝:

[root@station39 ~]# yum -y groupinstall "Development Libraries" "Development Tools" "Legacy Software Development"

環境構建完畢之後我們就可以編譯apache,mysql,php的源碼包。

由於mysql的編譯過程比較漫長,所以這裏我們使用mysql綠色安裝方式。

PS:apache目前官方正在維護的版本有三個:1.3系列 (最新版1.3.42)、2.0系列(最新版2.0.64)、 2.2系列(最新版2.2.17)。

這裏所要使用到的包我們已經準備好了:

[root@station39 LAMP]# ls

httpd-2.2.17.tar.bz2 mysql-5.1.50-linux-i686-glibc23.tar.gz php-5.3.5.tar.bz2

先安裝mysql,這裏使用綠色安裝方式,直接解壓到/usr/local重命名爲mysql下即可使用。

[root@station39 LAMP]# tar zxvf mysql-5.1.50-linux-i686-glibc23.tar.gz -C /usr/local

[root@station39 LAMP]# cd /usr/local

[root@station39 local]# ls

bin etc games include lib libexec mysql-5.1.50-linux-i686-glibc23 sbin share src

這裏需要重命名mysql,但是不建議這麼做,我們可以做一個軟鏈接過去

[root@station39 local]# ln -sv mysql-5.1.50-linux-i686-glibc23 mysql

[root@station39 local]# ll

lrwxrwxrwx 1 root root 31 Mar 10 12:00 mysql -> mysql-5.1.50-linux-i686-glibc23

建議使用前先閱讀INSTALL-BINARY文件。

[root@station39 mysql]# groupadd -g 306 -r mysql

[root@station39 mysql]# useradd -g mysql -u 306 -r -s /sbin/nologin -M mysql

[root@station39 mysql]# id mysql

uid=306(mysql) gid=306(mysql) groups=306(mysql) context=root:system_r:unconfined_t:SystemLow-SystemHigh

[root@station39 mysql]# chown -R mysql:mysql .

初始化mysql數據庫

[root@station39 mysql]# scripts/mysql_install_db --user=mysql

Installing MySQL system tables...

OK

Filling help tables...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password 'new-password'

./bin/mysqladmin -u root -h station39.example.com password 'new-password'

Alternatively you can run:

./bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!

[root@station39 mysql]# chown -R root .

[root@station39 mysql]# chown -R mysql data/

啓動mysql

[root@station39 mysql]# bin/mysqld_safe --user=mysql &

[root@station39 mysql]# netstat -ntlp | grep 3306

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 23423/mysqld

將啓動命令加入到環境變量裏邊

[root@station39 mysql]# vim /etc/profile

PATH=$PATH:/usr/local/mysql/bin //**line 44

[root@station39 mysql]# source /etc/profile

安裝完畢之後默認主配置文件是不存在的,但是在support-files 目錄下有my.cnf的主配置文件的模板

[root@station39 support-files]# ls

binary-configure config.small.ini my-innodb-heavy-4G.cnf my-small.cnf mysql.server

config.huge.ini magic my-large.cnf mysqld_multi.server ndb-config-2-node.ini

config.medium.ini my-huge.cnf my-medium.cnf mysql-log-rotate

[root@station39 support-files]# cp my-large.cnf /etc/my.cnf

mysql.server 是mysql的啓動腳本,複製到/etc/init.d目錄下

[root@station39 support-files]# cp mysql.server /etc/init.d/mysqld

加入到chkconfig列表中

[root@station39 support-files]# chkconfig --add mysqld

[root@station39 support-files]# chkconfig --list mysqld

mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

導出mysql的庫文件

[root@station39 support-files]# vim /etc/ld.so.conf.d/mysql.conf

/usr/local/mysql/lib

重新讀取一下庫文件

[root@station39 support-files]# ldconfig -v | grep mysql

導出mysql頭文件,這裏我們建立一個軟鏈接

[root@station39 support-files]# ln -sv /usr/local/mysql/include /usr/include/mysql

OK!至此mysql已經安裝完成!下面開始安裝httpd。

[root@station39 support-files]# cd /root/LAMP/

[root@station39 LAMP]# tar jxvf httpd-2.2.17.tar.bz2

[root@station39 LAMP]# cd httpd-2.2.17

[root@station39 httpd-2.2.17]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-ssl --enable-track-vars --with-z

[root@station39 httpd-2.2.17]# make

[root@station39 httpd-2.2.17]# make install

apache 啓動腳本:/usr/local/apache/bin/apachectl

將啓動命令加入到環境變量裏邊

[root@station39 bin]# vim /etc/profile

PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache/bin

[root@station39 bin]# source /etc/profile

PHP安裝

[root@station39 bin]# cd /root/LAMP/

[root@station39 LAMP]# tar jxvf php-5.3.5.tar.bz2

[root@station39 LAMP]# cd php-5.3.5

[root@station39 php-5.3.5]# yum install freetype-devel libpng-devel

[root@station39 php-5.3.5]#./configure --prefix=/usr/local/php--with-apx2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=mysqlnd --enable-mbstring=all

[root@station39 php-5.3.5]# make

[root@station39 php-5.3.5]# make install

環境已經搭建完成,我們來測試一下:

[root@station39 htdocs]# cd /usr/local/apache/htdocs

[root@station39 htdocs]# mv index.html index.php

[root@station39 htdocs]# vim index.php

<html><body><h1>It works!</h1></body></html>

<?php

phpinfo();

?>

編輯 /etc/httpd/httpd.conf 文件

DirectoryIndex index.php index.html //**line 166

AddType application/x-httpd-php .php //**line 309

重啓httpd服務

OK!已經可以訪問了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章