Linux搭建PHP+MySQL+Apache环境

2018-01-13 11:08:07来源:网络收集作者:纳米程序员人点击

分享

阿里云爆款


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



DirectoryIndex index.html index.php


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台