这是一篇凑数博文,只是为了让博客显的没有那么空
LNMP架构概述
LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python。
准备工作
CentOS 7 服务器 这里用的腾讯云轻量应用服务器
Nginx 1.24.0 下载路径 https://nginx.org/download/nginx-1.24.0.tar.gz
Mysql 5.6.51 软件源 http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
PHP 7.2.34 软件源 https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
LNMP架构部署
Nginx安装
下载Nginx源码到home目录
wget https://nginx.org/download/nginx-1.24.0.tar.gz
解压
tar -xzf nginx-1.24.0.tar.gz
进入解压的文件夹中,用命令配置Nginx编译安装
cd nginx-1.24.0
./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--modules-path=/usr/local/nginx/modules \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log \
--pid-path=/usr/local/nginx/logs/nginx.pid \
--lock-path=/usr/local/nginx/logs/nginx.lock
编译完成之后,运行命令安装
make && make install
进入Nginx,二进制可执行文件目录,启动Nginx
cd /usr/local/nginx/sbin/
启动Nginx
./nginx
安装完之后,浏览器访问服务器公网IP,如果可以看到如下页面说明安装成功
安装Mysql
依次输入下面三条命令安装Mysql代替CentOS自带的mariadb
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
yum -y install mysql-community-release-el7-5.noarch.rpm
yum -y install mysql-community-server
启动与查看
启动mysql
systemctl start mysqld
查看运行状态
systemctl status mysqld
登录mysql
mysql 5.6.51版本中默认状态下root用户密码为空(直接回车就可以登录)
登录mysql
mysql -uroot -p
修改root用户密码
set password for root@localhost = password('789456123');
安装PHP
添加php源
yum localinstall https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装php和相关插件
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
启动与查看
启动php-fpm
systemctl start php-fpm
查看版本
php -v
Nginx代理PHP
Nginx默认配置文件如下
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
删除部分注释文件,并开启php代理服务,结果如下
user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ ^(.+\.php)(.*)$ {
root html;
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;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
}
进入Nginx运行文件,重启Nginx
检查配置文件
./nginx -t
停止Nginx
./nginx -s stop
启动Nginx
./nginx