教程简介
本教程内容如下:
1.两个流行的Web服务器
apache 2.4.23
nginx 1.13.5
2.一个开源数据库
mysql 5.7.15
3.两个版本的PHP
PHP 5.6.24
PHP 7.1.9
4. 安装相应扩展
PHP 5.6.24以安装Redis扩展为例
PHP 7.1.9以找回PHP 7废弃的mysql扩展为例
当然不推荐使用php-mysql扩展,本教程只是演示
安装
准备安装包
apache Web服务器
httpd-2.4.23.tar.bz2
nginx Web服务器
nginx-1.13.5.tar.gz
mysql 开源数据库
mysql-5.7.15.tar.gz
php php网站源码解析器
php-5.6.24.tar.gz
cmake c语言自动化编译工具,本教程使用cmake编译mysql(高版本的mysql都是用cmake编译,以前低版本的用make就行)
cmake-3.6.2.tar.gz
libmcrypt PHP libmcrypt模块,php中用于加密的模块
libmcrypt-2.5.8.tar.gz
libvpx PHP libvpx模块,php中的vp9视频编译器
libvpx-1.6.0.zip
libpng PHP libpng模块,php中用于处理png的扩展
libpng-1.2.31.tar.gz
jpegsrc PHP jpeg模块,php中用于处理jpeg的扩展
jpegsrc.v9a.tar.gz
apr Apache库文件,Apache兼容多平台的底层支持接口库
apr-1.5.2.tar.bz2
apr-util Apache库文件,apr的工具库
apr-util-1.5.4.tar.gz
boost C++准标准库,使用cmake安装mysql时需要使用,低版本的不需要boost
boost_1_59_0.tar.gz
mysql 5.7对应的Boost版本为1.59.0,其他版本的不行(包括高版本的)。
下载地址:https://jaist.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
安装基础开发环境
移除系统自带的低版本软件包
yum -y remove apr-util-devel apr apr-util-mysql apr-docs apr-devel apr-util apr-util-docs
安装编译器,链接器,构建工具,依赖的基础库,补丁工具等
yum -y install make apr autoconf automake gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm freetype libjpeg libpng php-common php-gd ncurses libtool libxml2 libxml2 libvpx libjpeg libpng libXpm patch nsd yasm
出现以下内容,不用管,继续下面的步骤安装。
--> 处理 compat-qpid-cpp-client-0.24-19.el7.x86_64 与 qpid-cpp-client 的冲突 --> 解决依赖关系完成 错误:compat-qpid-cpp-client conflicts with qpid-cpp-client-1.36.0-1.el7.x86_64 您可以尝试添加 --skip-broken 选项来解决该问题 您可以尝试执行:rpm -Va --nofiles --nodigest
安装libmycrpt
1 | cd libmycrypt-2.5.8 |
安装libvpx
1 | cd ../libvpx-1.6.0 |
不加–enable-shared在PHP编译时会遇到以下错误:
1 | /usr/bin/ld: /usr/local/libvpx/lib/libvpx.a(vpx_codec.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC |
1 | make -j |
安装jpeg
1 | cd ../jpeg-9a |
##
安装libpng
1 | cd ../libpng-1.2.31 |
安装cmake
1 | ./configure |
make -j如果出错
rm -f CMakeCache.txt
安装apr
1 | cd ../apr-1.5.2 |
安装apr-util
1 | cd ../apr-util-1.5.4 |
安装nginx
1 | cd ../nginx-1.13.5/ |
安装mysql
1 | groupadd mysql #添加mysql组 |
安装前将boot_1_59_0.tar.gz压缩包放在/usr/local/boost_1_59_0/目录下
1 | [root@local boost_1_59_0]# pwd |
1 | cd /usr/local/src/mysql-5.7.15 |
编译mysql需要消耗大量时间,cc1plus会占用大量CPU和内存,主要是CPU,内存会占用的少一点,加上-j参数会快很多,但是配置低的话加上-j会出现CPU,内存不足等而失败。
我的用-j在55%的时候出现这个:
c++: 编译器内部错误:已杀死(程序 cc1plus)
编译的时候时候非常慢,可以看看都生成了哪些二进制可执行文件,听说Gento Linux编译需要几天。
48.1MB的.tar.gz编译完成后的文件用du -sh .统计了一下,5.0G,如果用tar打包成.tar.gz应该有600多MB,mysql官网已经编译好的Linux通用的mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz有610MB。
make -j install
安装后/usr/local/mysql大小1.9G。
配置mysql
1 | cd /usr/local/mysql |
vim my.cnf
1 | basedir = /usr/local/mysql |
vim /etc/init.d/mysqld
1 | basedir=/usr/local/mysql |
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
如果出现这个
2017-09-16T16:00:04.136525Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
执行
1 | rm -rf /usr/local/mysql/data/* |
1 | cd lib |
解决PHP 检查环境时以下错误
1 | configure: error: Cannot find libmysqlclient_r under /usr/local/mysql. |
启动mysql及检查状态
1 | [root@local mysql]# systemctl start mysqld.service #启动mysql |
安装apache
1 | cd /usr/local/src/httpd-2.4.23 |
1 | /usr/local/apache2/bin/apachectl -k start #启动apache |
打开浏览器输入ip地址,将看到以下内容
It works!
如果出错,检查一下哪里的权限有问题。
配置apache
1 | cd /usr/local/apache2 |
找到AllowOverride None
修改为:AllowOverride All #开启apache支持伪静态,有两处都做修改
找到:Options Indexes FollowSymLinks
修改为:Options FollowSymLinks #不显示目录结构
找到:DirectoryIndex index.html
修改为:DirectoryIndex index.html index.php
<Files “.ht*”>
Require all denied
</Files>
修改为
<Files “.ht*”>
Require all granted
</Files>
LoadModule rewrite_module modules/mod_rewrite.so #取消前面的#号,开启apache支持伪静态
ServerName 0.0.0.0:80
解决启动/关闭/重启时的警告
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
1 | cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd #将apache服务器管理程序复制到相应目录方便使用系统命令管理 |
/usr/local/apache2/bin/apachectl start
chmod +x /etc/rc.d/rc.local
安装PHP5.6.24
cd /usr/local/src/php-5.6.24
./configure –prefix=/usr/local/php5 –with-config-file-path=/usr/local/php5/etc –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-mysql-sock=/tmp/mysql.sock –with-gd –with-iconv –with-freetype –with-jpeg –with-zlib –with-libxml –enable-xml –enable-discard-path –enable-magic-quotes –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curlwappers –enable-mbregex –enable-fastcgi –enable-force-cgi-redirect –enable-mbstring –enable-ftp –enable-gd-native-ttf –with-openssl –enable-pcntl –enable-sockets –with-xmlrpc –enable-zip –enable-soap –enable-pear –with-pear –with-gettext –with-mine-magic –enable-suhosin –enable-session –with-mcrypt –enable-fpm –with-jpeg –with-vpx-dir=/usr/local/libvpx –with-jpeg-dir=/usr/local/jpeg –with-png –with-png-dir=/usr/local/libpng
1 | [root@local php-5.6.24]# ./configure --prefix=/usr/local/php5 \ |
1 | Thank you for using PHP. |
最后有一个警告,不用管它,生成了Makefile文件就行。
make -j make -j test #这一步可以省略
===================================================================== WARNED TEST SUMMARY --------------------------------------------------------------------- zend multibyte (2) [ext/mbstring/tests/zend_multibyte-02.phpt] (warn: XFAIL section but test passes) zend multibyte (6) [ext/mbstring/tests/zend_multibyte-06.phpt] (warn: XFAIL section but test passes) zend multibyte (8) [ext/mbstring/tests/zend_multibyte-08.phpt] (warn: XFAIL section but test passes) zend multibyte (10) [ext/mbstring/tests/zend_multibyte-10.phpt] (warn: XFAIL section but test passes) zend multibyte (11) [ext/mbstring/tests/zend_multibyte-11.phpt] (warn: XFAIL section but test passes) Phar: bug #69958: Segfault in Phar::convertToData on invalid file [ext/phar/tests/bug69958.phpt] (warn: XFAIL section but test passes) Bug #69111 Crash in SessionHandler::read() [ext/session/tests/bug69111.phpt] (warn: XFAIL section but test passes) Bug #70172 - Use After Free Vulnerability in unserialize() [ext/standard/tests/serialize/bug70172.phpt] (warn: XFAIL section but test passes) ===================================================================== You may have found a problem in PHP. This report can be automatically sent to the PHP QA team at http://qa.php.net/reports and http://news.php.net/php.qa.reports This gives us a better understanding of PHP's behavior. If you don't want to send the report immediately you can choose option "s" to save it. You can then email it to qa-reports@lists.php.net later. Do you want to send this report now? [Yns]: Y
这里我给PHP提交了一个bug,这个不影响,继续安装
make -j install
1 | [root@local php-5.6.24]# du -sh . #这个目录417M |
配置PHP
1 | cp php.ini-production /usr/local/php5/etc/php.ini #复制php配置文件到安装目录 |
找到:;date.timezone =
修改为:date.timezone = PRC #设置时区
1 | cp etc/php-fpm.conf.default etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件 |
user = www #设置php-fpm运行账号为www
group = www #设置php-fpm运行组为www
pid = run/php-fpm.pid #取消前面的分号