centos7中配置lnmp环境

firewall和selinux先关闭

1
2
3
4
systemctl stop firewall
systemctl disable firewall
vim /etc/selinux/config
#将SELINUX=enforcing改为SELINUX=disabled

nginx安装:

1
2
3
4
yum install epel-release
yum install nginx -y
systemctl start nginx
systemctl enable nginx

现在可以测试一下能不能显示网页
http://server_domain_name_or_IP/

然后就是MySQL (MariaDB)

1
2
3
yum install mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb

然后是初始化MariaDB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
mysql_secure_installation
:<<BLOCK
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
       SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
 
Enter current password for root (enter for none):<---输入现在的root密码,因为我们还没设置,直接回车
OK, successfully used password, moving on...
 
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
 
Set root password? [Y/n] Y   <---是否设定root密码,当然设置了,输入Y回车
New password: <---输入root密码,并回车,输入的过程中不会有任何显示
Re-enter new password: <---再次输入root密码,并回车,输入的过程中不会有任何显示
Password updated successfully!
Reloading privilege tables..
 ... Success!
 
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
 
Remove anonymous users? [Y/n] Y <---是否删除匿名用户,删除,输入Y回车
 ... Success!
 
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
 
Disallow root login remotely? [Y/n] Y <---是否删禁止root用户远程登录,当然禁止,输入Y回车
  ... Success!
 
By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
 
Remove test database and access to it? [Y/n] <---是否删除测试数据库test,删除,输入Y回车
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
  ... Success!
 
 Reloading the privilege tables will ensure that all changes made so far
 will take effect immediately.
 
Reload privilege tables now? [Y/n] Y <---刷新权限,输入Y回车
 ... Success!
 
 Cleaning up...
 
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
 
 Thanks for using MySQL!
BLOCK

然后是安装php

1
2
3
yum install php php-mysql php-fpm
yum search php #查找需要的组件也一起安装了
systemctl enable php-fpm

配置php

1
2
3
4
5
6
7
8
9
vim /etc/php-fpm.d/www.conf
改成
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nobody
listen.group = nobody
user = nginx
group = nginx
#
systemctl start php-fpm

然后是配置nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
vim /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  server_domain_name_or_IP;
 
    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html;
    index index.php index.html index.htm;
 
    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
 
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

添加评论