使用源代码编译安装基于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!已经可以访问了。

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