Linux搭建PHP+MySQL+Apache环境

环境:

CentOS 6.4

MySQL详细安装可参考:http://www.cnblogs.com/yangxia-test/archive/2012/11/12/2766237.html

Apache详细安装可参考:http://www.cnblogs.com/yangxia-test/archive/2012/11/09/2762486.html

一、下载文件

1、php下载地址:http://php.net/downloads.php  版本:php-5.6.3.tar.gz

2、libxml2下载地址:http://download.chinaunix.net/download/0007000/6095.shtml  版本:libxml2-2.7.4.tar.gz

3、apache2下载地址:http://httpd.apache.org/  版本:httpd-2.4.10.tar.gz

4、apr与apr-util下载地址:http://apr.apache.org   版本:apr-1.5.1.tar.gz / apr-util-1.5.4.tar.gz

5、pcre下载地址:http://sourceforge.net/projects/pcre/files/pcre/  版本:pcre-8.36.tar.gz

6、MySQL下载地址:http://dev.mysql.com/downloads/mysql/5.1.73.html  

MySQL-devel-community-5.1.73-1.rhel5.x86_64.rpm

MySQL-client-community-5.1.73-1.rhel5.x86_64.rpm

MySQL-server-community-5.1.73-1.rhel5.x86_64.rpm

下载

二、安装MySQL

1、二进制安装MySQL,步骤如下:

[[email protected] mysql]# rpm -ivh MySQL-server-community-5.1.73-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-server-community ########################################### [100%]

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password ‘new-password‘
/usr/bin/mysqladmin -u root -h vm15.example.com password ‘new-password‘

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

Please report any problems with the /usr/bin/mysqlbug script!

Starting MySQL.. SUCCESS!
Giving mysqld 2 seconds to start

[[email protected] mysql]# rpm -ivh MySQL-client-community-5.1.73-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-client-community ########################################### [100%]

[[email protected] mysql]# rpm -ivh MySQL-devel-community-5.1.73-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-devel-community ########################################### [100%]

2、验证安装是否成功

[[email protected] mysql]# rpm -qa |grep MySQL
MySQL-client-community-5.1.73-1.rhel5.x86_64
MySQL-devel-community-5.1.73-1.rhel5.x86_64
MySQL-server-community-5.1.73-1.rhel5.x86_64

[[email protected] mysql]# mysql

出现了“mysql>”提示符,恭喜你,安装成功!

三、安装Apache

参考:http://www.cnblogs.com/yangxia-test/archive/2012/11/09/2762486.html

四、安装libxml2

将下载的libxml2-2.7.4.tar.gz文件上传至/usr/local

[[email protected] local]# mkdir -p libxml2
[[email protected] local]# tar -zxvf libxml2-2.7.4.tar.gz
[[email protected] local]# cd libxml2-2.7.4
[[email protected] libxml2-2.7.4]# ./configure --prefix=/usr/local/libxml2
[[email protected] libxml2-2.7.4]# make
[[email protected] libxml2-2.7.4]# make install

如果安装成功以后,在/usr/local/libxml2/目录下将生成bin、include、lib和share四个目录。在后面安装PHP5源代码包的配置时,会通过在configure命令的选项中加上"--with-libxml-dir=/usr/ local/libxml2"选项,用于指定安装libxml2库文件的位置。

五、安装php

将下载的php-5.6.3.tar.gz文件上传至/usr/local

[[email protected] local]# mkdir -p php
[[email protected] local]# tar -zxvf php-5.6.3.tar.gz
[[email protected] local]# cd php-5.6.3
[[email protected] php-5.6.3]#./configure --prefix=/usr/local/php --with-mysql --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/local/libxml2

出现以下信息表示编译成功

..
checking for external oniguruma... no
checking for mcrypt support... no
checking for MSSQL support via FreeTDS... no
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
configure: error: Cannot find MySQL header files under /usr/local/mysql.
Note that the MySQL client library is not bundled anymore!

creating libtool
appending configuration tag "CXX" to libtool

Generating files
configure: 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.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

[[email protected] php-5.6.3]#make

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

安装成功。

六、配置php

1、配置php.ini,只需要把php-5.6.3安装包中的php.ini-production拷贝到/usr/local/php/lib/下

[[email protected] php-5.6.3]# cp php.ini-production /usr/local/php/lib/php.ini

2、配置 httpd.conf 让apache支持PHP:

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

找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容

  AddType application/x-httpd-php .php      (.前面有空格)

  AddType application/x-httpd-php-source .phps        (.前面有空格)

3、在DirectoryIndex增加 index.php,以便Apache识别PHP格式的index

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

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule> 

七、重启Apache

[[email protected] mysql]#  /usr/local/apache2/bin/apachectl start

(一定要重启)

八、测试php是否成功安装

写一个php测试页info.php,放到/usr/local/apache2/htdocs中。

<?php

phpinfo();

?>;

在浏览器中输入:服务器地址/info.php。通过phpinfo()可以查看很多信息,比如php.ini的存放路径,以及所有扩展组件等,很强大。

如果能正常显示出php的信息,则说明Apche+Mysql+PHP安装成功!

九、安装遇到的问题

1、安装MySQL时,报下面的错误:

[[email protected] mysql]# rpm -ivh MySQL-server-community-5.1.73-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
file /usr/share/mysql/charsets/README from install of MySQL-server-community-5.1.73-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.73-3.el6_5.x86_64
file /usr/share/mysql/charsets/Index.xml from install of MySQL-server-community-5.1.73-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.73-3.el6_5.x86_64
file /usr/share/mysql/charsets/armscii8.xml from install of MySQL-server-community-5.1.73-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.73-3.el6_5.x86_64
file /usr/share/mysql/charsets/ascii.xml from install of MySQL-server-community-5.1.73-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.73-3.el6_5.x86_64
file /usr/share/mysql/charsets/cp1250.xml from install of MySQL-server-community-5.1.73-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.73-3.el6_5.x86_64
file /usr/share/mysql/charsets/cp1251.xml from install of MySQL-server-community-5.1.73-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.73-3.el6_5.x86_64
file /usr/share/mysql/charsets/cp1256.xml from install of MySQL-server-community-5.1.73-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.73-3.el6_5.x86_64

解决方法:yum remove mysql-libs-5*

2、configure php时,报错:

Configuring SAPI modules
checking for AOLserver support... no
checking for Apache 1.x module support via DSO through APXS... configure: error: You have enabled Apache 1.3 support while your server is Apache 2. Please use the appropriate switch --with-apxs2

解决方法:./configure --prefix=/usr/local/php --with-mysql  --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/local/libxml2

3、安装apr时,报错rm: cannot remove `libtoolT‘: No such file or directory

解决方法

直接打开/usr/local/apr-1.5.1/configure 把 $RM“$cfgfile” 那行删除掉
$RM“$cfgfile” 大约在 42302行

[[email protected] apr-1.5.1]#grep -n RM configure

[[email protected] apr-1.5.1]#sed -i ‘/$RM "$cfgfile"/d‘ configure

然后再重新运行 ./configure --prefix=/usr/local/apr 就可以了.

4、[[email protected] php-5.6.3]#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/local/libxml2

..
checking for external oniguruma... no
checking for mcrypt support... no
checking for MSSQL support via FreeTDS... no
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
configure: error: Cannot find MySQL header files under /usr/local/mysql.
Note that the MySQL client library is not bundled anymore!

解决方法

[[email protected] php-5.5.6]# find / -name mysql.h
/usr/include/mysql/mysql.h

查找到mysql.h文件,我们更改参数为--with-mysql,如果没有的话,请安装mysql-devel包,

时间: 2024-10-29 03:17:01

Linux搭建PHP+MySQL+Apache环境的相关文章

[经验技巧] “php+mysql+apache”环境搭建及&quot;手动SQL注入&quot;,20180527-0

[经验技巧] "php+mysql+apache"环境搭建及"手动SQL注入" 1."php+mysql+apache"环境搭建 环境载体:虚拟机Window7 Service Pack 1 旗舰版 下载"phpStudy (php5.2) " 链接:http://www.phpstudy.net/phpstudy/phpStudy(PHP5.2).zip 文件见附件1. 安装"phpStudy (php5.2) &

阿里云ECS搭建Java+mysql+tomcat环境的简要步骤

使用阿里云ECS挺长一段时间了.这两天碰巧朋友小白让我一步一步教他在ECS上搭建Java+mysql+tomcat环境,所以把在这里把步骤在这简单整理了一下,以便需要的人查阅. 我购买的阿里云服务器系统是Centos 6.5. 在购买好阿里云ECS后. 1.下载XShell 2.下载XFtp 3.使用XShell链接到阿里云ECS 4.以下命令在XShell中使用,也就是通过XShell控制阿里云服务器里的操作系统 [1]常用命令 pwd       查看当前目录 df -h      查看当前

linux搭建Lamp(centos7+apache+mysql)

我先在电脑里装了虚拟机,在虚拟机中测试了数次之后,再在服务器上搭建的.说说我的环境:虚拟机是:VMware-workstation-full-8.0.0-471780.exe:Linux系统用的是:CentOS-7-x86_64-Minimal-1503-01.ios;(阿里云上也是用的CentOS7-64bit)准备好这两个之后,就开始一步一步搭建我们的LAMP环境了. 一.安装虚拟机 二.安装CentOS7 注意:以下安装,我都是用的root权限. 三.安装Apache1.安装 yum -y

Linux下实现Mysql开发环境的部署和数据库程序的实现

SQL本身并不复杂,实际上我感觉部署mysql的环境才是最复杂的. 这里采用了centos6.5系统来部署环境. 首先需要安装数据库和数据库开发环境,以及编译环境 yum install MySQL MySQL-server MySQL-devel gcc gcc-c++ -y 然后运行数据库 service mysqld start 如果你用的是centos7以上的系统,mysql就被mariadb取代用以下命令执行 systemctl start mariadb.service 现在直接在控

在Linux环境下搭建Tomcat+mysql+jdk环境

注:所有内容都是妹纸我亲自搭建成功运行,如果有问题,欢迎发邮件来交流. [email protected](此QQ只用来收邮件,一般情况下是不会登陆的,所有有问题可以发邮件哦~我会回复的) 按照下面的步骤一步一步来.   [Linux环境] 1.下载并安装一个VMware workstation, 这个是虚拟机的平台,后面要在里面搭建Linux系统. 2.下载一个centos安装包,linux版本有多种,比如说redhat.ubuntu.deepin.BT3,个人比较习惯使用centos,这里下

linux下搭建nginx+mysql+apache

对于开发人员来说,进行Web开发时可以用Apache进行网站测试,然而当一个Web程序进行发布时,Apache中并发性能差就显得很突出,这时配置一台Nginx服务器显得尤为重要. 以下是配置Nginx服务器的方法: 1.下载Xshell和Xftp用于管理Linux系统和上传文件 2.下载aliyun一键web安装包(包含Nginx.PHP.Mysql)  点此下载 3.将aliyun一键安装包上传到root目录下 4.执行命令:cd /root 进入root目录 5.执行命令:ls –l查看目录

在fedora21 上的php+mysql+apache环境搭建

LAMP Stands for Linux,Apache,MySQL and PHP. Most of the websites works with the above combination. The main purpose of LAMP is testing the application locally by the programmer before going to the production. Below are the steps to install LAMP (Apac

php+mysql+Apache环境搭建

最近有一个小程序需要用php来跑,记录一下php的环境配置过程. 1.首先在下载集成工具wamp,WAMP是指在Windows服务器上使用Apache.MySQL和PHP的集成安装环境,可以快速安装配置Web服务器: https://sourceforge.net/projects/wampserver/files/WampServer%203/WampServer%203.0.0/wampserver3.0.6_x64_apache2.4.23_mysql5.7.14_php5.6.25-7.

在阿里云 CentOS 服务器(ECS)上搭建 nginx + mysql + php-fpm 环境

阿里云的云服务器(ECS)可以选择多种操作系统,打算用它运行 Drupal或者 WordPress ,你最好选择 Linux 系统,这篇文章的演示是基于阿里云的 CentOS 操作系统的服务器.我们在上面搭建一个 nginx + mysql + php-fpm 的环境,这就是常说的 LNMP .我们不过多解释什么是什么,而是着重讲流程与方法,想了解具体的细节,去搜索下吧:)这个手册是在阿里云上测试的,不过应该也适用于其它使用 CentOS 系统的服务器. 背景 宁皓网的< CentOS:在阿里云