Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。 利用源码进行apache mysql php安装 先下载mysql源码, 然后解压进行安装 在之前先建个mysql账号mysql组(有了则不需要建立) [iyunv@wang Packages]# yum --disablerepo=* --enablerepo=c6-media install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libmcrypt* libtool* -y 安装 [iyunv@wang ~]# groupadd mysql [iyunv@wang ~]# useradd -r -g mysql mysql [iyunv@wang ~]# rpm -qa |grep mysql 查看之前安装 与mysql想关的包,删除 [iyunv@wang ~]# yum --disablerepo=* --enablerepo=c6-media remove mysql-libs 软件包移除 [iyunv@wang ~]# tar -zxvf mysql-5.6.15.tar.gz -C /usr/local/src 进行解压 [iyunv@wang ~]# 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 编译安装 [iyunv@wang local]# ln -s mysql-5.5.15-linux2.6-i686/ mysql 做个链接 [iyunv@wang local]# cd mysql [iyunv@wang 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 . [iyunv@wang mysql]# chown -R mysql:mysql . 改变当前目录所有者与所有组为mysql [iyunv@wang mysql]# ./scripts/mysql_install_db --user=mysql 进行安装 如果出现这样的错误就需要安装libaio [iyunv@wang mysql]# yum --disablerepo=* --enablerepo=c6-media install libaio libaio-devel -y 进行安装 [iyunv@wang mysql]# ./scripts/mysql_install_db --user=mysql 重新安装 [iyunv@wang mysql]# cd data/ [iyunv@wang data]# ll mysql/ 查看mysql目录下是否有数据,有数据的话表明安装成功 [iyunv@wang data]# cd .. 进入mysql目录 、 [iyunv@wang mysql]# chown -R root . 改变当前所有用户为管理员 [iyunv@wang mysql]# chown -R mysql data/ 将data用户改为mysql [iyunv@wang mysql]# cp my.cnf /etc/ copy文件到my.cnf [iyunv@wang mysql]# cd support-files/ [iyunv@wang support-files]# cp -p mysql.server /etc/init.d/mysqld 复制mysql文件到mysqld下
[iyunv@wang support-files]# service mysqld start 测试是否能够启动 [iyunv@wang mysql]# vim /etc/profile 修改配置文件
PATH=$PATH:/usr/local/mysql/bin 添加此语句 [iyunv@wang mysql]# . /etc/profile 重新读取 [iyunv@wang mysql]# mysql 进入mysql [iyunv@wang mysql]# mysqladmin -u root -p password '123' 设置mysql密码 [iyunv@wang mysql]# chkconfig --add mysqld 启动系统启动 [iyunv@wang mysql]# chkconfig mysqld on [iyunv@wang mysql]# vim /etc/ld.so.conf.d/mysql.conf 编辑mysql配置文件
写入此路径 [iyunv@wang mysql]# ldconfig 刷新缓存 [iyunv@wang mysql]# ldconfig -pv |grep mysql 查看结果
[iyunv@wang mysql]# cd /usr/include/ 进入目录 [iyunv@wang include]# ln -s /usr/local/mysql/include/ mysql 做一个链接 [iyunv@wang mysql]# vim /etc/man.config 处理man手册
MANPATH /usr/local/mysql/man 加入即可 [iyunv@wang mysql]# man mysql 进行测试 Mysql处理成功 然后进行apach的安装 httpd-2.4.4.tar.bz2 apr-1.4.6.tar.gz apr-1.4.6.tar.gz 需要这3个软件包 [iyunv@wang ~]# tar -zxvf apr-1.4.6.tar.gz -C /usr/local/src/ 解压apr软件包 [iyunv@wang ~]# tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src/ 解压aprutil软件包 [iyunv@wang ~]# tar -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src/ 解压httpd软件包 [iyunv@wang ~]# cd /usr/local/src/apr-1.4.6/ 进入apr目录 [iyunv@wang apr-1.4.6]# ./configure --prefix=/usr/local/apr 进行编译 [iyunv@wang apr-1.4.6]# make && make install 安装 [iyunv@wang apr-1.4.6]# cd ../apr-util-1.5.1/ 切换到apr-util目录 [iyunv@wang apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-utils --with-apr=/usr/local/apr/bin/apr-1-config 编译,指定工具安装路径,指定apr的路径 [iyunv@wang apr-util-1.5.1]# make && make install 进行编译安装 [iyunv@wang 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包 [iyunv@wang ~]# yum --disablerepo=* --enablerepo=c6-media install pcre-devel -y 安装包 然后再进行编译配置
出现这个错误提示,需要安装[iyunv@wang ~]# yum --disablerepo=* --enablerepo=c6-media install openssl-devel -y 再进行编译配置通过后 [iyunv@wang httpd-2.4.4]# make && make install 配置安装 完成后 [iyunv@wang httpd-2.4.4]# cd /usr/local/apache/ 进入apache目录 [iyunv@wang apache]# vim /etc/profile 编辑profile文件
/usr/local/apache/bin 增加新的路径 [iyunv@wang apache]# . /etc/profile 进行更新 [iyunv@wang apache]# httpd -k start 测试是否能启动 [iyunv@wang apache]# netstat -tupln |grep 80 查看80端口是否开启 [iyunv@wang apache]# vim /etc/man.config 编辑man配置文件
加入MANPATH /usr/local/apache/man [iyunv@wang apache]# man ab 尝试下是否生效 [iyunv@wang apache]# cd /usr/include/ 进入include目录 [iyunv@wang include]# ln -s /usr/local/apache/include/ apache 做个链接 [iyunv@wang ~]# cd /etc/init.d/ 进入目录 [iyunv@wang init.d]# touch httpd 创建httpd文件 [iyunv@wang init.d]# chmod a+x httpd 加入可执行权限 [iyunv@wang 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启动关闭动态效果 [iyunv@wang init.d]# chkconfig --add httpd 加入httpd服务 [iyunv@wang init.d]# chkconfig --list |grep httpd 查看服务启动
PHP源码安装 [iyunv@wang ~]# tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src/ 解压软件包 [iyunv@wang ~]# cd /usr/local/src/php-5.5.8/ 进入目录 [iyunv@wang 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来实现安装 [iyunv@wang ~]# yum --disablerepo=* --enablerepo=c6-media install screen -y 安装screen [iyunv@wang php-5.5.8]# screen 使用screen 又打开了一个窗口 ctrl+a+d可以离开 screen -ls可以查看 恢复的话 screen -r 编号 [iyunv@wang php-5.5.8]# make && make install 然后进行后台配置安装 安装完成后: [iyunv@wang php-5.5.8]# cd /usr/local/apache/modules/ 进入模块目录 [iyunv@wang modules]# ll |grep php -rwxr-xr-x. 1 root root 23450184 Aug 24 06:41 libphp5.so 查看是否有php模块 [iyunv@wang modules]# vim /etc/httpd/httpd.conf 进入配置文件
加入此语句 AddType application/x-httpd-php .php
加入 index.php [iyunv@wang modules]# service httpd restart 重启httpd 进行测试apache是否能与php进行结合 [iyunv@wang modules]# cd ../htdocs/ [iyunv@wang htdocs]# vim index.php 创建一个网页文件 写入此函数 [iyunv@wang htdocs]# mkdir /etc/php /etc/php5.d 创建2个目录 [iyunv@wang htdocs]# cd /usr/local/src/php-5.5.8/ [iyunv@wang php-5.5.8]# cp php.ini-production /etc/php/php.ini 拷贝文件到php.ini [iyunv@wang php-5.5.8]# service httpd restart 重启httpd 然后输入网页查看下
成功与php进行了关联 再测试是否能通过php调动mysql [iyunv@wang php-5.5.8]# cd /usr/local/apache/htdocs/ 进入htdocs目录 [iyunv@wang htdocs]# vim index.php 编辑网页文件
此文件用来测试是否能与数据库连通 登录网页查看
显示ok成功 [iyunv@wang htdocs]# service mysqld stop 停止mysql测试
成功 至此,lamp环境搭建已经成功
|