linux+apache+mysql+php

准备工作:

1.配本地yum

[[email protected] ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo

LAMP的搭建(源代码)

2.挂载光盘使用:

LAMP的搭建(源代码)

[[email protected] ~]# mkdir /mnt/cdrom 
[[email protected] ~]# mount /dev/cdrom /mnt/cdrom 
mount: block device /dev/cdrom is write-protected, mounting read-only

3.系统必须安装的工具:

[[email protected] ~]# yum grouplist  |less

Development Libraries 
  Development Tools

Legacy Network Server

X Software Development

(四个必须安装)

如果基于java平台则需要安装Java Development

一、mysql的安装

1.用xshell自带的上传工具上传左侧的三个压缩文件!

LAMP的搭建(源代码)

LAMP的搭建(源代码)

2.绿色软件:(解压到/usr/local/下)

LAMP的搭建(源代码)

[[email protected] ~]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local/

3.查看解压后的文件

LAMP的搭建(源代码)

4.查看安装步骤(自带的)

[[email protected] mysql-5.5.15-linux2.6-i686]# less INSTALL-BINARY

LAMP的搭建(源代码)

4.与其要求对比,进行设置

[[email protected] ~]# cd /usr/local/

[[email protected] local]# ln -s mysql-5.5.15-linux2.6-i686/ mysql 

//创建链接,比较方便,如果直接复制,占多余的内存

[[email protected] local]# cd mysql 
[[email protected] mysql]# ll 

查看文件是否是mysql-5.5.15-linux2.6-i686下面的内容

LAMP的搭建(源代码)

LAMP的搭建(源代码)

LAMP的搭建(源代码)

[[email protected] 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

[[email protected] mysql]# chown -R root .  //把该目录下的所有权限再次改过来

[[email protected] mysql]# chown -R mysql data  // 只有data 所属用户mysql

LAMP的搭建(源代码)

[[email protected] mysql]# cp support-files/my-medium.cnf /etc/my.cnf  //内存大小调

[[email protected] mysql]#  bin/mysqld_safe --user=mysql &   //启动mysql 
[1] 19779 
[[email protected] 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 
[[email protected] mysql]# netstat -tupln |grep mysql   //该功能是否有效 
tcp        0      0 :::3306 (端口号)            :::*              LISTEN      20017/mysqld       

[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld

//由于经常使用:service mysqld start, 已习惯,所以重命名为mysqld 
[[email protected] 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 
[[email protected] mysql]# netstat -tupln |grep mysql 
[[email protected] mysql]# service mysqld start 
Starting MySQL.^[[A.^[[A                                   [  OK  ] 
[[email protected] mysql]# netstat -tupln |grep mysql 
tcp        0      0 :::3306                     :::*                        LISTEN      20325/mysqld        
[[email protected] mysql]# chkconfig --list|grep mysql // mysql不能用chkconfig来管理

[[email protected] mysql]# vim /etc/init.d/mysqld  LAMP的搭建(源代码)

LAMP的搭建(源代码)

[[email protected] 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/

[[email protected] mysql]# vim /etc/ld.so.conf/LAMP的搭建(源代码)

[[email protected] mysql]# cd /etc/ld.so.conf.d 
 

[[email protected] ld.so.conf.d]# vim mysql.conf

LAMP的搭建(源代码)

[[email protected] ld.so.conf.d]# ll 
total 4 
-rw-r--r-- 1 root root 21 Aug  3 15:18 mysql.conf

[[email protected] ~]# cd /etc/ld.so.conf.d 
[[email protected] ld.so.conf.d]# ldconfig –v

[[email protected] 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

LAMP的搭建(源代码)

二、Apache的搭建

1.查看现在使用Apache版本

[[email protected] ~]# 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/

LAMP的搭建(源代码)

[[email protected] ~]# tar -jxvf httpd-2.2.19.tar.bz2 -C /usr/local/src/

3.进入目录,查看是否是源码

LAMP的搭建(源代码)

4.查看安装步骤(自带的)

[[email protected] httpd-2.2.19]# less INSTALL

LAMP的搭建(源代码)

5.执行代码--编译---整理:

 5.1 执行代码

[[email protected] httpd-2.2.19]# ./configure --prefix=/usr/local/apache  --sysconfdir=/etc/httpd  --enable-so --enable-ssl   --with-z

执行后显示的部分信息:

LAMP的搭建(源代码)

  5.2 编译(make)

[[email protected] httpd-2.2.19]# make

LAMP的搭建(源代码)

  5.3 整理目录(make install)

LAMP的搭建(源代码)

   执行完make install后的信息:

LAMP的搭建(源代码)

6.进入安装后的apache目录,查看所需要修改及使用的信息

LAMP的搭建(源代码) 

LAMP的搭建(源代码)

7.查看并修改服务启动文件信息:

LAMP的搭建(源代码)

[[email protected] bin]# file apachectl 
apachectl: Bourne shell script text executable    //bash脚本 
[[email protected] bin]# vim apachectl

LAMP的搭建(源代码)

[[email protected] 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 
[[email protected] bin]# netstat -tupln |grep http 
tcp        0      0 :::80                       :::*                        LISTEN      10212/httpd         
[[email protected] 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 
[[email protected] bin]# netstat -tupln |grep http

开机启动,需修改:vim /etc/rc.local

LAMP的搭建(源代码)

8.Apache库文件、头文件路径的修改:

apache 的头文件,库文件也不是系统能调用的路径!

LAMP的搭建(源代码)

LAMP的搭建(源代码)

加载成功!

LAMP的搭建(源代码)

三、php的搭建

1.检测现用php版本,安装较新版本!

[[email protected] ~]# 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

LAMP的搭建(源代码)

[[email protected] ~]# tar -jxvf php-5.3.7.tar.bz2 -C /usr/local/src/

3.进入目录,看到configure文件(可编程脚本),证明是源码

LAMP的搭建(源代码)

 ./configure --help  //查看需要启用的功能!

注意:

--prefix=安装目录

--with-apxs2= //把php变成Apache的一个模块

--with-mysql=mysql的安装路径,便于调用

--with-mysqli= mysql的接口程序

--enable-mbstring=//mysql支持长字符串

4.执行代码-----编译(make)-----整理目录(make install)

4.1 执行代码

[[email protected] 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

执行代码结束显示:

LAMP的搭建(源代码)

4.2 编译

[[email protected] php-5.3.7]# make

编译结束显示:

LAMP的搭建(源代码)

由于make test 比较费时(此处省略)

4.3 开始整理目录

[[email protected] php-5.3.7]# make install

整理过程中:(以下证明php作为apache的一个模块)

LAMP的搭建(源代码)

整理完成部分界面:

LAMP的搭建(源代码)

四、测试:

[[email protected] php-5.3.7]# cd /usr/local/apache/htdocs/ 
[[email protected] htdocs]# ll 
total 4 
-rw-r--r-- 1 root root 44 Nov 21  2004 index.html

[[email protected] htdocs]# cat index.html 
<html><body><h1>It works!</h1></body></html>

LAMP的搭建(源代码)

[[email protected] htdocs]# cat index.php 
<?php 
phpinfo(); 
?>

[[email protected] 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

[[email protected] htdocs]# netstat -tupln |grep http 
tcp        0      0 :::80                       :::*                        LISTEN      592/httpd

访问不到php页面:

解决:在httpd.conf  加入  AddType application/x-httpd-php .php

[[email protected] htdocs]# vim /etc/httpd/httpd.conf 
默认页面:

LAMP的搭建(源代码)

修改如下:

LAMP的搭建(源代码)

[[email protected] 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 
[[email protected] 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

LAMP的搭建(源代码)

[[email protected] 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&gt;

[[email protected] htdocs]# vim index.php

LAMP的搭建(源代码)

LAMP的搭建(源代码)

LAMP的搭建(源代码)

LAMP的搭建(源代码)


本文转自 gjp0731 51CTO博客,原文链接:http://blog.51cto.com/guojiping/976679



相关文章:

  • 2021-04-26
  • 2021-06-29
  • 2021-11-22
  • 2021-06-02
  • 2021-11-24
  • 2021-09-10
  • 2021-11-04
  • 2021-11-05
猜你喜欢
  • 2021-11-21
  • 2021-07-27
  • 2021-05-24
  • 2021-11-04
  • 2021-06-15
  • 2021-06-27
相关资源
相似解决方案