使用源代码编译安装基于LAMP的网站架构

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

先检查编译环境

[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!已经可以访问了。










本文转自 490999122 51CTO博客,原文链接:http://blog.51cto.com/lyp0909/521611,如需转载请自行联系原作者
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
30天前
|
XML 运维 前端开发
LAMP架构调优(四)——资源压缩传输
LAMP架构调优(四)——资源压缩传输
14 2
|
30天前
|
运维 Linux Apache
LAMP架构调优(二)——修改Apache运行用户
LAMP架构调优(二)——修改Apache运行用户
197 1
|
1月前
|
运维 Linux Apache
LAMP架构调优(一)——隐藏Apache版本信息
LAMP架构调优(一)——隐藏Apache版本信息
16 1
|
1月前
|
运维 Linux Apache
LAMP架构调优(二)——修改Apache运行用户
LAMP架构调优(二)——修改Apache运行用户
12 0
|
7月前
|
关系型数据库 MySQL PHP
LAMP架构及搭建LAMP+Discuz论坛
LAMP架构及搭建LAMP+Discuz论坛
123 0
|
24天前
|
运维 Linux Apache
LAMP架构调优(三)——模块的安装与调用
LAMP架构调优(三)——模块的安装与调用
9 0
|
25天前
|
运维 Linux Apache
LAMP架构调优(十)——Apache禁止指定目录PHP解析与错误页面优化
LAMP架构调优(十)——Apache禁止指定目录PHP解析与错误页面优化
197 2
|
28天前
|
运维 Linux Apache
LAMP架构调优(九)——Apache Rewrite功能实战
LAMP架构调优(九)——Apache Rewrite功能实战
12 1
|
28天前
|
运维 安全 Linux
LAMP架构调优(八)——Apache Worker模式调优
LAMP架构调优(八)——Apache Worker模式调优
9 0
|
29天前
|
缓存 运维 Linux
LAMP架构调优(七)——Apache Prefork模式调优
LAMP架构调优(七)——Apache Prefork模式调优
17 2