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

[经验分享] Centos+mysql+apache(http)+php+wordpress搭建个人站点

[复制链接]

尚未签到

发表于 2018-11-21 10:03:34 | 显示全部楼层 |阅读模式
  [root@localhost data]# 安装次序很重要:apr --> apr-util --> apache --> MySQL -->php--->Xcache ——>wordpress
  架构:LAMP一直很受大众喜欢,完全能满足基本需求。当访问量大时可以尝试LNMP架构,做到前端负载均衡访问。
  下载:各安装包已放到云盘上,http://pan.baidu.com/s/1gd1uWTX
  一、安装编译apache
  1 编译安装apr
[root@localhost data]#tar xf apr-1.4.6.tar.bz2 [root@localhost data]#cd apr-1.4.6 [root@localhost apr-1.4.6]#./configure --prefix=/data/apr #####软件包安装的路径统一放在第三方软件位置:/data/ [root@localhost apr-1.4.6]#make  [root@localhost apr-1.4.6]#make install  2 编译安装apr-util

  •   [root@localhost data]#tar xf apr-util-1.5.2.tar.bz2
  •   [root@localhost data]#cd apr-util-1.5.2
  •   [root@localhost apr-util-1.5.2]#./configure –prefix=/data/apr-util –with-apr=/data/apr
  •   ####指定apr-util和apr安装路径
  3 安装pcre-devel软件包

  •   [root@localhost data]# yum install pcre-devel
  4 编译安装httpd-2.4.4

  •   [root@localhost data]# tar xf httpd-2.4.4.tar.bz2
  •   [root@localhost data]# cd httpd-2.4.4
  •   [root@localhost httpd-2.4.4]#./configure --prefix=/data/apache –sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/data/apr-util --enable-mpms-shared=all --with-mpm=event
  •   说明:--prefix=/data/apache    ####httpd安装路径
  •   --sysconfdir=/etc/httpd      ####系统配置文件目录路径
  •   --enable-so       ######支持共享模块功能
  •   --enable-ssl            #####支持ssl功能
  •   --enable-cgi       ####支持cgi功能
  •   --enable-rewrite    ####支持重写功能
  •   --with-zlib         #####支持扩展库文件功能
  •   --with-pcre       #####支持pcre功能
  •   --with-apr=/data/apr       ######指定apr安装路径
  •   --with-apr-util=/data/apr-util     #####指定apr-util安装路径
  •   --enable-mpms-shared=all      #####表示此平台的mpm模块都会被安装
  •   --with-mpm=event       #####特指定mpm模块为event,mpm模块可以在配置文件中修改
  •   [root@localhost httpd-2.4.4]#make
  •   [root@localhost httpd-2.4.4]#setenforce 0       #####由于web服务是受selinux控制会导致系统运行不起来,要把selinux的功能关掉
  •   [root@localhost httpd-2.4.4]#make install
  5 修改httpd的主配置文件,设置其pid文件的路径

  •   [root@localhost httpd-2.4.4]#vim /etc/httpd/httpd.conf
  •   添加内容:PidFile  “/var/run/httpd.pid”
  •   保存退出
6 为httpd提供服务脚本

  •   [root@localhost data]#cp /httpd-2.4.4/build/rpm/httpd.init  /etc/rc.d/init.d/httpd
  •   [root@localhost data]#vim /etc/rc.d/init.d/httpd
  •   说明:修改配置文件
       1:  #!/bin/bash   2:  #   3:  # Licensed to the Apache Software Foundation (ASF) under one or more   4:  # contributor license agreements.  See the NOTICE file distributed with   5:  # this work for additional information regarding copyright ownership.   6:  # The ASF licenses this file to You under the Apache License, Version 2.0   7:  # (the "License"); you may not use this file except in compliance with   8:  # the License.  You may obtain a copy of the License at   9:  #  10:  #     http://www.apache.org/licenses/LICENSE-2.0  11:  #  12:  # Unless required by applicable law or agreed to in writing, software  13:  # distributed under the License is distributed on an "AS IS" BASIS,  14:  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  15:  # See the License for the specific language governing permissions and  16:  # limitations under the License.  17:  #  18:  #  19:  # httpd        Startup script for the Apache Web Server  20:  #  21:  # chkconfig: - 85 15  22:  # description: The Apache HTTP Server is an efficient and extensible  \  23:  #             server implementing the current HTTP standards.  24:  # processname: httpd  25:  # pidfile: /var/run/httpd.pid  26:  # config: /etc/httpd/httpd.conf  27:  ### BEGIN INIT INFO  28:  # Provides: httpd  29:  # Required-Start: $local_fs $remote_fs $network $named  30:  # Required-Stop: $local_fs $remote_fs $network  31:  # Should-Start: distcache  32:  # Short-Description: start and stop Apache HTTP Server  33:  # Description: The Apache HTTP Server is an extensible server  34:  #  implementing the current HTTP standards.  35:  ### END INIT INFO  36:  37:  # Source function library.  38:  . /etc/rc.d/init.d/functions  39:  40:  # What were we called? Multiple instances of the same daemon can be  41:  # created by creating suitably named symlinks to this startup script  42:  prog=$(basename $0 | sed -e 's/^[SK][0-9][0-9]//')  43:  44:  if [ -f /etc/sysconfig/${prog} ]; then  45:          . /etc/sysconfig/${prog}  46:  fi  47:  # Start httpd in the C locale by default.  48:  HTTPD_LANG=${HTTPD_LANG-"C"}  49:  50:  # This will prevent initlog from swallowing up a pass-phrase prompt if  51:  # mod_ssl needs a pass-phrase from the user.  52:  INITLOG_ARGS=""  53:  54:  # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server  55:  # with the thread-based "worker" MPM; BE WARNED that some modules may not  56:  # work correctly with a thread-based MPM; notably PHP will refuse to start.  57:  apachectl=/database/apache/bin/apachectl  58:  httpd=${HTTPD-/database/apache/bin/httpd}  59:  pidfile=${PIDFILE-/var/run/${prog}.pid}  60:  lockfile=${LOCKFILE-/var/lock/subsys/${prog}}  61:  RETVAL=0  62:  63:  # check for 1.3 configuration  64:  check13 () {  65:          CONFFILE=/etc/httpd/httpd.conf  66:          GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"  67:          GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"  68:          GONE="${GONE}AccessConfig|ResourceConfig)"  69:          if grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then  70:                  echo  71:                  echo 1>&2 " Apache 1.3 configuration directives found"  72:                  echo 1>&2 " please read @docdir@/migration.html"  73:                  failure "Apache 1.3 config directives test"  74:                  echo  75:                  exit 1  76:          fi  77:  }  78:  # The semantics of these two functions differ from the way apachectl does  79:  # things -- attempting to start while running is a failure, and shutdown  80:  # when not running is also a failure.  So we just do it the way init scripts  81:  # are expected to behave here.  82:  start() {  83:          echo -n $"Starting $prog: "  84:          check13 || exit 1  85:          LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS  86:          RETVAL=$?  87:          echo  88:          [ $RETVAL = 0 ] && touch ${lockfile}  89:          return $RETVAL  90:  }  91:  stop() {  92:          echo -n $"Stopping $prog: "  93:          killproc -p ${pidfile} -d 10 $httpd  94:          RETVAL=$?  95:          echo  96:          [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}  97:  }  98:  reload() {  99:          echo -n $"Reloading $prog: " 100:          check13 || exit 1 101:          killproc -p ${pidfile} $httpd -HUP 102:          RETVAL=$? 103:          echo 104:  } 105: 106:  # See how we were called. 107:  case "$1" in 108:    start) 109:          start 110:          ;; 111:    stop) 112:          stop 113:          ;; 114:    status) 115:          if ! test -f ${pidfile}; then 116:              echo $prog is stopped 117:              RETVAL=3 118:          else 119:              status -p ${pidfile} $httpd 120:              RETVAL=$? 121:          fi 122:          ;; 123:    restart) 124:          stop 125:          start 126:          ;; 127:    condrestart) 128:          if test -f ${pidfile} && status -p ${pidfile} $httpd >&/dev/null; then 129:                  stop 130:                  start 131:          fi 132:          ;; 133:    reload) 134:          reload 135:          ;; 136:    configtest) 137:          LANG=$HTTPD_LANG $httpd $OPTIONS -t 138:          RETVAL=$? 139:          ;; 140:    graceful) 141:          echo -n $"Gracefully restarting $prog: " 142:          LANG=$HTTPD_LANG $httpd $OPTIONS -k $@ 143:          RETVAL=$? 144:          echo 145:          ;; 146:    *) 147:          echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|graceful|help|configtest}" 148:          exit 1 149:  esac 150:  exit $RETVAL

7 为httpd提供服务脚本   1:  [root@localhost httpd-2.4.4]#chmod +x /etc/rc.d/init.d/httpd  8 添加httpd为系统服务
   1:  [root@localhost ~]#chkconfig --add httpd  9 查看服务
   1:  [root@localhost ~]#netstat -ntl | grep 80
注:apache启动报告httpd: apr_sockaddr_info_get() failed错误。解决方法有两个:  修正方法有两种:
  1、不打开apache的httpd.conf关于ServerName申明,只修改/etc/hosts
  /etc/hosts修改内容如下(最后添加myservername申明):
  127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 myservername
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  2、直接修改httpd.conf关于ServerName定义
  ServerName myservername:80
  二、编译安装mysql
  请查看博文:http://strongit.blog.51cto.com/10020534/1659265
  三、编译安装php
  1 编译安装php-5.4.13
   1:  [root@localhost ~]# tar xf php-5.6.10.tar.gz   2:  [root@localhost ~]# cd php-5.6.10   3:  [root@localhost php-5.6.10]# ./configure --prefix=/data/php --with-mysql=/data/mysql --with-openssl --with-mysqli=/data/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/data/apache/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts   4:  说明:   5:  --prefix=/usr/local/php:php安装路径   6:  --with-mysql=/usr/local/mysql:mysql安装路径   7:  --with-openssl:支持openssl功能   8:  --with-mysqli=/usr/local/mysql/bin/mysql_config:mysql与apache访问的另一种接口,安装在二进制目录下   9:  --enable-mbstring:多字节string  10:  --with-freetype-dir:安装的字体库头文件  11:  --with-jpeg-dir:jpeg类型的库  12:  --with-png-dir:png类型的库  13:  --with-zlib:互联网上通用压缩库,先压缩再传送,减少带宽  14:  --with-libxml-dir=/usr:xml库文件的路径  15:  --enable-xml:支持xml功能  16:  --enable-sockets:php支持套接字功能  17:  --with-apxs2=/usr/local/apache/bin/apxs:基于apxs实现让php编译成apache模块  18:  --with-mcrypt:支持额外的加密库  19:  --with-config-file-path=/etc:php配置文件放置路径  20:  --with-config-file-scan-dir=/etc/php.d :php配置文件的分段文件放置路径  21:  --with-bz2 :压缩库  22:  --enable-maintainer-zts:当apache使用worker或event这两个MPM,编译时使用该选项  23:  ###我在执行./configure时候,出现了错误,提示我没有安装libmcrypt库文件,可以有两种解决方式:1、去掉该模块 2、下载依赖于该库文件的软件包,mhash*.rpm libmcrypt-*.rpm  24:  [root@localhost php-5.6.10]#make  25:  [root@localhost php-5.6.10]#make install  注:编译安装中会出现很多依赖关系,如果报错则安装相应依赖包。
  2 编辑配置文件
   1:  [root@localhost php-5.6.10]#cp php.ini-production /etc/php.ini   2:  [root@localhost php-5.6.10]#vim /etc/httpd/httpd.conf
DSC0000.jpg

   1:  [root@localhost php-5.6.10]#cd /data/apache/htdocs/     #####进入apache页面目录下,把默认页面修改为php页面文件   2:  [root@localhost htdocs]#mv index.html index.php   3:  [root@localhost htdocs]#vim index.php   4:  It works! my test page   5:     8:  保存退出   9:  #####发起php页面测试  10:  #####生成的测试页面内容对我们还是会有帮助,可以留意一下里面的内容  浏览器测试效果:
DSC0001.jpg

  图中,Success...是与mysql连接成功的返回信息,配置如下:
   1:  [root@localhost php-5.6.10]#vim /data/apache/htdocs/index.php   2:   3:  It works! my test page   4:    12:  保存退出  四、编译安装xcache,为php提速
  1 安装xcache-3.2.0
   1:  [root@localhost ~]# tar xf xcache-3.2.0.tar.gz   2:  [root@localhost ~]# cd xcache-3.2.0       ###xcache是php的扩展,要使用php命令加载此扩展   3:  [root@localhost xcache-3.2.0 ]# /datal/php/bin/phpize      ####phpize命令作用是要准备一个php扩展准备编译,所以扩展要先执行编译   4:  [root@localhostxcache-3.2.0 ]#./configure--enable-xcache--with-php-config=/data/php/bin/php-config   5:  #######php-config表示能够获取php的配置信息以及编译时的选项信息;   6:  ######由于不在默认路径下,xcache要获取php安装时所启用的功能,否则xcache会找不到php的路径   7:  [root@localhost xcache-3.2.0 ]#make   8:  [root@localhost xcache-3.2.0 ]#make install   9:  安装结束时,会出现类似如下行:  10:  Installing shared extensions:     /  11:  #####安装共享扩展模块路径,先把这个路径复制下来,等一下复制到xcache的配置文件中  2 编辑php.ini,整合php和xcache
   1:  [root@localhost xcache]# mkdir /etc/php.d   2:  [root@localhost xcache]# cp xcache.ini /etc/php.d    ###将xcache提供的样例配置导入php.ini   3:  [root@localhost xcache]#vim /etc/php.d/xcache.ini
DSC0002.jpg

  重启httpd服务,查看phpinfo()信息:
DSC0003.jpg

  五、安装wordpress
  准备工作:先创建好数据库,用户名等,解压到指定目录
   1:  cp wp-config-sample.php wp-config.php   2:  修改如下内容:   3:  /** WordPress数据库的名称 */   4:  define('DB_NAME', 'wordpress');   5:   6:  /** MySQL数据库用户名 */   7:  define('DB_USER', 'wordpress');   8:   9:  /** MySQL数据库密码 */  10:  define('DB_PASSWORD', 'wordpress');  11:  12:  /** MySQL主机 */  13:  define('DB_HOST', 'IP:3306');  14:  15:  /** 创建数据表时默认的文字编码 */  16:  define('DB_CHARSET', 'utf8');  17:  18:  /** 数据库整理类型。如不确定请勿更改 */  19:  define('DB_COLLATE', 'utf8_general_ci');添加apache虚拟主机:   1:  vim /etc/httpd/httpd.conf   2:     3:      ServerAdmin  fei110339@163.com   4:      DocumentRoot /data/apache/htdocs   5:      ServerName fei110339   6:    重启服务访问看看,http://localhost/wordpress
  如报错,查看日志:tail -f /data/apache/logs/error_log
  注:如出现forbidden的提示,需修改
   1:  vim /etc/httpd/httpd.conf   2:   3:     4:      Options FollowSymLinks   5:      AllowOverride None   6:     # Order deny,allow   7:     # Deny from all   8:    接下来,就可以使用您设置的用户名密码配置您的站点了。




运维网声明 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-637641-1-1.html 上篇帖子: Apache2.4.x与Apache2.2.x的一些区别 下篇帖子: LAMP搭建 (apache2.4 FCGI+php5+mysql5.5)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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