Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。
利用源码进行apache mysql php安装
先下载mysql源码,
然后解压进行安装
在之前先建个mysql账号mysql组(有了则不需要建立)
[[email protected] Packages]# yum --disablerepo=\* --enablerepo=c6-media install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libmcrypt* libtool* -y 安装
[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd -r -g mysql mysql
[[email protected] ~]# rpm -qa |grep mysql 查看之前安装 与mysql想关的包,删除
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media remove mysql-libs 软件包移除
[[email protected] ~]# tar -zxvf mysql-5.6.15.tar.gz -C /usr/local/src 进行解压
[[email protected] ~]# cd /usr/local/src/mysql-5.6.15/
cmake ./ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci 进行编译(如果安装完软件包后还出现错误,把解压的东西删除了重新解压一次)
make && make install 编译安装
[[email protected] local]# ln -s mysql-5.5.15-linux2.6-i686/ mysql 做个链接
[[email protected] local]# cd mysql
[[email protected] mysql]# vim INSTALL-BINARY 可以查看帮助文件进行安装
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
[[email protected] mysql]# chown -R mysql:mysql . 改变当前目录所有者与所有组为mysql
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql 进行安装
如果出现这样的错误就需要安装libaio
[[email protected] mysql]# yum --disablerepo=\* --enablerepo=c6-media install libaio libaio-devel -y 进行安装
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql 重新安装
[[email protected] mysql]# cd data/
[[email protected] data]# ll mysql/ 查看mysql目录下是否有数据,有数据的话表明安装成功
[[email protected] data]# cd .. 进入mysql目录 、
[[email protected] mysql]# chown -R root . 改变当前所有用户为管理员
[[email protected] mysql]# chown -R mysql data/ 将data用户改为mysql
[[email protected] mysql]# cp my.cnf /etc/ copy文件到my.cnf
[[email protected] mysql]# cd support-files/
[[email protected] support-files]# cp -p mysql.server /etc/init.d/mysqld 复制mysql文件到mysqld下
[[email protected] support-files]# service mysqld start 测试是否能够启动
[[email protected] mysql]# vim /etc/profile 修改配置文件
PATH=$PATH:/usr/local/mysql/bin 添加此语句
[[email protected] mysql]# . /etc/profile 重新读取
[[email protected] mysql]# mysql 进入mysql
[[email protected] mysql]# mysqladmin -u root -p password ‘123‘ 设置mysql密码
[[email protected] mysql]# chkconfig --add mysqld 启动系统启动
[[email protected] mysql]# chkconfig mysqld on
[[email protected] mysql]# vim /etc/ld.so.conf.d/mysql.conf 编辑mysql配置文件
写入此路径
[[email protected] mysql]# ldconfig 刷新缓存
[[email protected] mysql]# ldconfig -pv |grep mysql 查看结果
[[email protected] mysql]# cd /usr/include/ 进入目录
[[email protected] include]# ln -s /usr/local/mysql/include/ mysql 做一个链接
[[email protected] mysql]# vim /etc/man.config 处理man手册
MANPATH /usr/local/mysql/man 加入即可
[[email protected] mysql]# man mysql 进行测试
Mysql处理成功
然后进行apach的安装
httpd-2.4.4.tar.bz2
apr-1.4.6.tar.gz
apr-1.4.6.tar.gz 需要这3个软件包
[[email protected] ~]# tar -zxvf apr-1.4.6.tar.gz -C /usr/local/src/ 解压apr软件包
[[email protected] ~]# tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src/ 解压aprutil软件包
[[email protected] ~]# tar -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src/ 解压httpd软件包
[[email protected] ~]# cd /usr/local/src/apr-1.4.6/ 进入apr目录
[[email protected] apr-1.4.6]# ./configure --prefix=/usr/local/apr 进行编译
[[email protected] apr-1.4.6]# make && make install 安装
[[email protected] apr-1.4.6]# cd ../apr-util-1.5.1/ 切换到apr-util目录
[[email protected] apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-utils --with-apr=/usr/local/apr/bin/apr-1-config 编译,指定工具安装路径,指定apr的路径
[[email protected] apr-util-1.5.1]# make && make install 进行编译安装
[[email protected] apr-util-1.5.1]# cd ../httpd-2.4.4/ 配置httpd
./configure \
--prefix=/usr/local/apache \
--sysconfdir=/etc/httpd \
--enable-so \
--enable-ssl \
--enable-rewrite \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-apr-util=/usr/local/apr-utils/bin/apu-1-config \
--with-pcre \
-with-z \
--enable-mpms-shared=all 进行编译配置
出现错误提示,需要安装pcre-devel包
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media install pcre-devel -y 安装包
然后再进行编译配置
出现这个错误提示,需要安装[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media install openssl-devel -y
再进行编译配置通过后
[[email protected] httpd-2.4.4]# make && make install 配置安装
完成后
[[email protected] httpd-2.4.4]# cd /usr/local/apache/ 进入apache目录
[[email protected] apache]# vim /etc/profile 编辑profile文件
/usr/local/apache/bin 增加新的路径
[[email protected] apache]# . /etc/profile 进行更新
[[email protected] apache]# httpd -k start 测试是否能启动
[[email protected] apache]# netstat -tupln |grep 80 查看80端口是否开启
[[email protected] apache]# vim /etc/man.config 编辑man配置文件
加入MANPATH /usr/local/apache/man
[[email protected] apache]# man ab 尝试下是否生效
[[email protected] apache]# cd /usr/include/ 进入include目录
[[email protected] include]# ln -s /usr/local/apache/include/ apache 做个链接
[[email protected] ~]# cd /etc/init.d/ 进入目录
[[email protected] init.d]# touch httpd 创建httpd文件
[[email protected] init.d]# chmod a+x httpd 加入可执行权限
[[email protected] init.d]# vim httpd 进行编辑
#!/bin/bash
2 prog=/usr/local/apache/bin/httpd
3 lockfile=/var/lock/subsys/httpd
4 # description: the apache service
5 # chkconfig: 2345 88 44
6 start(){
7 if [ -e $lockfile ];then
8 echo "the apache service is started"
9 else
10 echo -n "the apache service is starting ...."
11 sleep 1
12 $prog -k start && echo "ok" && touch $lockfile || echo "failer"
13 fi
14
15 }
16
17 stop(){
18 if [ !e $lockfile ];then
19 echo "the apache service is stopped"
20 else
21 echo "the apache service is stoping..."
22 $prog -k stop && echo "ok" && rm -rf $lockfile || echo "failer"
23 fi
24
25 }
26
27
28 case "$1" in
29 start)
30 start
31 ;;
32 stop)
33 stop
34 ;;
35 restart)
36 stop
37 start
38 ;;
39 *)
40 echo "Usage: start|stop|restart"
41 ;;
42 esac
添加此代码来实现httpd启动关闭动态效果
[[email protected] init.d]# chkconfig --add httpd 加入httpd服务
[[email protected] init.d]# chkconfig --list |grep httpd 查看服务启动
PHP源码安装
[[email protected] ~]# tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src/ 解压软件包
[[email protected] ~]# cd /usr/local/src/php-5.5.8/ 进入目录
[[email protected] php-5.5.8]# ./configure \
> --prefix=/usr/local/php \
> --with-config-file-path=/etc/php \
> --with-config-file-scan-dir=/etc/php5.d \
> --with-apxs2=/usr/local/apache/bin/apxs \
> --with-mysql=/usr/local/mysql \
> --with-pdo-mysql=/usr/local/mysql \
> --with-mysqli=/usr/local/mysql/bin/mysql_config \
> --enable-mbstring=all \
> --with-gd
配置编译
接下来需要make && make isntall 因为时间比较长,睡眠的时候可能连接断开所以需要screen来实现安装
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media install screen -y 安装screen
[[email protected] php-5.5.8]# screen 使用screen
又打开了一个窗口 ctrl+a+d可以离开 screen -ls可以查看
恢复的话 screen -r 编号
[[email protected] php-5.5.8]# make && make install 然后进行后台配置安装
安装完成后:
[[email protected] php-5.5.8]# cd /usr/local/apache/modules/ 进入模块目录
[[email protected] modules]# ll |grep php
-rwxr-xr-x. 1 root root 23450184 Aug 24 06:41 libphp5.so 查看是否有php模块
[[email protected] modules]# vim /etc/httpd/httpd.conf 进入配置文件
加入此语句 AddType application/x-httpd-php .php
加入 index.php
[[email protected] modules]# service httpd restart 重启httpd
进行测试apache是否能与php进行结合
[[email protected] modules]# cd ../htdocs/
[[email protected] htdocs]# vim index.php 创建一个网页文件
写入此函数
[[email protected] htdocs]# mkdir /etc/php /etc/php5.d 创建2个目录
[[email protected] htdocs]# cd /usr/local/src/php-5.5.8/
[[email protected] php-5.5.8]# cp php.ini-production /etc/php/php.ini 拷贝文件到php.ini
[[email protected] php-5.5.8]# service httpd restart 重启httpd
然后输入网页查看下
成功与php进行了关联
再测试是否能通过php调动mysql
[[email protected] php-5.5.8]# cd /usr/local/apache/htdocs/ 进入htdocs目录
[[email protected] htdocs]# vim index.php 编辑网页文件
此文件用来测试是否能与数据库连通
登录网页查看
显示ok成功
[[email protected] htdocs]# service mysqld stop 停止mysql测试
成功
至此,lamp环境搭建已经成功