Home php教程 php手册 CentOS5.4下安装和配置Apache、PHP、MySql、PHPMyAdmin

CentOS5.4下安装和配置Apache、PHP、MySql、PHPMyAdmin

Jun 14, 2016 am 12:02 AM
apache mysql php phpmyadmin code Install Open source programming programming language software development Configuration

查看文章索引请通过http://www.cnblogs.com/seesea125/archive/2012/04/17/2453256.html

 

安装Php的人目的不同,如果是开发人员,不是专门的DBA,只是想安装PHP和MySql,然后迅速转入编程工作,自然对Linux以及配置都不熟悉,这种情况下,如果从Apache开始都重新安装,则需要各种包的下载和配置,而且各种包还互相具有依赖性,对于菜鸟来说无疑是一场噩梦,我就是这种情况,一开始想认真了解下这些软件的安装和配置,但是这样害我折腾2,3天,还是没有配置好,几乎灰心绝望,最后转变思路,用最简单的方法安装和配置成功,这样对于初学Linux,也对未来的进一步学习充满了信心。

废话少说了,正文开始。

一 安装操作系统,安装操作系统时,注意一定要安装gcc,这是Apache运行的基础,因此图形界面安装时,选择自定义选择安装包,要选择Development Toos,如下图所示:

image

如果是新手,最好连桌面也选上,毕竟一开始没有到了玩命令行刷刷的地步,而且选择了桌面后,可以看到Linux下的文件夹路径,以及某些安装包没装好,还可以从光盘里重新安装,如下图所示:

image

这两个,一个是MySq数据库,一个就是Apache和Php了,如下图所示:

image

选择Web Server ,点击下面的Optional packages按钮,能看到里面有httpd和php的包,如下图所示:
image

image

好了,这是安装操作系统时,直接安装上Apache,Php,MySql了,如果安装后发现这些没安装,还可以在图形界面下通过添加删除程序来操作(命令行也可以,就是对新手来说复杂点)

二 系统装好后,注意配置一下,让系统能上网,上网可以选择NAT和Bridge方式,其中NAT方式默认和主系统一个IP地址上网,Bridge方式是再给虚拟机分配一个IP地址,接下来安装是要用到网络的。

三 安装好后,查看这几个软件包是否存在,如果不存在要重新安装。

运行以下命令检查你的Linux是否已经安装了必备组件:
Rpm –qi httpd                      # 检查是否已安装httpd套件
Rpm –qi mysql                    # 检查是否已安装mysql套件
Rpm –qi php                        # 检查是否已安装php套件
Rpm –qi php-mysql              # 检查是否已安装php-mysql套件,注意这个是必须装的,因为这个是运行PHPMyAdmin必须用到的一个套件

四  安装不存在的包

如果这些包不存在怎么办?我们可以通过YUM方法去安装,国内的镜像服务器都比较快,因为先把我们的系统下载个国内的镜像。

运行以下命令:

先进入yum源配置目录

cd /etc/yum.repos.d

备份系统自带的yum源

mv CentOS-Base.repo CentOS-Base.repo.save

下载其他更快的yum源

中科大的yum源:
wget http://centos.ustc.edu.cn/CentOS-Base.repo
163的yum源:
wget http://mirrors.163.com/.help/CentOS-Base-163.repo
sohu的yum源
wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo

推荐使用163的源,比较稳定,速度也比较快。

更新完yum源后,建议更新一下,使操作立即生效
yum makecache

在第三步里检查没有安装的包后,对号入座,直接yum安装缺少的包

1). 安装Apache
yum install httpd mod_ssl
2). 安装php
yum install php php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml
3). 安装mysql
yum install mysql-server
4). 启动mysql,
service mysqld start
5). 启动apache
service httpd start

如果单独少了一个php-mysql套件,可以yum install php-mysql即可。

五 测试

在浏览器中访问http://youhost/,看看apache欢迎页是不是出来了?

接下来要写一个php页面,命名为index.php,这个php文件要放在web根目录,根目录在哪呢,根目录的路径配置在httpd.conf文件里,在命令行输入

vim /etc/httpd/conf/httpd.conf

在里面查找DocumentRoot /var/www/html 这个就是PHP的根目录。

让我们新建这个文件,在命令行输入vim /var/www/html/index.php

打开后,在里面写入一句话,按esc,然后输入:wq,这样就保持并退出了。

这个时候再访问http://youhost/,是不是php的信息就出来了?

六 安装和配置PhpMyAdmin

因为CentOS默认安装的PHP版本是5.1.6的,而PhpMyAdmin现在版本都要求再5.2以上的版本运行,升级版本接下来再说,现在为了让PhpMyAdmin能运行,就不用下最新的了,先下个phpMyAdmin-2.8.2.tar.bz2,一样的用,呵呵

1 下载后,把phpmyadmin代码拷贝到刚才php根目录下/VAR/WWW/HTML,然后解压,在命令行输入:

Tar jxvf phpmyadmin2.8.2.tar.bz2

2 将解压后的文件夹重命名为phpMyAdmin:

[root@localhost HTML]#mv phpmyadmin2.8.2  ./phpMyAdmin

3 找到 phpMyAdmin/libraries/config.default.php文件,将config.default.php复制到phpmyadmin目录下,然后更名为config.inc.php

4 对config.inc.php文件进行vi编辑

a.查找 $cfg['PmaAbsoluteUri'] 修改为你将上传到空间的phpMyAdmin的网址:

    如:$cfg['PmaAbsoluteUri'] = 'http://192.168.1.11/phpMyAdmin/';

  b.查找 $cfg['Servers'][$i]['host'] = 'localhost';(通常用默认,也有例外,可以不用修改)

  c.查找 $cfg['Servers'][$i]['auth_type'] = 'config';

    在自己的机子里调试用config;如果在网络上的空间用cookie,这里我们既然在前面已经添加了网址,就修改成cookie ,这里建议使用cookie。

  d.查找 $cfg['Servers'][$i]['user'] = 'root'; // MySQL user(mysql用户名,自己机里用root;)

  e.查找 $cfg['Servers'][$i]['password'] = ''; // MySQL password (mysql用户的密码,自己的服务器一般都是mysql用户root的密码)

  f.查找 $cfg['Servers'][$i]['only_db'] = ''; // If set to a db-name, only(你只有一个数据就设置一下;如果你在本机或想架设服务器,那么建议留空)

  g.查找 $cfg['DefaultLang'] = 'zh'; //选择语言为简体中文

  h.设置完毕后保存。

5 测试:在浏览器中输入http://youhost/phpMyAdmin/

   登陆phpMyAdmin后,如果遇到错误,没有发现 PHP 的扩展设置mbstring, 而当前系统好像在使用宽字符集。没有 mbstring 扩展的 phpMyAdmin 不能正确识别字符串,可能产生不可意料的结果.

在命令行执行 Yum install php-mbstring即可

好了,终于完成了。

这个是最简单的安装方法,如果在安装的时候,发现php版本是5.1.6,但是想升级到5.2.10,怎么办?

1 升级之前先卸载当前的php5.1.6,不要手工删除,yum安装的就用yum删除,执行yum remove php即可

2 通过yum服务器安装,发现没有这个版本,去网站下载php源代码,在本地编译,执行下面的命令行.

./configure --prefix=/my/php  

make  

make install

3 重新启动apache

service httpd restart

这个时候发现PHP已经能运行了

4 这个时候发现PHP不能连接MySql数据库,执行下面命令

install mysql-devel,一路yes安装

重新编译运行PHP,加上--with-mysql  ,PHP里包括了大量的PHP扩展,只要加一个--with-mysql指示符, 编译的Php就支持mysql访问了

./configure --prefix=/my/php --with-mysql  

make  

make install 

升级完成

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to adjust the wordpress article list How to adjust the wordpress article list Apr 20, 2025 am 10:48 AM

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

How to safely store JavaScript objects containing functions and regular expressions to a database and restore? How to safely store JavaScript objects containing functions and regular expressions to a database and restore? Apr 19, 2025 pm 11:09 PM

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

How to cancel the editing date of wordpress How to cancel the editing date of wordpress Apr 20, 2025 am 10:54 AM

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

C  : Is It Dying or Simply Evolving? C : Is It Dying or Simply Evolving? Apr 24, 2025 am 12:13 AM

C isnotdying;it'sevolving.1)C remainsrelevantduetoitsversatilityandefficiencyinperformance-criticalapplications.2)Thelanguageiscontinuouslyupdated,withC 20introducingfeatureslikemodulesandcoroutinestoimproveusabilityandperformance.3)Despitechallen

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

How to process and display percentage numbers in Java? How to process and display percentage numbers in Java? Apr 19, 2025 pm 10:48 PM

Display and processing of percentage numbers in Java In Java programming, the need to process and display percentage numbers is very common, for example, when processing Excel tables...

See all articles