LAMP环境环境搭建(源码包):
. 适用于不同的平台, RHEL5, RHEL6
. 根据实际需要进行定制
0: 准备工作
(1)准备软件包
apr-1.4.6.tar.gz
apr-util-1.5.1.tar.gz
httpd-2.4.3.tar.gz
mysql-5.5.13.tar.gz
php-5.4.9.tar.gz
cmake-2.8.10.2.tar.gz
pcre-8.31.tar.gz
(2)编译工具准备
==安装gcc、gcc-c++ (建议安装开发工具、开发库)
# yum -y install gcc gcc-c++
==安装cmake:
# tar xf cmake-2.8.10.2.tar.gz
# ./bootstrap --prefix=/usr/local/cmake
# make && make install
# cmake --version
==============================
温馨提示:如果找不到cmake:
使用绝对路径
# /usr/local/cmake/bin/cmake --version
==============================
1. 安装mysql
(1)卸载系统中原有的mysql
# yum -y remove "mysql*"
# killall mysqld
(2) 安装依赖的库
# yum -y install ncurses-devel
(3)安装mysql-5.5.13.tar.gz
# groupadd mysql
# useradd -r -g mysql mysql
# tar xvf mysql-5.5.13.tar.gz
# cd mysql-5.5.13
# cmake . // .表示当前目录
===================================================================================================
补充知识:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DMYSQL_USER=mysql \
-DEXTRA_CHARSETS=all \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1
===================================================================================================
# make
# make install
# ls /usr/local/mysql 查看安装文件
(4)安装后的配置
# cd /usr/local/mysql
# chown -R mysql.mysql . //更改当前目录下所有文件属主和属组
# ./scripts/mysql_install_db --user=mysql //初始化mysql
# ls /usr/local/mysql/data/mysql/ //产生mysql授权信息
===================================================================================================
RPM包数据库目录: /var/lib/mysql
源码包数据库目录:PREFIX/data //PREFIX指安装路径
===================================================================================================
# chown -R root .
# chown -R mysql data //数据库目录所有文件属主必须是mysql
# pwd
/usr/local/mysql
# cp support-files/my-medium.cnf /etc/my.cnf //生成mysql的主配置文件
# cp support-files/mysql.server /etc/init.d/mysqld //复制启动脚本
# service mysqld start
# chkconfig mysqld on
===================================================================================================
另一方法启动mysql
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
===================================================================================================
(5)登录测试
# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin/
# source ~/.bash_profile //使用新PATH变量立即生效
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.13-log Source distribution
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> select user,host,password from mysql.user; //查询当前的授权用户
+------+------------------------+----------+
| user | host | password |
+------+------------------------+----------+
| root | localhost | |
| root | station3.uplooking.com | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | station3.uplooking.com | |
+------+------------------------+----------+
mysql> update mysql.user set password=password("123") where user='root' and host='localhost'; 修改密码
mysql> delete from mysql.user where password=''; 删除匿名等用户
mysql> grant all on *.* to root@'192.168.2.%' identified by '123'; 授权一个远程管理用户
mysql> flush privileges;
===================================================================================================================
2. 安装httpd-2.4.3.tar.gz
(1)卸载系统中原有的httpd,nginx
# yum -y remove "httpd*"
# killall httpd
# killall nginx
# netstat -tnlp |grep :80 查询80端口是否被占用
(2)安装依赖的库
# tar xf httpd-2.4.3.tar.gz
# tar xf apr-1.4.6.tar.gz
# tar xf apr-util-1.5.1.tar.gz
复制apr,apr-util到apache源码包指定的目录中
# mv apr-1.4.6 httpd-2.4.3/srclib/apr
# mv apr-util-1.5.1 httpd-2.4.3/srclib/apr-util
(3)安装pcre
# tar xf pcre-8.31.tar.gz
# cd pcre-8.31
# ./configure --prefix=/usr/local/pcre
# make && make install
# ls /usr/local/pcre/ 查看安装的文件
(4)安装Apache
# cd httpd-2.4.3
# ./configure \
> --prefix=/usr/local/apache2 \ 安装路径
> --with-included-apr \ 包含apr库
> --with-pcre=/usr/local/pcre \ 指定pcre安装的位置
> --enable-so \ 支持DSO(动态共享对象),能够支持动态模块,默认支持
> --enable-rewrite \ 支持地址重写
> --enable-ssl 启用SSL支持(安全套接层)
# make && make install
(5)启动Apache
# /usr/local/apache2/bin/apachectl -k start 启动Apache
# echo "/usr/local/apache2/bin/apachectl -k start" >> /etc/rc.local 开机启动
# elinks -dump 192.168.2.110
It works!
===================================================================================================================
另一种启动的方法:
# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
# service httpd start
# netstat -tnlp |grep :80
tcp 0 0 :::80 :::* LISTEN 25932/httpd
# elinks -dump 192.168.2.110 It works!
===================================================================================================================
===================================================================================================================
3. 安装PHP
(1)卸载系统中原有的php
# yum -y remove "php*"
(2)安装依赖的库
# yum -y install libxml2-devel
(3)安装PHP
# tar xf php-5.4.9.tar.gz
# cd php-5.4.9
# ./configure \
> --prefix=/usr/local/php \ 安装路径
> --with-apxs2=/usr/local/apache2/bin/apxs \ 关联Apache
> --with-mysql 关联mysql
# make && make install
# cp php.ini-development /usr/local/lib/php.ini 复制php的主配置文件
# ls /usr/local/apache2/modules/ |grep php
libphp5.so Apache模块目录下已安装php模块
# grep --color 'php5' /usr/local/apache2/conf/httpd.conf
oadModule php5_module modules/libphp5.so 查看Apache主配置文件中是否已加载php模块
===================================================================================================================
已经安装了
Mysql
Apache
PHP
整合配置:
Mysql /etc/my.cnf
Apache /usr/local/apache/conf/httpd.conf
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
PHP /usr/local/lib/php.ini
配置Apache支持PHP /usr/local/apache/conf/httpd.conf
LoadModule php5_module modules/libphp5.so 安装php时自动添加,不需要手动加
AddType application/x-httpd-php .php 让Apache识别php类型的文件
DirectoryIndex index.html index.php 设置主页文件
DocumentRoot "/usr/local/apache2/htdocs" 源码包缺省网站主目录
# /usr/local/apache2/bin/apachectl stop
# /usr/local/apache2/bin/apachectl start
创建php网站
# cd /usr/local/apache2/htdocs/
# rm -rf index.html 删除默认网页
# cat /usr/local/apache2/htdocs/index.php
安装论坛:Discuz_X2.5_SC_UTF8.zip
1. mysql创建数据库并授权用户
mysql> create database bbs;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on bbs.* to bbs@'%' identified by '444';
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
2. 上传网站
unzip Discuz_X2.5_SC_UTF8.zip
cp -rf upload/* /usr/local/apache2/htdocs/ load下的所有文件上传到 /usr/local/apache2/htdocs/
chmod -R 777 /usr/local/apache2/htdocs/
3. 安装网站
浏览器访问0daybank
文章评论