LAMP & LNMP及简单环境搭建
LAMP & LNMP
LAMP = Linux + Apache + MySQL + PHP
LNMP = Linux + Nginx + MySQL + PHP
流行,免费,开源,轻量
Linux VS Windows: 完全免费,稳定高效
MySQL: 关系型数据库
Apache:Web服务器软件
监听端口,接收请求,解析HTTP协议,转发给PHP
Nginx 服务器软件
Apache & Nginx:前景更好,配置轻松,性能更优
Apache: select轮询机制
Nginx: epoll事件监听机制
编译安装
./configure # 编译前准备
make # 编译
make install # 安装
- 1
- 2
- 3
安装依赖软件
yum install -y vim wget gcc gcc++ libxml2-devel
- 1
编译安装php
1、下载
https://www.php.net/downloads.php
wget https://www.php.net/distributions/php-7.3.11.tar.gz
tar -zxvf php-7.3.11.tar.gz
cd php-7.3.11
- 1
- 2
- 3
2、编译安装
启用支持FPM FastCGI
https://www.php.net/manual/zh/install.fpm.install.php
./configure --prefix=/usr/local/php7 --enable-fpm
make && make install
- 1
- 2
CGI 公共网关接口,一个协议 fork子进程,处理完释放
FastCGI 语言无关,解释器子进程常驻在内存
FPM PHP扩展
$ php -r "phpinfo();"
- 1
MySQL
1、下载
https://dev.mysql.com/downloads/mysql/
source code
-> Generic Linux (Architecture Independent), Compressed TAR Archive
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18.tar.gz
- 1
2、安装依赖
yum install -y cmake gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel
- 1
3、安装
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql/data \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled
make && make install
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
4、启动使用
mysqld
mysql
- 1
- 2
- 3
Apache
1、下载
http://httpd.apache.org/
依赖:apr apr-util pcre
wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
tar -zxvf httpd-2.4.41.tar.gz
cd httpd-2.4.41
- 1
- 2
- 3
- 4
2、编译安装(配置必要的参数略)
./configure
make && make install
- 1
- 2
3、启动
apachetcl -k start
- 1
开放80端口sudo
firewall-cmd --zone=public --add-port80/tcp --permanent
systemctl restart firewalld.service
- 1
- 2
Nginx
1、下载
http://nginx.org/en/download.html
# 下载
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxvf nginx-1.16.1.tar.gz
# 安装 pcre url重写功能
./configure --prefix=/usr/local/nginx --with-pcre=/pcre
make && make install
# 启动
./nginx
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
工作方式
请求 <-> Nginx <-> PHP-FPM
- 1
配置
location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+?\.php)(/.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
配置php-fpm
php-fpm.conf
pm = dynamic 设置动态解析
pm.max_children = 5 最大可以启动多少进程
pm.start_servers = 2 默认启动几个进程
- 1
- 2
- 3
配置Nginx
nginx.conf
worker_processes 1; (启动多少子进程)
- 1
重启
nginx -s reload
- 1
查看进程
ps aux|grep nginx
- 1
文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/102888454
- 点赞
- 收藏
- 关注作者
评论(0)