LAMP
  goer ... 2022-01-15    大约 1 分钟 
  [toc]
# 搭建环境
Linux Apache/Nginx Mysql PHP
# 1. Nginx web服务器
提供web服务 apache也类似 (httpd)
yum install nginx -y
1
重要目录
配置文件: (包管理工具安装的)
/etc/nginx/conf.d/default.confweb目录:
/usr/share/nginx/html
server {
    listen       80 default_server;      //监听端口
    # listen       [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/html;   //web目录
    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;
    location / {
    }
    error_page 404 /404.html;
        location = /40x.html {
    }
    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
启动和开机自起
nginx  //启动
chkconfig nginx on  //开机自启
1
2
2
# 2. mysql 数据库服务器
存放数据的表
yum install mysql-server -y
1
启动mysql服务 (mysqld)
service mysqld restart   systemctl mysqld status//查看服务进程
1
设置root密码
/usr/bin/mysqladmin
/usr/bin/mysqladmin -u root password "yourpassword"  //设置密码
1
设置开机自启动
chkconfig mysqld on  //启动
1
# 3. PHP
php预格式化处理器,开源的后端语言
yum install php php-fpm php-mysql -y   //安装
1
启动php-frm 进程
service php-fpm start   
1
查看HP-FPM 进程监听哪个端口
netstat -nlpt | grep php-fpm
1
开机自动启动:
chkconfig php-fpm on1
# 配置nginx 加 php
在
/etc/nginx/conf.d目录中新建一个名为 php.conf 的文件,并配置 Nginx 端口
server {
    listen 8000;  //端口
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ .php$ {
        root           /usr/share/php;  //php路径
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
重启 nginx 服务
service nginx restart 
1
检查是否成功 在
/usr/share/php目录下新建一个 info.php 文件来检查 php 是否安装成功了
// info.php
<?php phpinfo(); ?>
1
2
2
http://地址/info.php
 
 