天天看點

使用源代碼編譯安裝基于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...

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!已經可以通路了。

本文轉自 490999122 51CTO部落格,原文連結:http://blog.51cto.com/lyp0909/521611,如需轉載請自行聯系原作者