ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

4-源码构建LAMP环境

2019-06-14 12:00:35  阅读:206  来源: 互联网

标签:apr lamp LAMP 源码 构建 usr mysql php root


4-源码构建LAMP环境

课程目标

  • 使用源码方式基于LAMP架构搭建BBS论坛或者博客
  • 本文成功搭建2个网站,一个个人博客,一个是web界面管理mysql数据库的应用

请耐心阅读,细心操作,你也会成功!

思考:yum工具搭建lamp环境和源码包搭建的区别

  • rpm版本

    安装方便,升级、卸载都很灵活,很难或者无法定制主要组件的功能,适合批量部署

  • 源码包编译

    根据业务需求定制,前提是必须对平台的功能需要非常了解:卸载、升级、安装并不是很方便灵活

  • 生产环境如何做

    • 上线前,在测试环境中编译安装并且调试完毕后,把编译后的源码同步到其余软硬环境一样的机器,直接 make install即可
    • 上线前,在测试环境中编译安装并且调试完毕后,把源码包封装成rpm包,再使用批量化部署软件进行统一安装

一、项目简介

  • LAMP(Linux+Apache+MySQL+Perl/PHP/Python)的一个缩写,它们通常一起使用来运行动态网站。虽然这些开放源代码程序本身并不是专门设计成同另外几个程序一起工作的,但由于它们的免费和开源,这个组合开始流行(大多数Linux发行版本捆绑了这些软件),这就导致这些组件经常在一起使用。LAMP网站架构是目前国际流行的web框架,是国际上非常成熟的架构框架,很多流行的商业应用都是采取这个架构的。LAMP具有通用、跨平台、高性能、低价格的优势,因此lamp无论是性能、质量还是价格都是企业搭建网站的首选平台,现已为商用型web架构代名词。
  • 本章的目标是完全通过源代码编译安装,组建一个LAMP的环境,并运行一个PHP写的web网站。

二、环境准备

1.需要准备的软件包

共享文件夹/LAMP下
apr-1.5.2.tar.bz2
apr-util-1.5.4.tar.bz2
httpd-2.4.12.tar.bz2
php-5.6.11.tar.xz
mysql-5.6.25.tar.gz

http://archive.apache.org/dist/
https://www.php.net/releases/

2.安装前环境准备

清空环境,安装相应的软件包
yum -y groupinstall "Development tools"
yum -y groupinstall "Desktop Platform Development"      桌面开发工具包(图形化相关包)
yum install cmake
yum install ncurses-devel

3.编译方式

Apache-->MySQL-->php    或者  MySQL-->Apache-->php
说明:
1.apache必须要先于PHP安装,因为PHP是作为apache的模块libphp.so,被apache加载调用
2.apache和MySQL之间并没有直接先后顺序的依赖,谁先谁后无所谓
3.在PHP-5.3版本前,MySQL必须先于php的编译,因为PHP需要实现连接数据库的功能,它通过MySQL的接口才能编译出该功能
4.在PHP-5.3版本或者之后,PHP已经集成了一套连接MySQL数据的代码,并不依赖MySQL的接口,这时,MySQL和PHP的编译顺序也就无所谓了

三、编译安装MySQL

版本:mysql-5.6.25.tar.gz
需求:
1.安装目录:/mysql25/mysql_basedir
2.数据目录:/mysql25/data
3.端口:3307(默认3306)
4.socket:/mysql25/mysql_basedir

安装:
1.官方网站下载相应软件包
2.解压

3.安装
1)创建相应的目录和用户并授权
[root@lamp ~]# cd /LAMP/
[root@lamp LAMP]# ll
total 32428
-rwxr-xr-x 1 root root 33203321 Apr 29 18:06 mysql-5.6.25.tar.gz
[root@lamp LAMP]# tar -xf mysql-5.6.25.tar.gz -C /usr/src/
[root@lamp LAMP]# ls /usr/src
debug  kernels  mysql-5.6.25
[root@lamp LAMP]# mkdir -p /mysql25/mysql_basedir 
[root@lamp LAMP]# mkdir /mysql25/data
[root@lamp LAMP]# id mysql  
id: mysql: No such user
//-r创建一个系统用户,-s指定默认的shell   /sbin/nologin  不能像其他用户一样登录操作系统
[root@lamp LAMP]# useradd -r mysql -s /sbin/nologin 
[root@lamp LAMP]# su - mysql
su: warning: cannot change directory to /home/mysql: No such file or directory
This account is currently not available.
[root@lamp LAMP]# id mysql
uid=496(mysql) gid=493(mysql) groups=493(mysql)
[root@lamp LAMP]# ll -d /mysql25/
drwxr-xr-x 4 root root 4096 Apr 29 18:32 /mysql25/
[root@lamp LAMP]# chown -R mysql.mysql /mysql25/    更改属主和属组为mysql
[root@lamp LAMP]# ll -d /mysql25/
drwxr-xr-x 4 mysql mysql 4096 Apr 29 18:32 /mysql25/
[root@lamp LAMP]# ll /mysql25/
total 8
drwxr-xr-x 2 mysql mysql 4096 Apr 29 18:32 data
drwxr-xr-x 2 mysql mysql 4096 Apr 29 18:32 mysql_basedir

2)进入到解压后的路径进行安装
[root@lamp ~]# cd /usr/src/mysql-5.6.25/
[root@lamp mysql-5.6.25]# pwd
/usr/src/mysql-5.6.25

根据需求配置:
查看官方文档
https://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

vim /usr/src/mysql-5.6.25
cmake . \
-DCMAKE_INSTALL_PREFIX=/mysql25/mysql_basedir/ \
-DMYSQL_DATADIR=/mysql25/data \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DSYSCONFDIR=/mysql25/mysql_basedir/etc \
-DMYSQL_TCP_PORT=3307 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DMYSQL_USER=mysql
编译:
make
安装:
make install
总结:
1.配置的时候,指定安装的路径,该路径可以存在也可以不存在,建议事先创建并且更改权限chown
2.系统默认自动创建,权限是root,需要自己更改


后续配置:(官方文档。。。2.2)
shell> scripts/mysql_install_db --user=mysql    默认初始化数据库到/var/lib/mysql
shell> bin/mysqld_safe --user=mysql &   启动mysql,&放在后台执行
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

[root@lamp mysql_basedir]# scripts/mysql_install_db --user=mysql --basedir=/mysql25/mysql_basedir/ --datadir=/mysql25/data/
[root@lamp mysql_basedir]# ll /mysql25/data/
total 110604
-rw-rw---- 1 mysql mysql 12582912 Apr 30 14:30 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Apr 30 14:30 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Apr 30 14:30 ib_logfile1
drwx------ 2 mysql mysql     4096 Apr 30 14:30 mysql
drwx------ 2 mysql mysql     4096 Apr 30 14:30 performance_schema
drwx------ 2 mysql mysql     4096 Apr 30 14:30 test
初始化成功
尝试启动
[root@lamp mysql_basedir]# bin/mysqld_safe --user=mysql
190430 14:34:18 mysqld_safe Logging to '/var/log/mysqld.log'.
190430 14:34:18 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
190430 14:34:21 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
发现问题,查看日志解决
[root@lamp ~]# tail -f /var/log/mysqld.log
2019-04-30 14:35:04 2798 [ERROR] /mysql25/mysql_basedir/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
2019-04-30 14:35:04 2798 [ERROR] Can't start server: can't create PID file: No such file or directory
190430 14:35:04 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[root@lamp mysql_basedir]# ll /var/lib/mysql/
total 110596
-rw-rw---- 1 mysql mysql       56 Apr 30 14:34 auto.cnf
-rw-rw---- 1 mysql mysql 12582912 Apr 30 14:34 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Apr 30 14:35 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Apr 30 14:34 ib_logfile1
srwxrwxrwx 1 mysql mysql        0 Apr 30 14:35 mysql.sock
发现mysql.sock又写入到/var/lib/mysql/里了,那么问题应该是环境没有清理干净
[root@lamp mysql_basedir]# ls /etc/my.cnf 
/etc/my.cnf
[root@lamp mysql_basedir]# rpm -qf /etc/my.cnf 果然发现5.1版本存在
mysql-libs-5.1.71-1.el6.x86_64
[root@lamp mysql_basedir]# cat /etc/my.cnf 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[root@lamp mysql_basedir]# bin/mysql --help
Default options are read from the following files in the given order:  读取顺序
/etc/my.cnf /etc/mysql/my.cnf /mysql25/mysql_basedir/etc/my.cnf ~/.my.cnf 
发现/etc/my.cnf优先读取

总结:
在启动数据库时,默认会到/var/lib/mysql里去找相应文件,系统有一个默认的配置文件/etc/my.cnf,在该文件中定义了数据目录/var/lib/mysql
解决:
1.删除/etc/my.cnf
2.修改/etc/my.cnf
清空/var/lib/mysql/*
再次启动,进行验证
[root@lamp ~]# ps -ef|grep mysql
root       2883   2329  0 14:49 pts/0    00:00:00 /bin/sh bin/mysqld_safe --user=mysql
mysql      2973   2883  1 14:49 pts/0    00:00:00 /mysql25/mysql_basedir/bin/mysqld --basedir=/mysql25/mysql_basedir --datadir=/mysql25/data --plugin-dir=/mysql25/mysql_basedir/lib/plugin --user=mysql --log-error=/mysql25/data/lamp.err --pid-file=/mysql25/data/lamp.pid
root       2999   2827  0 14:50 pts/1    00:00:00 grep mysql
[root@lamp ~]# netstat -nltp|grep 3307
tcp        0      0 :::3307                     :::*                        LISTEN      2973/mysqld 
顺利启动
[root@lamp ~]# pkill -9 mysqld      结束mysqld

如果希望使用service方式启动mysql,可以做如下配置
[root@lamp mysql_basedir]# cp support-files/mysql.server /etc/init.d/mysql25
[root@lamp mysql_basedir]# vim /etc/init.d/mysql25 此处无需修改
[root@lamp mysql_basedir]# netstat -nltp|grep 3307
[root@lamp mysql_basedir]# service mysql25 start
Starting MySQL                                             [  OK  ]
[root@lamp mysql_basedir]# netstat -nltp|grep 3307
tcp        0      0 :::3307                     :::*                        LISTEN      3133/mysqld
登录验证:
[root@lamp mysql_basedir]# bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.25 Source distribution

更改环境变量,以便用mysql直接登录
临时更改:
[root@lamp mysql_basedir]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@lamp mysql_basedir]# export PATH=/mysql25/mysql_basedir/bin:$PATH
[root@lamp mysql_basedir]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.25 Source distribution
永久更改:
[root@lamp ~]# vim /etc/profile
。。。在文件最后增加以下
export PATH=/mysql25/mysql_basedir/bin:$PATH
[root@lamp ~]# source /etc/profile      重新读取配置文件


设置密码:
[root@lamp ~]# mysqladmin -uroot password '123'
Warning: Using a password on the command line interface can be insecure.
[root@lamp ~]# mysql -uroot -p123

https://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html 官方文档

https://dev.mysql.com/doc/refman/5.6/en/binary-installation.html通用二进制命令安装(后续配置参照)

四、编译安装Apache

环境准备

rpm -q httpd
rpm -e httpd --nodeps
先清空环境(卸载2.2版本)

1.安装依赖包apr

说明:

在RHEL6.5下直接编译apache的2.4版本,会报下面的错误:

checking for APR... configure: WARNING: APR version 1.4.0 or later is required,found 1.3.9
configure: WARNING: skipped APR at apr-1-config, version not acceptable

原因:表示系统自带的apr软件版本为1.3.9,但需要1.4.0以上的版本

解决方法:
第一种:把apache降为2.2系列
第二种:去下载新版本apr先编译,再编译apache调用它(选择第二种)
安装apr软件
[root@lamp LAMP]# ll
total 50156
-rwxr-xr-x 1 root root   826885 Apr 30 16:57 apr-1.5.2.tar.bz2
-rwxr-xr-x 1 root root   694427 Apr 30 16:57 apr-util-1.5.4.tar.bz2
-rwxr-xr-x 1 root root  5054838 Apr 30 16:57 httpd-2.4.12.tar.bz2
-rwxr-xr-x 1 root root 33203321 Apr 29 18:06 mysql-5.6.25.tar.gz
-rwxr-xr-x 1 root root 11569588 Apr 30 16:57 php-5.6.11.tar.xz
[root@lamp LAMP]# cd
[root@lamp ~]# 
[root@lamp ~]# cd /LAMP/
[root@lamp LAMP]# ll
total 50156
-rwxr-xr-x 1 root root   826885 Apr 30 16:57 apr-1.5.2.tar.bz2
-rwxr-xr-x 1 root root   694427 Apr 30 16:57 apr-util-1.5.4.tar.bz2
-rwxr-xr-x 1 root root  5054838 Apr 30 16:57 httpd-2.4.12.tar.bz2
-rwxr-xr-x 1 root root 33203321 Apr 29 18:06 mysql-5.6.25.tar.gz
-rwxr-xr-x 1 root root 11569588 Apr 30 16:57 php-5.6.11.tar.xz
[root@lamp LAMP]# tar -xf apr-1.5.2.tar.bz2 -C /usr/src/
[root@lamp LAMP]# tar -xf apr-util-1.5.4.tar.bz2 -C /usr/src/
[root@lamp LAMP]# cd /usr/src/
[root@lamp src]# ll
total 20
drwxr-xr-x  27 1000  1000 4096 Apr 25  2015 apr-1.5.2
drwxr-xr-x  19 1000  1000 4096 Sep 17  2014 apr-util-1.5.4
drwxr-xr-x.  2 root root  4096 Sep 23  2011 debug
drwxr-xr-x.  3 root root  4096 Apr 18 21:18 kernels
drwxr-xr-x  35 7161 wheel 4096 Apr 29 22:14 mysql-5.6.25
[root@lamp src]# cd apr-1.5.2/
[root@lamp apr-1.5.2]# ls
apr-config.in  build-outputs.mk  helpers       misc           strings
apr.dep        CHANGES           include       mmap           support
apr.dsp        CMakeLists.txt    libapr.dep    network_io     tables
apr.dsw        config.layout     libapr.dsp    NOTICE         test
apr.mak        configure         libapr.mak    NWGNUmakefile  threadproc
apr.pc.in      configure.in      libapr.rc     passwd         time
apr.spec       docs              LICENSE       poll           tools
atomic         dso               locks         random         user
build          emacs-mode        Makefile.in   README
buildconf      encoding          Makefile.win  README.cmake
build.conf     file_io           memory        shmem
[root@lamp apr-1.5.2]# ./configure
[root@lamp apr-1.5.2]# make
[root@lamp apr-1.5.2]# make install
默认安装到/usr/local
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config

配置apr-util-1.5.4
[root@lamp apr-1.5.2]# cd ..
[root@lamp src]# ls
apr-1.5.2  apr-util-1.5.4  debug  kernels  mysql-5.6.25
[root@lamp src]# cd apr-util-1.5.4/
[root@lamp apr-util-1.5.4]# ./configure --with-apr=/usr/local/apr/bin/apr-1-config
[root@lamp apr-util-1.5.4]# make
[root@lamp apr-util-1.5.4]# make install
Libraries have been installed in:
   /usr/local/apr/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr/bin/apu-1-config

以下操作配置库文件的默认检索路径
[root@lamp apr-util-1.5.4]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
[root@lamp apr-util-1.5.4]# ll /etc/ld.so.conf.d/
total 20
-r--r--r--. 1 root root 324 Nov 22  2013 kernel-2.6.32-431.el6.x86_64.conf
-rw-r--r--. 1 root root  17 Nov 23  2013 mysql-x86_64.conf
-rw-r--r--. 1 root root  22 Sep 24  2011 qt-x86_64.conf
-rw-r--r--  1 root root 276 Apr 29 17:37 vmware-tools-libraries.conf
-rw-r--r--. 1 root root  21 Oct 30  2013 xulrunner-64.conf
[root@lamp apr-util-1.5.4]# cat /etc/ld.so.conf.d/mysql-x86_64.conf 
/usr/lib64/mysql
[root@lamp apr-util-1.5.4]# echo /usr/local/apr/lib/ > /etc/ld.so.conf.d/lamp.conf
[root@lamp apr-util-1.5.4]# ldconfig
[root@lamp apr-util-1.5.4]# cat /etc/ld.so.conf.d/lamp.conf 
/usr/local/apr/lib/

思考:一个软件的库文件是有可能被其他软件所调用,那么其他软件能否找到你的库文件呢?

  • 一般来说,库文件安装到/lib,/lib64,/usr/lib/,/usr/lib64等,都可以找到:但是如果一个软件A把库文件安装到/usr/local/A/lib下,就要把这个路径添加到 ldconfig 命令可以找到的路径列表里去,别人才能找到。

  • ldconfig是一个动态链接库管理命令:主要用途是在默认搜索目录(/lib,/lib64,/usr/lib/,/usr/lib64/)

    一级动态库配置文件/etc/ld.so.conf中所列的目录中搜索出可共享的动态链接库。

问题:怎样将库文件的指定安装路径加入到 ldconfig命令的搜索列表中?

方法1:在/etc/ld.so.conf这个主配置文件里面加上一行,写上让别人要查找库文件的路径
方法2:在/etc/ld.so.conf.d/目录下创建一个*.conf结尾的文件,里面加入该路径即可

echo /usr/local/apr/lib/ > /etc/ld.so.conf.d/lamp.conf
ldconfig    加入该路径后,使用此命令让其生效

2.安装httpd软件

版本:httpd-2.4.12.tar.bz2
1.下载 http://archive.apache.org/dist/
2.解压
3.安装(解压的目录里)
[root@lamp ~]# cd /LAMP/
[root@lamp LAMP]# ls
apr-1.5.2.tar.bz2       httpd-2.4.12.tar.bz2  php-5.6.11.tar.xz
apr-util-1.5.4.tar.bz2  mysql-5.6.25.tar.gz
[root@lamp LAMP]# tar -xf httpd-2.4.12.tar.bz2 -C /usr/src/
[root@lamp LAMP]# cd /usr/src/
[root@lamp src]# ls
apr-1.5.2  apr-util-1.5.4  debug  httpd-2.4.12  kernels  mysql-5.6.25
[root@lamp src]# cd httpd-2.4.12/
[root@lamp httpd-2.4.12]# ls
ABOUT_APACHE     CHANGES         INSTALL         os
acinclude.m4     CMakeLists.txt  InstallBin.dsp  README
Apache-apr2.dsw  config.layout   LAYOUT          README.cmake
Apache.dsw       configure       libhttpd.dsp    README.platforms
apache_probes.d  configure.in    LICENSE         ROADMAP
ap.d             docs            Makefile.in     server
build            emacs-style     Makefile.win    srclib
BuildAll.dsp     httpd.dsp       modules         support
BuildBin.dsp     httpd.spec      NOTICE          test
buildconf        include         NWGNUmakefile   VERSIONING
[root@lamp httpd-2.4.12]#

配置:
./configure \
--enable-modules=all \
--enable-mods-shared=all \
--enable-so \
--enable-rewrite \
--with-mpm=prefork \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-apr-util=/usr/local/apr/bin/apu-1-config

[root@lamp httpd-2.4.12]# vim apache.sh
[root@lamp httpd-2.4.12]# chmod +x apache.sh 
[root@lamp httpd-2.4.12]# cat apache.sh
./configure \
--enable-modules=all \
--enable-mods-shared=all \
--enable-so \
--enable-rewrite \
--with-mpm=prefork \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-apr-util=/usr/local/apr/bin/apu-1-config
[root@lamp httpd-2.4.12]# ./apache.sh 
报错
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

[root@lamp httpd-2.4.12]# yum list|grep pcre    检查有没有pcre
pcre.x86_64                               7.8-6.el6                   @anaconda-CentOS-201311272149.x86_64/6.5  已安装
mingw32-pcre.noarch                       8.10-2.el6.5                local-yum 
pcre.i686                                 7.8-6.el6                   local-yum 
pcre-devel.i686                           7.8-6.el6                   local-yum 
pcre-devel.x86_64                         7.8-6.el6                   local-yum 
pcre-static.x86_64                        7.8-6.el6                   local-yum 

发现已安装,那么问题是pcre-devel没有安装
[root@lamp httpd-2.4.12]# yum -y install pcre-devel
安装之后再次执行配置脚本apache.sh
[root@lamp httpd-2.4.12]# ./apache.sh
[root@lamp httpd-2.4.12]# make
[root@lamp httpd-2.4.12]# make install
[root@lamp httpd-2.4.12]# ls /usr/local/apache2/
bin    cgi-bin  error   icons    logs  manual
build  conf     htdocs  include  man   modules

配置说明:

# ./configure \
--enable-modules=all \      加载所有支持模块
--enable-mods-shared=all \  共享方式加载大部分常用模块
--enable-so \           启用动态模块加载功能
--enable-rewrite \      启用地址重写功能
--with-mpm=prefork \    插入式并行处理模块,称为多路处理模块,Prefork是类UNIX平台上默认的MPM
--with-apr=/usr/local/apr/bin/apr-1-config \    指定依赖软件apr路径
--with-apr-util=/usr/local/apr/bin/apu-1-config

# make
# make install

# ls /usr/local/apache2/ 确认这个目录产生后,说明编译安装成功

五、编译安装PHP

版本:php-5.6.11.tar.xz
1.下载  https://www.php.net/releases/
2.解压
[root@lamp httpd-2.4.12]# cd /LAMP/
[root@lamp LAMP]# ls
apr-1.5.2.tar.bz2       httpd-2.4.12.tar.bz2  php-5.6.11.tar.xz
apr-util-1.5.4.tar.bz2  mysql-5.6.25.tar.gz
[root@lamp LAMP]# tar -xf php-5.6.11.tar.xz -C /usr/src/
[root@lamp LAMP]# cd /usr/src
[root@lamp src]# ls
apr-1.5.2       debug         kernels       php-5.6.11
apr-util-1.5.4  httpd-2.4.12  mysql-5.6.25
[root@lamp src]# cd php-5.6.11/
[root@lamp php-5.6.11]# pwd
/usr/src/php-5.6.11
3.安装(在解压目录里)
1)配置
[root@lamp php-5.6.11]# vim php.sh
[root@lamp php-5.6.11]# chmod +x php.sh 
[root@lamp php-5.6.11]# ./php.sh

./php.sh: line 5: --with-mysqli=/mysql25/mysql_basedir/bin/mysql_config: No such file or directory
./php.sh: line 7: --with-zlib: command not found
./php.sh: line 26: --enable-calender: command not found
检查脚本文件的书写是否有误,一般都是因为 转义换行的\没加,导致下面的错误

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
2)编译
[root@lamp php-5.6.11]# make

Build complete.
Don't forget to run 'make test'
3)安装
[root@lamp php-5.6.11]# make install

[root@lamp php-5.6.11]# ls /usr/local/apache2/modules/libphp5.so 
/usr/local/apache2/modules/libphp5.so


配置说明:

# ./configure \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql/ \    要改成自定义的目录   /mysql25/mysql_basedir
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql \ 链接mysql模块
--with-zlib \
--with-zlib-dir=/usr/local/mysql/zlib \  数据压缩用的函数库
--with-curl \
--enable-zip \
--with-gd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-opcache \
--enable-mbstring \
--enable-mbregex \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm
--enable-calendar \
--enable-bcmath \

with-apxs2  调用apache加载模块支持PHP
gd          画图库
libiconv    字符变换转换
libmcrypt   字符加密
mcrypt      字符加密
mhash       哈希运算


make    //make成功后,会显示让你make test,不用做
make install

ls /usr/local/apache2/modules/libphp5.so    确认有这个.so模块文件,就表示编译PHP成功

# ./configure \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/mysql25/mysql_basedir \
--with-mysqli=/mysql25/mysql_basedir/bin/mysql_config \
--with-pdo-mysql=/mysql25/mysql_basedir \
--with-zlib \
--with-zlib-dir=/mysql25/mysql_basedir/zlib \
--with-curl \
--enable-zip \
--with-gd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-opcache \
--enable-mbstring \
--enable-mbregex \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-calendar \
--enable-bcmath \

参考https://www.jianshu.com/p/0a79847c8151

https://www.cnblogs.com/fps2tao/p/7884011.html

六、后续配置

1、配置apache和php的联系

1.修改apache配置文件
# vim /usr/local/apache2/conf/httpd.conf
1>配置优先支持中文
LoadModule negotiation_modules/mod_negotiation.so   此模块打开注释
Include conf/extra/httpd-languages.conf 打开此选项,扩展配置文件就生效了

# vim /usr/local/apache2/conf/extra/httpd-languages.conf    修改子配置文件
DefaultLanguage zh-CN   打开注释,默认语言集改为中文 (可无)
LanguagePriority zh-CN en ca ...语言及优先集,把zh-CN写到前面

2>配置apache对php支持    也就是apache和php的联系
# vim /usr/local/apache2/conf/httpd.conf
LoadeModule php5_module     modules/libphp5.so  找这一句,在这句下面加上两句
AddHandler php5-script      .php    添加两行,告诉httpd把.php文件交给模块去编译
AddType text/html   .php    这两句的意思是以.php结尾的文件都认为是php程序文件,注意这两句的.php前面都是有一个空格的

3>默认主页加上index.php,并放在index.html前,支持php的首页文件

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

4>配置网站家目录   (此处暂不配置)
DocumentRoot "/web"

默认:/usr/local/apache2/htdocs/index.php

到第九节配置虚拟主机
[root@lamp ~]# vim /usr/local/apache2/conf/httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

2.让php支持链接本地的数据库

说明:

本地数据库一般是通过socket文件链接,而本地数据库的socket文件如果不在默认路径,就必须告诉php从哪里读取socket文件。

# cp /usr/src/php-5.6.11/php.ini-production /usr/local/lib/php.ini
vim /usr/local/lib/php.ini
...

[MySQL]
mysql.default_port=3307
mysql.default_socket = /mysql25/mysql_basedir

[MySQLi]
mysql.default_port=3307
mysql.default_socket = /mysql25/mysql_basedir

3.网站加目录里写php测试页

要跟随环境
DocumentRoot "/usr/local/apache2/htdocs"
[root@lamp ~]# cd /usr/local/apache2/htdocs
[root@lamp htdocs]# ls
index.html
[root@lamp htdocs]# mv index.html index.php
[root@lamp htdocs]# vim index.php
<?php
        phpinfo();
?>

七、启动相关服务

启动数据库
启动apache

[root@lamp htdocs]# /usr/local/apache2/bin/apachectl start
AH00557: httpd: apr_sockaddr_info_get() failed for lamp
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

[root@lamp htdocs]# netstat -nltp|grep 80
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1803/sshd           
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1380/cupsd          
tcp        0      0 :::80                       :::*                        LISTEN      3492/httpd

看到下图就表示lamp的编译安装和基本配置成功。

八、源码编译软件经验总结

1556695898235

1556695948894

1556696044430

4.思考总结

假设有一个软件aaa,安装到/usr/local和安装到/usr/local/aaa之间的区别?

  • 安装到/usr/local下:
    • 优点:
      1. 此软件的命令一般会安装到/usr/local/bin或者/usr/local/sbin等;
      2. 这些路径都默认在$PATH里,所以安装的命令可以直接使用,而不用使用绝对路径;
      3. 库文件一般都会安装到/usr/locallib下,所以把它加入ldconfig,以后所以安装在此目录的库文件都可以被找到
    • 缺点:
      1. 不方便删除,因为很多软件都安装在/usr/local下
  • 安装到/usr/local/aaa下:
    • 优缺点与上面相反
  • 建议:小软件默认安装在/usr/local下,大软件安装在/usr/local/软件名下

九、部署web应用

搭建Discuz论坛
Discuz_X3.2_SC_UTF8.zip     Discuz论坛
phpwind_v9.0.1_utf8.zip     wind论坛
phpMyAdmin-4.4.11-all-language.zip      php写的mysql的管理工具(类似oracle的OEM)
wordpress-4.7.3-zh_CN.tar.gz    博客

需求:
搭建2个网站,一个个人博客,一个是web界面管理mysql数据库的应用

步骤:
1.创建两个目录来分别存放不同的网站
apache2.4版本用户为
User daemon
Group daemon

mkdir   /webserver/{admin,myblog} -p
2.拷贝网站相关的数据到网站目录里
unzip phpMyAdmin-4.4.11-all-languages.zip -d /usr/src/
tar xf wordpress-4.7.3-zh_CN.tar.gz -C /usr/src
cd phpMyAdmin-4.4.11-all-languages/
ls
cp -a ./* /webserver/admin/
cd ..
cp -a wordpress/* /webserver/myblog/
修改权限
chown -R daemon. /webserver
3.通过虚拟主机将网站发布出去

虚拟主机:

# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/webserver/admin"
    ServerName www.mysqladmin.cc
#   ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/webserver/myblog"
    ServerName www.myblog.net
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>

打开主配置文件里面的模块
[root@lamp ~]# vim /usr/local/apache2/conf/httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf    去掉注释

4.重启服务
/usr/local/apache2/bin/apachectl start

5.测试验证

出现403错误,首先查看目录权限都是daemon,接着查看主配置文件,修改如下
<Directory />
    AllowOverride none
    #Require all denied   版本原因,2.4的apache目录拒绝所有人访问
    Require all granted     
</Directory>
重启服务后重新测试





phpwind论坛:
# cp -a phpMyAdmin-4.0.2-all-language/* /webserver/bbswind
# cd /webserver/bbswind
# mv config.sample.inc.php  config.inc.php
$cfg['blowfish_secret']='a8sfdfkjsafaf';随便修改
。。。
$cfg['Servers'][$i]['host'] = 'localhost';  如果登录不成功尝试修改为127.0.0.1

排错1:

排错2:

第一个原因:数据库用户名密码不对

第二个原因:本机不允许连接

[root@lamp admin]# cp config.sample.inc.php config.inc.php
[root@lamp admin]# vim config.inc.php
#$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['host'] = '127.0.0.1';
修改之后重启服务果然能够登陆成功

排错3:

先在本机数据库建立一个myblog的database

​ 然后进入本机浏览器www.myblog.net,点击 现在就开始 ,然后依次输入myblog--->root--->123,点击提交,出现下图错误。

[root@lamp myblog]# cp wp-config-sample.php wp-config.php
[root@lamp myblog]# vim wp-config.php 

/** WordPress数据库的名称 */
define('DB_NAME', 'myblog');

/** MySQL数据库用户名 */
define('DB_USER', 'root');

/** MySQL数据库密码 */
define('DB_PASSWORD', '123');

点击重试之后提交,又出错

现在进入到mysql里面删除myblog数据库,再次重建,然后进入网页刷新,清空缓存,出现下面的错误,这个时候只能是思考配置文件的问题

检查一下/myblog下面的文件权限

再次测试,还是错误

[root@lamp myblog]# chown daemon. wp-config.php 
[root@lamp myblog]# vim wp-config.php 

// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'myblog');

/** MySQL数据库用户名 */
define('DB_USER', 'root');

/** MySQL数据库密码 */
define('DB_PASSWORD', '123');

/** MySQL主机 */
define('DB_HOST', '127.0.0.1');     修改为127.0.0.1

[root@lamp myblog]# /usr/local/apache2/bin/apachectl restart
AH00557: httpd: apr_sockaddr_info_get() failed for lamp
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

测试

大功告成!

标签:apr,lamp,LAMP,源码,构建,usr,mysql,php,root
来源: https://www.cnblogs.com/liuwei-xd/p/11022588.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有