CentOS 官方 yum 仓库:渣,很渣,非常渣

直到现在,官方源中仍然没有 Nginx,PHP 和 MySQL 的版本也已经老掉牙了

换源,刻不容缓!

epel & remi & ius

  1. 7.x
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
  1. 6.x
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-remi

vi /etc/yum.repos.d/remi.repo [remi]段中enabled=0改1

vi /etc/yum.repos.d/remi-php70.repo [remi-php70]段enabled=0改1

yum list php

看到版本号是 7.x

nginx 官方源

rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

php & mysql

yum install nginx mysql-server mysql-client php php-fpm php-cli

PHP 组件

yum install php-pdo php-mysql php-gd php-bcmath php-mcrypt php-xml php-dba php-pecl-apc php-mbstring php-intl

配置 LNMP

chkconfig nginx on
chkconfig mysqld on
chkconfig php-fpm on

装 Nginx 的时候 yum 会自动安装 Apache

chkconfig httpd off

然后来配置 Nginx 删掉 Nginx 默认的配置文件与目录: rm -rf /etc/nginx/conf.d/default.conf /usr/share/nginx 新建一个配置文件: vi /etc/nginx/conf.d/www.conf

server { listen 80; server_name localhost; //这里改成你的域名 root /home/www; //这里改成准备放网页文件的目录 index index.php index.html index.htm;

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;
}

}

Nginx 上传大小,并禁止 Nginx 在 HTTP Header 中发送服务器信息

vi /etc/nginx/nginx.conf

include /etc/nginx/conf.d/*.conf;这一行上面插入两行

client_max_body_size 200m;
server_tokens off;

配置 MySQL

cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
service mysqld start
mysql_secure_installation

PHP配置

vi /etc/php.ini

上传大小,搜索upload_max_filesize=2M,改200M max_file_uploads=2,改200

使 HTTP Header 中不显示 PHP 信息,搜索expose_php = On,改为expose_php = Off

最后在文件末尾加上两行:

cgi.fix_pathinfo=1 date.timezone = “PRC”

LNMP service

service nginx start service mysqld start service php-fpm start

建立 web 目录:

mkdir /home/www

vi /home/www/index.php <?php phpinfo(); ?>