LAMP安装
在服务器优化之前,对于LNMP的合作运行应该有一定的了解。这里介绍Apache、PHP的安装及配置。在Apache+PHP的单机并发量最大之后再加入MysqL。本测试均在虚拟机环境下执行。
- 虚拟机及环境信息:
- Ubuntu 16.04 4G 双核 50G
- Apache 2.4.25
- PHP 7.1.2
- Vmware 12.0
开发环境准备 :
编译工具
sudo apt install gcc g++ make
备注:以上工具也可直接安装 build-essential 包
编辑工具
sudo apt install vim
Apache 安装
1、下载Apache源码 (到Apache官网查看最新稳定版本)
wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.25.tar.bz2
- 2、验证源码包的完整性(其实并不需要,但是学习一下也是好的)
- a 下载 asc 文件。(要与上面下载的包版本一致)
wget https://www.apache.org/dist/httpd/httpd-2.4.25.tar.bz2.asc
两个文件在同一目录下
gpg --verify httpd-2.4.18.tar.gz.asc httpd-2.4.18.tar.gz
-
提示: gpg: Signature made Tue Dec 8 21:32:07 2015 CET using RSA key ID 791485A8 gpg: Can’t check signature: public key not found。
-
b 下载public key
gpg --keyserver pgpkeys.mit.edu --recv-key 791485A8 (注意与上面提示的 key ID 一致)
提示: 提示:(下载成功)
gpg: requesting key 791485A8 from HKP keyserver pgpkeys.mit.edu
gpg: trustdb created
gpg: key 791485A8: public key “Jim Jagielski jim@apache.org”
imported
gpg: Total number processed: 1
gpg: imported: 1**
: c 再次验证
gpg --verify httpd-2.4.18.tar.gz.asc httpd-2.4.18.tar.gz
提示:
gpg: Signature made Tue Dec 8 21:32:07 2015 CET using RSA key ID 791485A8
gpg: Good signature from “Jim Jagielski jim@apache.org”
gpg: aka “Jim Jagielski jim@jimjag.com”
gpg: aka “Jim Jagielski jim@jaguNET.com”
gpg: aka “Jim Jagielski jimjag@gmail.com”
gpg: checking the trustdb
gpg: no ultimately trusted keys found
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the
owner.
Fingerprint: A93D 62EC C3C8 EA12 DB22 0EC9 34EA 76E6 7914 85A8
到此验证完依然不能够完全信任所下载的源码包,因为下载的public key有可能是假的。
验证最关键的一步是验证public key的指纹
gpg --fingerprint 791485A8
验证完成。
3、尝试编译
./configure
4、下载Apache运行时需要的库 apr apr-util pcre
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.gz
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
- >
- 将 apr 及 apr-util 分别解压到 /http-2.4.25/srclib/下
-
- 安装 pcre
- 进入解压后的pcre目录;
./configure --prefix=/usr/local/pcre
: 定义 C
4、编译安装Apache
进入httpd目录
./configure --prefix=/usr/local/apache2(默认) --with-included-apr --with-mpm=worker --enable-mods-shared=all
make
make install
5、启动/停止 Apache
/usr/local/apache2/bin/apachetl -k start/stop/restart
PHP安装
1、下载PHP源码
wget http://cn2.PHP.net/distributions/PHP-7.1.2.tar.gz
tar -zvxf PHP-7.1.2.tar.gz
cd PHP-7.1.2
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-MysqL --prefix=/usr/local/PHP7 --enable-fpm
make
make install
2、设置PHP.ini
cp PHP.ini-development /usr/local/lib/PHP.ini
- 3、配置Apache处理PHP
-
打开httpd.conf
LoadModule PHP7_module modules/libPHP7.so (PHP7安装成功后会自动加上 以防万一 检查一下)
<FilesMatch \.PHP$>
SetHandler application/x-httpd-PHP
</FilesMatch>
<FilesMatch "\.PHPs$">
SetHandler application/x-httpd-PHP-source
</FilesMatch>
##找到 LoadModule rewrite_module modules/mod_rewrite.so 去掉 前面的 # 号
RewriteEngine On
RewriteRule (.*\.PHP)s$ $1 [H=application/x-httpd-PHP-source]
#配置虚拟主机
<VirtualHost ip:8080>
ServerAdmin webmaster@host.example.com
DocumentRoot "/home/yking/test.tt"
ServerName test.tt
ErrorLog "logs/host.example.com-error_log"
TransferLog "logs/host.example.com-access_log"
</VirtualHost>
<Directory "/home/yking/test.tt">
AllowOverride None
Require all granted
</Directory>
重启Apache。 配置完成。