首页 > 代码库 > LEMP

LEMP

在 CentOS 7 系统上:
$ sudo rpm --import http://nginx.org/keys/nginx_signing.key
$ sudo rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
$ sudo yum install nginx
$ sudo systemctl start nginx
$ sudo systemctl enable nginx
$ sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
$ sudo firewall-cmd --reload
#--sql
$ sudo yum install mariadb-server
$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb
$ sudo mysql_secure_installation
#--php
$ sudo yum php php-fpm php-mysql
$ sudo systemctl start php-fpm
$ sudo systemctl enable php-fpm


在 CentOS 6 系统上:
$ sudo rpm --import http://nginx.org/keys/nginx_signing.key
$ sudo rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
$ sudo yum install nginx
$ sudo service nginx start
$ sudo chkconfig nginx on
$ sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
$ sudo service iptables save
#--mysql
$ sudo yum install mysql-server
$ sudo service mysqld start
$ sudo chkconfig mysqld on
#--php#默认会把apache当成依赖条件自动安装
$ sudo yum --enablerepo=remi install php php-fpm php-mysql
$ sudo chkconfig php-fpm on
$ sudo service php-fpm start

在 CentOS 6 系统中,安装 REMI仓库中最新的 php-mysql 模块时,MySQL 的服务端包和客户端包会被当做一部分依赖包而自动的更新。

在 CentOS 6 和 CentOS 7 中,在安装 PHP 包的同时会把 Apache web 服务器(即 httpd)当做它的依赖包一起安装。这会跟 nginx web 服务器起冲突。这个问题会在下一节来讨论。

取决于您的使用情况,可以使用 yum 命令来定制您的 PHP 引擎,也许会想安装下面的任意一个扩展 PHP 模块包。
php-cli: PHP 的命令行界面。从命令行里测试 PHP 时非常有用。
php-gd: PHP 的图像处理支持。
php-bcmath: PHP 的数学支持。
php-mcrypt: PHP 的加密算法支持 (例如 DES、Blowfish、CBC、 CFB、ECB ciphers 等)。
php-xml: PHP 的 XML 解析和处理支持。
php-dba: PHP 的数据抽象层支持。
php-pecl-apc: PHP 加速器/缓存支持。
----------------------------------------------

$ sudo vi /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  www.server_domain.com;
    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;
 
    location / {
    }
 
    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    }
 
    # nginx passes PHP scripts to FastCGI server via a TCP/9000 socket
    # this setting much be consistent with /etc/php-fpm.d/www.conf
    # try_files prevents nginx from passing bad scripts to FastCGI server
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

LEMP