linux+apache+mysql+php
准备工作:
1.配本地yum
[root@gjp99 ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo
2.挂载光盘使用:
[root@gjp99 ~]# mkdir /mnt/cdrom
[root@gjp99 ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
3.系统必须安装的工具:
[root@gjp99 ~]# yum grouplist |less
Development Libraries
Development Tools
Legacy Network Server
X Software Development
(四个必须安装)
如果基于java平台则需要安装Java Development
一、mysql的安装
1.用xshell自带的上传工具上传左侧的三个压缩文件!
2.绿色软件:(解压到/usr/local/下)
[root@gjp99 ~]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local/
3.查看解压后的文件
4.查看安装步骤(自带的)
[root@gjp99 mysql-5.5.15-linux2.6-i686]# less INSTALL-BINARY
4.与其要求对比,进行设置
[root@gjp99 ~]# cd /usr/local/
[root@gjp99 local]# ln -s mysql-5.5.15-linux2.6-i686/ mysql
//创建链接,比较方便,如果直接复制,占多余的内存
[root@gjp99 local]# cd mysql
[root@gjp99 mysql]# ll
查看文件是否是mysql-5.5.15-linux2.6-i686下面的内容
[root@gjp99 mysql]# scripts/mysql_install_db --user=mysql
WARNING: The host 'gjp99.baidu.com' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK
[root@gjp99 mysql]# chown -R root . //把该目录下的所有权限再次改过来
[root@gjp99 mysql]# chown -R mysql data // 只有data 所属用户mysql
[root@gjp99 mysql]# cp support-files/my-medium.cnf /etc/my.cnf //内存大小调
[root@gjp99 mysql]# bin/mysqld_safe --user=mysql & //启动mysql
[1] 19779
[root@gjp99 mysql]# 120803 14:49:22 mysqld_safe Logging to '/usr/local/mysql/data/gjp99.baidu.com.err'.
120803 14:49:22 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[root@gjp99 mysql]# netstat -tupln |grep mysql //该功能是否有效
tcp 0 0 :::3306 (端口号) :::* LISTEN 20017/mysqld
[root@gjp99 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
//由于经常使用:service mysqld start, 已习惯,所以重命名为mysqld
[root@gjp99 mysql]# service mysqld stop //在此可以正常使用此功能
Shutting down MySQL.^[[A^[[A120803 14:51:47 mysqld_safe mysqld from pid file /usr/local/mysql/data/gjp99.baidu.com.pid ended
^[[A [ OK ]
[1]+ Done bin/mysqld_safe --user=mysql
[root@gjp99 mysql]# netstat -tupln |grep mysql
[root@gjp99 mysql]# service mysqld start
Starting MySQL.^[[A.^[[A [ OK ]
[root@gjp99 mysql]# netstat -tupln |grep mysql
tcp 0 0 :::3306 :::* LISTEN 20325/mysqld
[root@gjp99 mysql]# chkconfig --list|grep mysql // mysql不能用chkconfig来管理
[root@gjp99 mysql]# vim /etc/init.d/mysqld
[root@gjp99 mysql]# ll /etc/rc.d/rc3.d/ |grep mysql
lrwxrwxrwx 1 root root 16 Aug 3 14:57 S64mysqld -> ../init.d/mysqld
库文件:
默认调用库:/lib/ /usr/lib /usr/local/lib
但mysql非标准路径!文件存放在:/usr/local/mysql/lib/
[root@gjp99 mysql]# vim /etc/ld.so.conf/
[root@gjp99 mysql]# cd /etc/ld.so.conf.d
[root@gjp99 ld.so.conf.d]# vim mysql.conf
[root@gjp99 ld.so.conf.d]# ll
total 4
-rw-r--r-- 1 root root 21 Aug 3 15:18 mysql.conf
[root@gjp99 ~]# cd /etc/ld.so.conf.d
[root@gjp99 ld.so.conf.d]# ldconfig –v
[root@gjp99 ld.so.conf.d]# ldconfig -v |grep mysql
/usr/local/mysql/lib:
libmysqlclient.so.18 -> libmysqlclient_r.so.18.0.0
说明库文件已可以正常的被调用了!
头文件:
默认头文件 /usr/include /usr/local/include/
mysql默认在/usr/local/mysql/include
二、Apache的搭建
1.查看现在使用Apache版本
[root@gjp99 ~]# yum list all |grep http
This system is not registered with RHN.
RHN support will be disabled.
httpd.i386 2.2.3-31.el5 rhel-server
httpd-devel.i386 2.2.3-31.el5 rh
2.上传过来的文件为源码,需解压缩到/usr/local/src/
[root@gjp99 ~]# tar -jxvf httpd-2.2.19.tar.bz2 -C /usr/local/src/
3.进入目录,查看是否是源码
4.查看安装步骤(自带的)
[root@gjp99 httpd-2.2.19]# less INSTALL
5.执行代码--编译---整理:
5.1 执行代码:
[root@gjp99 httpd-2.2.19]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --with-z
执行后显示的部分信息:
5.2 编译(make)
[root@gjp99 httpd-2.2.19]# make
5.3 整理目录(make install)
执行完make install后的信息:
6.进入安装后的apache目录,查看所需要修改及使用的信息
7.查看并修改服务启动文件信息:
[root@gjp99 bin]# file apachectl
apachectl: Bourne shell script text executable //bash脚本
[root@gjp99 bin]# vim apachectl
[root@gjp99 bin]# ./apachectl start
httpd: apr_sockaddr_info_get() failed for gjp99.baidu.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@gjp99 bin]# netstat -tupln |grep http
tcp 0 0 :::80 :::* LISTEN 10212/httpd
[root@gjp99 bin]# ./apachectl stop
httpd: apr_sockaddr_info_get() failed for gjp99.baidu.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@gjp99 bin]# netstat -tupln |grep http
开机启动,需修改:vim /etc/rc.local
8.Apache库文件、头文件路径的修改:
apache 的头文件,库文件也不是系统能调用的路径!
加载成功!
三、php的搭建
1.检测现用php版本,安装较新版本!
[root@gjp99 ~]# yum list all |grep php
This system is not registered with RHN.
RHN support will be disabled.
php.i386 5.1.6-23.2.el5_3 (现在在使用的版本) rhel-
2.上传的版本,是源码,需解压缩到/usr/local/src
[root@gjp99 ~]# tar -jxvf php-5.3.7.tar.bz2 -C /usr/local/src/
3.进入目录,看到configure文件(可编程脚本),证明是源码
./configure --help //查看需要启用的功能!
注意:
--prefix=安装目录
--with-apxs2= //把php变成Apache的一个模块
--with-mysql=mysql的安装路径,便于调用
--with-mysqli= mysql的接口程序
--enable-mbstring=//mysql支持长字符串
4.执行代码-----编译(make)-----整理目录(make install)
4.1 执行代码:
[root@gjp99 php-5.3.7]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring=all
执行代码结束显示:
4.2 编译
[root@gjp99 php-5.3.7]# make
编译结束显示:
由于make test 比较费时(此处省略)
4.3 开始整理目录
[root@gjp99 php-5.3.7]# make install
整理过程中:(以下证明php作为apache的一个模块)
整理完成部分界面:
四、测试:
[root@gjp99 php-5.3.7]# cd /usr/local/apache/htdocs/
[root@gjp99 htdocs]# ll
total 4
-rw-r--r-- 1 root root 44 Nov 21 2004 index.html
[root@gjp99 htdocs]# cat index.html
<html><body><h1>It works!</h1></body></html>
[root@gjp99 htdocs]# cat index.php
<?php
phpinfo();
?>
[root@gjp99 htdocs]# /usr/local/apache/bin/apachectl start
httpd: apr_sockaddr_info_get() failed for gjp99.baidu.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@gjp99 htdocs]# netstat -tupln |grep http
tcp 0 0 :::80 :::* LISTEN 592/httpd
访问不到php页面:
解决:在httpd.conf 加入 AddType application/x-httpd-php .php
[root@gjp99 htdocs]# vim /etc/httpd/httpd.conf
默认页面:
修改如下:
[root@gjp99 htdocs]# /usr/local/apache/bin/apachectl stop
httpd: apr_sockaddr_info_get() failed for gjp99.baidu.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@gjp99 htdocs]# /usr/local/apache/bin/apachectl start
httpd: apr_sockaddr_info_get() failed for gjp99.baidu.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@gjp99 htdocs]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.15-log MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
[root@gjp99 htdocs]# vim index.php