# 安装
$ yum install nginx -y
# 开启服务
$ systemctl start nginx
# 开机自启
$ systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
# 查看状态
$ systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-03-15 07:17:26 EDT; 11s ago
Docs: http://nginx.org/en/docs/
Main PID: 2976 (nginx)
CGroup: /system.slice/nginx.service
├─2976 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─2977 nginx: worker process
Mar 15 07:17:26 lnmp systemd[1]: Starting nginx - high performance web server...
Mar 15 07:17:26 lnmp systemd[1]: Started nginx - high performance web server.
$ curl 192.168.119.136
<!DOCTYPE html><html><head><title>Welcome to nginx!</title><style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;}</style></head><body><h1>Welcome to nginx!</h1><p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p></body></html>
$ cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name www.lnmp.com;#charset koi8-r;
access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;}
location /status {
stub_status on;}#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 /usr/share/nginx/html;}
location ~ .*/.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
expires 30d;}# 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;#}}
7. 重启服务
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$ systemctl restart nginx
三、MariaDB数据库
1. 安装MariaDB
$ yum install mariadb-server -y
2. mariadb服务
# 启动服务
$ systemctl start mariadb
# 开机自启
$ systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
# 查看状态
$ systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-03-15 07:34:25 EDT; 9s ago
Main PID: 4047 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─4047 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─4212 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-err...
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: MySQL manual formore instructions.
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: Please report any problems at http://mariadb.org/jira
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: The latest information about MariaDB is available at http://mariadb.org/.
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: You can find additional information about the MySQL part at:
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: http://dev.mysql.com
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: Consider joining MariaDB's strong and vibrant community:
Mar 15 07:34:22 lnmp mariadb-prepare-db-dir[3964]: https://mariadb.org/get-involved/
Mar 15 07:34:23 lnmp mysqld_safe[4047]: 210315 07:34:23 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Mar 15 07:34:23 lnmp mysqld_safe[4047]: 210315 07:34:23 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Mar 15 07:34:25 lnmp systemd[1]: Started MariaDB database server.
3. 修改密码
$ mysqladmin -uroot password Com.123456
$ mysql -uroot -pCom.123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
4. 创建数据库用户
MariaDB [(none)]> create user "dbadmin"@"localhost" identified by "Com.123456";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on *.* to "dbadmin"@"localhost";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> create user "dbadmin"@"%" identified by "Com.123456";
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> grant all on *.* to "dbadmin"@"%";
Query OK, 0 rows affected (0.00 sec)
$ systemctl start php-fpm.service
$ systemctl enable php-fpm.service
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
$ systemctl status php-fpm.service
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-03-15 08:41:18 EDT; 13s ago
Main PID: 2396 (php-fpm)
Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
CGroup: /system.slice/php-fpm.service
├─2396 php-fpm: master process (/etc/php-fpm.conf)
├─2398 php-fpm: pool www
├─2399 php-fpm: pool www
├─2400 php-fpm: pool www
├─2401 php-fpm: pool www
└─2402 php-fpm: pool www
Mar 15 08:41:18 lnmp systemd[1]: Starting The PHP FastCGI Process Manager...
Mar 15 08:41:18 lnmp systemd[1]: Started The PHP FastCGI Process Manager.
5. php-fpm配置文件
$ vim /etc/php-fpm.d/www.conf
[www]
user = nginx
group = nginx
6. nginx配置文件
$ vim /etc/nginx/conf.d/default.conf
location / {
root /opt/nginx/html;
index index.php index.html index.htm;}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#
location ~ \.php$ {
root /opt/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_cache TEST;
fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;}# 重启服务
$ systemctl restart nginx
五、测试
1. 测试LNMP环境
$ vim /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
# 下载源码包
https://files.phpmyadmin.net/phpMyAdmin/5.1.0/phpMyAdmin-5.1.0-all-languages.tar.gz
# 解压
$ tar -zxvf phpMyAdmin-5.1.0-all-languages.tar.gz -C /usr/share/nginx/html/
# 使用前配置
$ cd /usr/share/nginx/html/
$ mv phpMyAdmin-5.1.0-all-languages/ phpmyadmin
$ cd phpmyadmin/
$ cp config.sample.inc.php config.inc.php
$ vim config.inc.php
cfg['blowfish_secret']='dbadmin'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */