CentOS 7安装 Nginx, MySQL, PHP (LEMP)

1、安装启动Nginx

sudo yum install epel-release
sudo yum install nginx
sudo systemctl start nginx
sudo systemctl enable nginx

2、安装 MySQL (MariaDB)

sudo yum install mariadb-server mariadb
sudo systemctl start mariadb
sudo mysql_secure_installation

设置MySQL密码:

mysql_secure_installation prompts:
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

New password: password
Re-enter new password: password
Password updated successfully!
Reloading privilege tables..
 ... Success!

开始启动MariaDB

sudo systemctl enable mariadb

3、安装php

sudo yum install php php-mysql php-fpm
sudo vi /etc/php.ini
/etc/php.ini excerpt
cgi.fix_pathinfo=0
sudo vi /etc/php-fpm.d/www.conf
/etc/php-php.d/www.conf — 1 of 3
listen = /var/run/php-fpm/php-fpm.sock
/etc/php-php.d/www.conf — 2 of 3
listen.owner = nobody
listen.group = nobody
/etc/php-php.d/www.conf — 3 of 3
user = nginx
group = nginx
sudo systemctl start php-fpm

设置开机启动

sudo systemctl enable php-fpm

4、配置Nginx处理PHP

sudo vi /etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/default.conf — original
server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
/etc/nginx/conf.d/default.conf — updated
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;
    }
}

重新启动Nginx

sudo systemctl restart nginx

5、测试

sudo vi /usr/share/nginx/html/info.php
<?php phpinfo(); ?>
http://your_server_IP_address/info.php

发布日期:

所属分类: Apache/Ngnix 标签:     


没有相关文章!