-
创建者:
虚拟的现实,上次更新时间:10月 07, 2023 需要 3 分钟阅读时间
LNMP简介
LEMP简介
以往的 linux 服务器大多采用LAMP(linux、apache、mysql、php)的方式,随着 nginx 的应用场景的增加已逐步有取代 apache 的趋势。本文的系统采用CentOS7。
参考资源
Linux 安装及相关配置
操作系统的安装略。
添加软件源
禁用 selinux
vim /etc/selinux/config
调整主机名称和时间
hostnamectl set-hostname xxxx timedatectl set-time "08/30/17 10:24"
nginx 安装及相关配置
软件安装
wget http://nginx.org/download/nginx-1.13.4.tar.gz
./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf {color}
--user=nginx --group=nginx --sbin-path=/usr/sbin --pid-path=/var/run/nginx.pid {color}
--error-log-path=/var/log/nginx/nginx-error.log --with-http_ssl_module {color}
--with-http_realip_module --with-http_gzip_static_module --with-http_sub_module {color}
--add-module=../ngx-fancyindex-0.4.2/
Make
Make install
添加启动脚本
vim /usr/lib/systemd/system/nginx.service
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
systemctl enable nginx.service
配置站点
vim /etc/nginx/nginx.conf
user nginx;
worker_processes 16;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
vim /etc/nginx/conf.d/ftp.conf
server {
listen 80 default_server;
server_name _;
large_client_header_buffers 4 32k;
client_max_body_size 50M;
root /var/www/html/ftp;
charset utf-8;
access_log /var/log/nginx/ftp.access.log;
error_log /var/log/nginx/ftp.error.log;
location / {
root /var/www/html/ftp;
index index.php index.html index.htm;
fancyindex on;
fancyindex_localtime on;
fancyindex_exact_size off;
fancyindex_footer "/Nginx-Fancyindex-Theme/footer.html";
fancyindex_header "/Nginx-Fancyindex-Theme/header.html";
fancyindex_ignore "Nginx-Fancyindex-Theme";
fancyindex_ignore "phpMyAdmin";
fancyindex_name_length 55;
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
location = /404.html { root /usr/local/nginx/html;}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/nginx/html;
}
location ~ /(libraries|setup/frames|setup/libs) {
deny all;
return 404;
}
location /phpMyAdmin {
alias /var/www/html/ftp/phpMyAdmin;
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/pma_pass;
index index.php index.html index.htm;
}
location /pure {
alias /var/www/html/ftp/pure;
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/pma_pass;
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.\.php)(/.)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/ftp$fastcgi_script_name;
include fastcgi_params;
}
}
Systemctl restart nginx Firewall-cmd –zone=public –permanent –add-service=http Firewall-cmd –reload
查看本地及外网地址
ip addr show eno1 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
curl http://icanhazip.com
MySQL安装及配置
在 CentOS7 下,数据库可以选择 mariadb ,也可以直接安装 MySQL 。前者是数据库的一个分支,就像 CentOS 之于 RedHat 。
安装MySQL
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update sudo yum install mysql-server systemctl start mysqld mysql_secure_installation
![]()
yum -y install phpmyadmin
配置 phpMyAdmin
cd /var/www/html/ftp ln -s /usr/share/phpMyAdmin ./ openssl passwd vim /etc/nginx/pma_pass
为访问的页面增加验证功能,类似于 apache 的 .htpass 文件功能。 nginx 的设置参考第三节。
PHP安装及配置
nginx 下的 php 使用 php-fpm 组件。可以根据业务系统需求安装不同的版本( PHP5 或 PHP7 )
安装 PHP5
yum install php php-mysql php-fpm
修改 /etc/php.ini 文件中的 cgi 选项的配置。
cgi.fix_pathinfo=0
修改 /etc/php-fpm.d/www.conf 中的相关配置。
配置好 nginx 后,重启相关服务测试(可建立 php 的测试文件)。
systemctl start php-fpm systemctl enable php-fpm vi /usr/share/nginx/html/info.php
<?php phpinfo(); ?>
安装 PHP7
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7.rpm yum install yum-utils –y yum-config-manager --enable remi-php71 yum --enablerepo=remi,remi-php71 install php-fpm php-common yum --enablerepo=remi,remi-php71 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml
错误提示:"FastCGI sent in stderr: "PHP message: PHP Fatal error: Call to undefined function __() in"
- 无标签
添加评论