table of Contents
- I. Introduction
- Second, prepare the environment
- Third, compile and install MySQL
- Fourth, compile and install Apache
- Fifth, compile and install PHP
- Six subsequent configuration
- Seven start-related services
- Eight, the source compiler software Experience
- Nine, deploy web application
- Troubleshooting 1:
- Troubleshooting 2:
- Troubleshooting 3:
- We're done!
Course objectives
- Use Code ways to build a BBS forum or blog based on LAMP architecture
- This paper successfully built two websites, a personal blog, is a web application interface management mysql database
Please read the patient, careful operation, you will succeed!
Thoughts: yum tool to build the difference between lamp and source packages built environment
rpm version
Easy to install, upgrade, uninstall is very flexible, it is difficult or impossible to customize functions of the major components, suitable for mass deployment
Compile source packages
According to custom business needs, provided that you need to be very understanding of the function of the platform: uninstalling, upgrading, installation is not very convenient and flexible
How do the production environment
- Before on-line, compiled and installed in the test environment after debugging, the compiled source code synchronized to the rest of the hardware and software environment as the machine, can directly make install
- Before on-line, compiled and installed in the test environment, the debugging, the source packet is encapsulated into rpm package, and then use the bulk unified installation software deployment
I. Introduction
- LAMP (Linux + Apache + MySQL + Perl / PHP / Python) is an acronym that is generally used together to run dynamic Web sites. Although the open-source program itself is not specifically designed to work in conjunction with several other programs, but since they are free and open source, this combination became popular (most Linux distributions version bundled with the software), which leads to these components often used together. LAMP site architecture is the internationally popular web framework, is a very mature international architectural framework, many popular business applications are taken by the architecture. LAMP has a common, cross-platform, high-performance, low-cost advantages, so the lamp whether it is performance, quality and price are the platform of choice for enterprises to build the site, is now available for commercial web-type architecture synonymous.
- The goal of this chapter is entirely through the source code compiler installation, set up a LAMP environment, written in PHP and runs a web site.
Second, prepare the environment
1. The need to prepare the package
共享文件夹/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. Pre-installation Environment Preparation
清空环境,安装相应的软件包
yum -y groupinstall "Development tools"
yum -y groupinstall "Desktop Platform Development" 桌面开发工具包(图形化相关包)
yum install cmake
yum install ncurses-devel
3. Compile way
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的编译顺序也就无所谓了
Third, compile and install 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 official documents
Universal mounting https://dev.mysql.com/doc/refman/5.6/en/binary-installation.html binary commands (refer to the follow-up configuration)
Fourth, compile and install Apache
Preparing the Environment
rpm -q httpd
rpm -e httpd --nodeps
先清空环境(卸载2.2版本)
1. Install dependencies apr
Description:
In RHEL6.5 direct apache compiled version 2.4, will be reported the following error:
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/
Reflections: A software library files are likely to be called by other software, other software, you can find it in the library?
In general, libraries are installed to / lib, / lib64, / usr / lib /, / usr / lib64, etc., can be found: but if a software installation A library files to the / usr / local / A / lib under, to take this path to the ldconfig command can find a list of paths to go, others can be found.
ldconfig is a dynamic link library management commands: The main purpose is to search in the default directory (/ lib, / lib64, / usr / lib /, / usr / lib64 /)
Directory listed a dynamic library configuration file /etc/ld.so.conf in the search for a shareable dynamic link library.
Question: how to specify the installation path of the library file is added to ldconfig command of the search list?
方法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. Install the software 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
Configuration instructions:
# ./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/ 确认这个目录产生后,说明编译安装成功
Fifth, compile and install 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
Configuration instructions:
# ./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 \
Reference https://www.jianshu.com/p/0a79847c8151
https://www.cnblogs.com/fps2tao/p/7884011.html
Six subsequent configuration
1, the configuration of the contact apache and 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. Let php database of local support links
Description:
Local database is generally through the socket file link, while the local database file socket if not in the default path, you have to tell php to read the file from where the 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. The directory website plus write php test page
要跟随环境
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();
?>
Seven start-related services
启动数据库
启动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的编译安装和基本配置成功。
Eight, the source compiler software Experience
4. Thinking summary
Suppose there is a software aaa, installed into usr / difference between / usr / local / aaa / local and installed?
- Mounted to the / usr / local:
- advantage:
- This command is typically software installed into the / usr / local / bin or / usr / local / sbin the like;
- These paths are the default in your $ PATH, so the installation of command can be used directly, without using an absolute path;
- Libraries usually installed to / usr / locallib, so add it ldconfig, so after installation can be found in the library of files in this directory
- Disadvantages:
- Inconvenient to delete, because a lot of software installed in / usr / local
- advantage:
- Mounted to the / usr / local / aaa:
- In contrast to the above advantages and disadvantages
- Recommendation: Small software is installed by default in / usr / local, large software is installed in / usr / local / Software name
Nine, deploy web application
搭建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 [email protected]
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 [email protected]
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
Troubleshooting 1:
Troubleshooting 2:
The first reason: the database user name password wrong
The second reason: the unit does not allow the connection
[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';
修改之后重启服务果然能够登陆成功
Troubleshooting 3:
Myblog first establish a database in the native database
Then enter the native browser www.myblog.net, now click on Start, then enter myblog ---> root ---> 123, click submit, the following figure error.
[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');
After clicking submit retries, and error
Now enter the mysql database inside myblog delete and rebuild again, and then enter the page refreshes, empty the cache, the following error, this time only to think of the configuration file problem
Check / myblog following file permissions
Test again, or wrong
[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
test