设为首页 收藏本站
查看: 873|回复: 0

[经验分享] Linux搭建PHP+MySQL+Apache环境

[复制链接]

尚未签到

发表于 2018-10-9 10:03:14 | 显示全部楼层 |阅读模式
  环境:
  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,步骤如下:
  [root@vm15 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
  [root@memcache mysql]# rpm -ivh MySQL-client-community-5.1.73-1.rhel5.x86_64.rpm
  Preparing... ########################################### [100%]
  1:MySQL-client-community ########################################### [100%]
  [root@vm15 mysql]# rpm -ivh MySQL-devel-community-5.1.73-1.rhel5.x86_64.rpm
  Preparing... ########################################### [100%]
  1:MySQL-devel-community ########################################### [100%]
  2、验证安装是否成功
  [root@vm15 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
  [root@vm15 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
  [root@vm15 local]# mkdir -p libxml2
  [root@vm15 local]# tar -zxvf libxml2-2.7.4.tar.gz
  [root@vm15 local]# cd libxml2-2.7.4
  [root@vm15 libxml2-2.7.4]# ./configure --prefix=/usr/local/libxml2
  [root@vm15 libxml2-2.7.4]# make
  [root@vm15 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
  [root@vm15 local]# mkdir -p php
  [root@vm15 local]# tar -zxvf php-5.6.3.tar.gz
  [root@vm15 local]# cd php-5.6.3
  [root@vm15 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
  [root@vm15 php-5.6.3]#make
  [root@vm15 php-5.6.3]#make install
  安装成功。
  六、配置php
  1、配置php.ini,只需要把php-5.6.3安装包中的php.ini-production拷贝到/usr/local/php/lib/下
  [root@vm15 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
  

  七、重启Apache
  [root@vm15 mysql]#  /usr/local/apache2/bin/apachectl start
  (一定要重启)
  八、测试php是否成功安装
  写一个php测试页info.php,放到/usr/local/apache2/htdocs中。
  ;
  在浏览器中输入:服务器地址/info.php。通过phpinfo()可以查看很多信息,比如php.ini的存放路径,以及所有扩展组件等,很强大。

  如果能正常显示出php的信息,则说明Apche+Mysql+PHP安装成功!
  九、安装遇到的问题
  1、安装MySQL时,报下面的错误:
  [root@memcache 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行
  [root@vm15 apr-1.5.1]#grep -n RM configure
  [root@vm15 apr-1.5.1]#sed -i '/$RM "$cfgfile"/d' configure
  然后再重新运行 ./configure --prefix=/usr/local/apr 就可以了.
  4、[root@vm15 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!
  解决方法
  [root@localhost php-5.5.6]# find / -name mysql.h
  /usr/include/mysql/mysql.h
  查找到mysql.h文件,我们更改参数为--with-mysql,如果没有的话,请安装mysql-devel包,



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-619449-1-1.html 上篇帖子: Linux命令:MySQL系列之六--VIEW视图/mysql -e 下篇帖子: mysql5.7主从同步配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表