LAMP平台源码搭建
实验环境1
2
3
4
# cat /etc/redhat-release
CentOS release 6.6 (Final)
# uname -rn
LAMP 2.6.32-504.el6.x86_64
使用软件
1
2
3
4
5
6
7
8
9
apr-1.5.0.tar.bz2
apr-util-1.5.3.tar.bz2
httpd-2.4.10.tar.bz2
mariadb-5.5.43-linux-x86_64.tar.gz
php-5.4.40.tar.bz2
phpMyAdmin-4.0.5-all-languages.zip
wordpress-3.3.1-zh_CN.zip
xcache-3.2.0.tar.bz2
Discuz_7.2_FULL_SC_UTF8.zip
编译安装httpd2.4以上的版本的httpd依赖于apr,而且apr的版本不能低于1.4,但是系统自带的apr版本不够所以需要安装高版本的apr,还依赖与pcre-devel openssl-devel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
yum -y groupinstall "Development tools""Desktop Platform Development"
yum -y install pcre-devel openssl-devel
tar xf apr-1.5.0.tar.bz2
cd apr-1.5.0
./configure --prefix=/usr/local/apr
make && make install
cd ..
tar xf apr-util-1.5.3.tar.bz2
cd apr-util-1.5.3
./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr
make && make install
cd ..
编译安装httpd
1
2
3
4
5
6
7
tar xf httpd-2.4.10.tar.bz2
cd httpd-2.4.10
./configure --prefix=/usr/local/apache--sysconfdir=/etc/httpd24 --enable-so --enable-ssl
--enable-cgi--enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util/ --enable-modules=most--enable-mpms-shared=all
--with-mpm=event
make && make install
编译参数说明:
--prefix=/usr/local/apache #安装路径
--sysconfdir=/etc/httpd24 #配置文件路径
--enable-so #启用动态模块加载
--enable-ssl #启用ssl功能
--enable-cgi #启用cgi脚本程序支持
--enable-rewrite #启用网页地址重启功能
--with-zlib #支持zlib压缩功能
--with-pcre #支持pcre
--with-apr=/usr/local/apr #设置apr路径
--with-apr-util=/usr/local/apr-util#设置apr-util路径
--enable-modules=most #尽可能多的启用模块
--enable-mpms-shared=all #把所有的mpm功能都做成共享模块
--with-mpm=event #设置mpm模块为event
优化执行路径,让系统可以查找到httpd的命令
1
2
3
4
5
6
# vim/etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
# . /etc/profile.d/httpd.sh
# which httpd
/usr/local/apache/bin/httpd
# hash –r#清除以前系统上记录的httpd搜索记录
设置启动脚本
1
2
3
4
5
6
7
8
9
# cp bin/apachectl/etc/init.d/httpd24
# vim /etc/init.d/httpd24
#!/bin/sh
# chkconfig: 35 85 15 #设置服务识别参数,3、5级别启动,启动顺序85,关闭顺序15
# description: Apache #服务描述信息
# chkconfig --add httpd24
# chkconfig --level 35 httpd24 on
# chkconfig --list httpd24
httpd24 0:off1:off2:off3:on 4:off5:on 6:off
启动服务并且访问验证
1
2
3
# service httpd24 start
# netstat -lnt | grep 80
tcp 0 0 :::80 :::* LISTEN
安装mariadb新建MariaDB用户,并且设置用户为数据目录/mydata/data/的属主和属组
1
2
3
# groupadd -r mysql
# useradd -g mysql -r -s/sbin/nologin -M mysql
# chown -R mysql:mysql/mydata/data/
安装MariaDB并初始化
1
2
3
4
5
6
tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C/usr/local/
cd /usr/local/
ln -sv mariadb-5.5.43-linux-x86_64/ mysql
cd mysql/
chown -R mysql:mysql .
scripts/mysql_install_db --user=mysql --datadir=/mydata/data/ #指定进程用户,和数据目录
为MariaDB提供主配置文件
1
2
3
4
5
# cp support-files/my-large.cnf/etc/my.cnf
# vim /etc/my.cnf
thread_concurrency = 2 #CPU数量乘以2
datadir = /mydata/data #指定数据文件目录
innodb_file_per_table = 1 #设置每表一个表文件
为MariaDB提供启动脚本
1
2
3
4
5
6
# cp support-files/mysql.server/etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# chkconfig --list mysqld
mysqld 0:off1:off2:on 3:on 4:on 5:on 6:off
修改PATH环境变量,让系统直接使用MariaDB相关命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
# . /etc/profile.d/mysql.sh
启动测试
# service mysqld start
Starting MySQL...
# mysql
Welcome to the MariaDB monitor.Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.43-MariaDB-log MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDBCorporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clearthe current input statement.
MariaDB [(none)]>
编译安装php解决依赖关系
1
yum -y install bzip2-devel libmcrypt-devel
编译安装php
1
2
3
4
5
6
7
8
tar xf php-5.4.40.tar.bz2
cd php-5.4.40
./configure --prefix=/usr/local/php--with-mysql=/usr/local/mysql/
--with-mysqli=/usr/local/mysql/bin/mysql_config--with-apxs2=/usr/local/apache/bin/apxs
--enable-mbstring --with-freetype-dir--with-png-dir --with-zlib --with-libxml-dir=/usr/
--enable-xml--enable-sockets --with-mcrypt --with-config-file-path=/etc/php/php.ini
--with-config-file-scan-dir=/etc/php.d
make && make install
编译参数说明:
--prefix=/usr/local/php #php安装位置
--with-mysql=/usr/local/mysql/ #指明mysql安装路径
--with-mysqli=/usr/local/mysql/bin/mysql_config#mysql的访问接口
--with-apxs2=/usr/local/apache/bin/apxs#apache的apx位置
--enable-mbstring #支持多字节文本
--with-freetype-dir #搜索当前系统支持的字体
--with-png-dir #支持png格式的图片
--with-jpeg-dir #支持jpeg格式的图片
--with-zlib #支持zlib压缩
--with-libxml-dir=/usr/ #libxml路径
--enable-xml #支持xml文档的处理
--enable-sockets #启用socket功能
--with-mcrypt #启用mcrypt功能
--with-bz2 #支持with-bz2功能
--with-config-file-path=/etc/php/php.ini#php主配置文件
--with-config-file-scan-dir=/etc/php.d #辅助配置文件
为php提供配置文件
1
2
# mkdir /etc/php
# cp php.ini-production/etc/php/php.ini
编辑apache支持php
1
2
3
4
# vim /etc/httpd24/httpd.conf
AddTypeapplication/x-httpd-php.php
AddTypeapplication/x-httpd-php-source.phps
DirectoryIndexindex.phpindex.html
重启httpd或让其重新载入配置文件即可测试php是否已经可以正常使用
Apache连接php测试
1
2
3
4
# vim/usr/local/apache/htdocs/index.php
<?php
phpinfo();
?>
php连接MariaDB测试
1
2
3
4
5
6
7
8
# vim/usr/local/apache/htdocs/index.php
<?php
$conn=mysql_connect('localhost','root','');
if ($conn)
echo"连接数据库成功";
else
echo"连接数据库失败"
?>
设置虚拟主机编辑主配置文件,注释中心主机,启用虚拟主机选项
1
2
#DocumentRoot "/usr/local/apache/htdocs"
Include /etc/httpd/extra/httpd-vhosts.conf
创建相关页面
1
2
3
4
5
6
7
8
9
# mkdir -p/www/{bbs,phpMyadmin,wordpress}
# tree /www/
/www/
├── bbs
├── phpMyadmin
└── wordpress
# echo bbs > /www/bbs/index.html
# echo wordpress >/www/wordpress/index.html
# echo myadmin >/www/phpMyadmin/index.html
编辑虚拟主机配置文件设置虚拟主机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<VirtualHost *:80>
ServerName bbs.discuz.com
DocumentRoot "/www/bbs"
<Directory "/www/bbs">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog"/var/log/httpd/bbs-error-log"
CustomLog"/var/log/httpd/bbs-access-log" common
</VirtualHost>
<VirtualHost *:80>
ServerName mysql.phpMyadmin.com
DocumentRoot "/www/phpMyadmin"
<Directory"/www/phpMyadmin">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog"/var/log/httpd/phpMyadmin-error-log"
CustomLog"/var/log/httpd/phpMyadmin-access-log" common
</VirtualHost>
<VirtualHost *:80>
ServerName blog.wordpress.com
DocumentRoot "/www/wordpress"
<Directory "/www/wordpress">
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog"/var/log/httpd/wordpress-error-log"
CustomLog"/var/log/httpd/wordpress-access-log" common
</VirtualHost>
验证:客户端修改hosts文件,然后分别访问虚拟主机测试
部署phpMyadmin
1
2
3
4
unzip phpMyAdmin-4.0.5-all-languages.zip
mv phpMyAdmin-4.0.5-all-languages/*/www/phpMyadmin/
cd /www/phpMyadmin/
cp config.sample.inc.php config.inc.php
访问页面出现如下内容表示部署成功
此处不允许空密码登录,而默认安装的MariaDB是管理员是空密码,所以需要手动为MariaDB管理员设置密码
1
2
MariaDB > UPdate user SETPassword=PASSWORD('redhat') WHERE user='root';
MariaDB > FLUSH PRIVILEGES;
访问成功,结果如下所示
论坛部署Discuz连接数据库,创建bbs的库和用户
1
2
MariaDB [(none)]> create database bbsdb;
MariaDB [(none)]> GRANT all ON bbsdb.* TO'runbbs'@'localhost' IDENTIFIED BY 'adm123';
解压程序代码
1
# unzipDiscuz_7.2_FULL_SC_UTF8.zip -d Discuz
解压完成之后出现下面三个目录表示解压成功
1
2
3
4
5
# ls -lh Discuz
total 12K
drwxr-xr-x2root root 4.0K Oct 312012 readme
drwxr-xr-x 12 root root 4.0K Oct 312012 upload
drwxr-xr-x4root root 4.0K Oct 312012 utility
将upload目录上传到web目录下,并且设置httpd的服务用户对指定目录有写权限,否则会报错。
1
2
3
4
# mv Discuz/upload/* /www/bbs/
# cd /www/bbs/
# chown -R daemon templates/attachments/ forumdata/
# chown -R daemonuc_client/data/cache/ config.inc.php
访问web安装即可
添加数据库相关信息
只需要更改提供进行设置即可,设置完成出现下面的界面表示安装成功
安装后的处理,为了放置出现再次安装的情况,需要移除安装文件install
1
2
# mv install/ install.lock
# chmod 600 install.lock/
部署博客
1
2
3
4
5
6
7
8
9
10
11
12
13
# unzipwordpress-3.3.1-zh_CN.zip
# mv wordpress/* /www/wordpress/
# cd /www/wordpress/
# cp wp-config-sample.phpwp-config.php
# vim wp-config.php
/** WordPress 数据库的名称 */
define('DB_NAME', 'wordpress');
/** MySQL 数据库用户名 */
define('DB_USER', 'wordpress');
/** MySQL 数据库密码 */
define('DB_PASSWORD', 'myblog');
数据库创建博客的数据库和博客连接数据库的用户
1
2
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> GRANT all ON wordpress.* TO'wordpress'@'localhost' IDENTIFIED BY 'myblog';
设置完成之后打开浏览器输入http://blog.wordpress.com/wp-admin/install.php即开始安装
安装完成之后会转到登录页面,询问是否登录到后台管理博客
输入博客的域名访问博客前台
页:
[1]