目录
Welcome to Apache!!
首页 php教程 php手册 Linux下Apache+Mysql+PHP的安装与配置

Linux下Apache+Mysql+PHP的安装与配置

Jun 06, 2016 pm 07:45 PM
a linux 安装 配置

(1)Apache的安装与配置 思路:首先在官网下载APACHE源码,本系统下载版本为httpd-2.2.17.tar.gz,下面几步为在终端的配置命令 tar zxvf httpd-2.2.17.tar.gz cd httpd-2.2.17 ./configure --prefix=/usr/local/apache make make install service httpd sta

(1)       Apache的安装与配置

思路:首先在官网下载APACHE源码,本系统下载版本为httpd-2.2.17.tar.gz,下面几步为在终端的配置命令

tar zxvf httpd-2.2.17.tar.gz

cd httpd-2.2.17

./configure --prefix=/usr/local/apache

make

make install

service httpd start

如果出现:

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 222.31.76.227 for ServerName

                                                           [  OK  ]

 

 

 

 说明安装成功!

 

如果希望apache开机自启动的话,可以通过以下命令在/etc/rc.d/rc.local加入自启动命令:

echo "service httpd start">>/etc/rc.d/rc.local

 

测试Apache

/var/www/html目录下建立index.html文件

Welcome to Apache!!

 

 


保存后,在浏览器上输入http://XXX.XXX.XXX.XXX(Web服务器的IP)查看结果

注意:iptables必须关闭或者将80端口加到iptables

 

 

 

 

 

 

 

 

 

(2)       Mysql-client的安装与配置

思路:由于MYSQL没有源码包可以下载,所以本系统使用MYSQL的二进制安装包,使用版本为mysql-5.5.10-linux2.6-x86_64.tar.gz,下面几步为在终端的配置命令(可直接粘贴)

tar zxvf mysql-5.5.10-linux2.6-x86_64.tar.gz

cd /usr/local

ln -s /home/software/mysql-5.5.10-linux2.6-x86_64 mysql

cd mysql/

vi INSTALL-BINARY

看到以下部分为安装步骤

To install and use a MySQL binary distribution, the basic command

sequence looks like this:

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 .

shell> chown -R mysql data

# Next command is optional

shell> cp support-files/my-medium.cnf /etc/my.cnf

shell> bin/mysqld_safe --user=mysql &

# Next command is optional

shell> cp support-files/mysql.server /etc/init.d/mysql.server   //开机自启动(后面还需几步)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


如果已经安装在安装操作系统时已经安装过MYSQL,那么前6步(高亮部分)目前已经完成

(需要注意的是 data目录下存放的就是一个又一个数据库,所以,必须将权限设置为mysql,否则,mysql本身进不去,配置就会失败)

chown -R mysql.mysql .

scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/

chown -R root .

chown -R mysql data

cp support-files/my-medium.cnf /etc/my.cnf

bin/mysqld_safe --user=mysql &

service mysqld start

若显示:

Starting MySQL..                                           [  OK  ]

则说明mysql已成功启用!

 

使用  mysql_install_db --user=mysql  创建新的MySQL授权表,使用者为mysql

使用 mysqld_safe --user=mysql &     以用户名user_name或数字用户ID user_id运行mysqld服务器。(本文中的“用户”指系统登录账户,而不是 授权表中的MySQL用户)

 

MYSQL自启动

cp support-files/mysql.server /etc/init.d/mysqld

chmod 700 /etc/init.d/mysqld

chkconfig --add mysqld

如果遇到以下问题:

启动MYSQL出错,提示:
Starting mysqld daemon with databases from /usr/local/mysql/data
STOPPING server from pid file /usr/local/mysql/data/xmcncn.pid
061103 15:25:32  mysqld ended
解决方法:
vi /etc/my.cnf
看看[mysqld]下有没有
port  = 3306
添加上就可以了
touch /tmp/mysql.sock
killall -9 mysqld
/usr/local/mysql/bin/mysqld_safe -user=mysql &
成功启动

 

 

 

 

 

 

 

 

 

 

 

 

  

(3)php的安装与配置

首先,安装php前,以下包可能会需要安装:zlib-1.2.3.tar.gz、libpng-1.2.24.tar.gz、freetype-2.3.11.tar.gz、libtool-2.4.tar.gz、jpegsrc.v6b.tar.gz、autoconf-2.61.tar.gz、gd-2.0.35.tar.gz、libxml2-2.7.3.tar.gz

 

在官网下载php源码,本系统下载版本为php-5.3.6.tar,下面几步为在终端的配置命令(可直接粘贴)

cd /home/software/

tar -xvf php-5.3.6.tar

cd php-5.3.6

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-openssl-dir=/usr/lib/openssl --with-openssl

配置后若如下显示License,则说明成功,否侧可能还缺少上述的包。

checking whether -lc should be explicitly linked in... no

checking dynamic linker characteristics... GNU/Linux ld.so

checking how to hardcode library paths into programs... immediate

checking whether stripping libraries is possible... yes

creating libtool

appending configuration tag "CXX" to libtool

 

Generating files

updating cache ./config.cache

creating ./config.status

creating main/internal_functions.c

creating main/internal_functions_cli.c

+----------------------------------------------------------------------------------------+

| License:                                              |

| This software is subject to the PHP License, available in this     |

| distribution in the file LICENSE.  By continuing this installation  |

| process, you are bound by the terms of this license agreement.  |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                        |

+-----------------------------------------------------------------------------------------+

 

Thank you for using PHP.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


make

make test  //可以不做

make install

cp php.ini-development /etc/php.ini

vi /usr/local/apache/conf/httpd.conf

加入一句话:

AddType application/x-httpd-php .php

 

 


cd /var/www/html

vi index.php

新建php测试代码为:

phpinfo();

?>

 

 

 

 

重启apache,重启前要先修改/etc/selinux/config,将SELINUX=enforcing 改成SELINUX=disabled:

vi /etc/selinux/config

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#       enforcing - SELinux security policy is enforced.

#       permissive - SELinux prints warnings instead of enforcing.

#       disabled - SELinux is fully disabled.

SELINUX=disabled

# SELINUXTYPE= type of policy in use. Possible values are:

#       targeted - Only targeted network daemons are protected.

#       strict - Full SELinux protection.

SELINUXTYPE=targeted

 

 

 

 

 

 

 

 

 

 

 


service httpd restart

出现以下语句说明重启成功:

Stopping httpd:                                            [  OK ]

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 222.31.76.227 for ServerName

                                                         [  OK ]

 

 

 

 

 


在浏览器输入http://XXX.XXX.XXX.XXX/index.php,若显示phpinfo信息说明php配置成功。

 

 

 

若能显示phpinfo信息,但发现无法连接数据库(没有MYSQL的信息),说明phpmysql相连的模块包没有安装成功,可尝试下载安装php-mysqlrpm(php-mysql-5.1.6-27.el5.x86_64.rpm),安装它还需先安装php-pdorpm(php-pdo-5.1.6-27.el5.x86_64.rpm)pdo就是专门用于连接phpmysql的。

在以后的web端配置安装时,若phpinfo的基本信息能正常显示,但缺少某个模块功能,可单独下载其对应的rpm包,安装即可。

 

在/var/www/html下新建一个test.php,用于测试连接远程数据库:

Web2

echo "Hello World!";

$db=mysql_connect("远程服务器IP","用户名","password") or die ("mysql connected failed! ");

mysql_select_db("数据库名",$db);

$sql="select * from users";

$result=mysql_fetch_row(mysql_query($sql));

print_r($result);

?>

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

centos和ubuntu的区别 centos和ubuntu的区别 Apr 14, 2025 pm 09:09 PM

CentOS 和 Ubuntu 的关键差异在于:起源(CentOS 源自 Red Hat,面向企业;Ubuntu 源自 Debian,面向个人)、包管理(CentOS 使用 yum,注重稳定;Ubuntu 使用 apt,更新频率高)、支持周期(CentOS 提供 10 年支持,Ubuntu 提供 5 年 LTS 支持)、社区支持(CentOS 侧重稳定,Ubuntu 提供广泛教程和文档)、用途(CentOS 偏向服务器,Ubuntu 适用于服务器和桌面),其他差异包括安装精简度(CentOS 精

centos如何安装 centos如何安装 Apr 14, 2025 pm 09:03 PM

CentOS 安装步骤:下载 ISO 映像并刻录可引导媒体;启动并选择安装源;选择语言和键盘布局;配置网络;分区硬盘;设置系统时钟;创建 root 用户;选择软件包;开始安装;安装完成后重启并从硬盘启动。

Centos停止维护2024 Centos停止维护2024 Apr 14, 2025 pm 08:39 PM

CentOS将于2024年停止维护,原因是其上游发行版RHEL 8已停止维护。该停更将影响CentOS 8系统,使其无法继续接收更新。用户应规划迁移,建议选项包括CentOS Stream、AlmaLinux和Rocky Linux,以保持系统安全和稳定。

CentOS上GitLab的备份方法有哪些 CentOS上GitLab的备份方法有哪些 Apr 14, 2025 pm 05:33 PM

CentOS系统下GitLab的备份与恢复策略为了保障数据安全和可恢复性,CentOS上的GitLab提供了多种备份方法。本文将详细介绍几种常见的备份方法、配置参数以及恢复流程,帮助您建立完善的GitLab备份与恢复策略。一、手动备份利用gitlab-rakegitlab:backup:create命令即可执行手动备份。此命令会备份GitLab仓库、数据库、用户、用户组、密钥和权限等关键信息。默认备份文件存储于/var/opt/gitlab/backups目录,您可通过修改/etc/gitlab

docker原理详解 docker原理详解 Apr 14, 2025 pm 11:57 PM

Docker利用Linux内核特性,提供高效、隔离的应用运行环境。其工作原理如下:1. 镜像作为只读模板,包含运行应用所需的一切;2. 联合文件系统(UnionFS)层叠多个文件系统,只存储差异部分,节省空间并加快速度;3. 守护进程管理镜像和容器,客户端用于交互;4. Namespaces和cgroups实现容器隔离和资源限制;5. 多种网络模式支持容器互联。理解这些核心概念,才能更好地利用Docker。

docker desktop怎么用 docker desktop怎么用 Apr 15, 2025 am 11:45 AM

如何使用 Docker Desktop?Docker Desktop 是一款工具,用于在本地机器上运行 Docker 容器。其使用步骤包括:1. 安装 Docker Desktop;2. 启动 Docker Desktop;3. 创建 Docker 镜像(使用 Dockerfile);4. 构建 Docker 镜像(使用 docker build);5. 运行 Docker 容器(使用 docker run)。

centos怎么挂载硬盘 centos怎么挂载硬盘 Apr 14, 2025 pm 08:15 PM

CentOS硬盘挂载分为以下步骤:确定硬盘设备名(/dev/sdX);创建挂载点(建议使用/mnt/newdisk);执行mount命令(mount /dev/sdX1 /mnt/newdisk);编辑/etc/fstab文件添加永久挂载配置;卸载设备使用umount命令,确保没有进程使用设备。

centos停止维护后怎么办 centos停止维护后怎么办 Apr 14, 2025 pm 08:48 PM

CentOS 停止维护后,用户可以采取以下措施应对:选择兼容发行版:如 AlmaLinux、Rocky Linux、CentOS Stream。迁移到商业发行版:如 Red Hat Enterprise Linux、Oracle Linux。升级到 CentOS 9 Stream:滚动发行版,提供最新技术。选择其他 Linux 发行版:如 Ubuntu、Debian。评估容器、虚拟机或云平台等其他选项。

See all articles