CentOS7 yum快速安装php7.1+nginx+mysql+redis

一、安装Nginx

yum install nginx
## 开启Nginx
service nginx start

  • CentOS安装Nginx出错提示No package nginx available

解决方法:

先安装 epel

yum install epel-release

然后再安装Nginx

  • [bash: service: command not found 错误的解决方法]

service命令是要用ROOT用户来执行的,
su -root
并同时使用/sbin/service来操作就可以

如果还不行

/sbin目录下没有service这个命令
yum list | grep initscripts看看有没有装initscripts
没有的话yum install initscripts安装上去

安装成功后,可以打开浏览器访问主机IP,看看是否成功安装和启动服务。

二、安装MySql

1、安装community

yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

2、安装 mysql-server

yum install mysql-community-server

3、 开启mysql

service mysqld start

4、 查看mysql的root账号的密码,如果你改了密码,再查看这个不会显示你的修改过的密码

grep 'temporary password' /var/log/mysqld.log

5、登录mysql

mysql -uroot -p

6、修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

7、修改root用户可远程登录

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

8、刷新

flush privileges;

三、安装php

1、安装包

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

2、镜像源

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

3、查看

yum search php71w

4、安装php以及扩展

yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath

5、开启服务

service php-fpm start

6、修改/etc/nginx/nginx.conf 使其支持php
server {
    charset utf-8;
    client_max_body_size 128M;
    listen 80; ## listen for ipv4
    server_name localhost;
    root        /var/www/;
    index       index.php;

    location / {
        if (!-e $request_filename){
          rewrite ^/(.*)$ /index.php/$1 last;
        }
        try_files $uri $uri/ /index.php?$args;
    }   

    location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_pass   127.0.0.1:9000;
        try_files $uri =404;
    }
    location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include /etc/fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/?.*)$;
        fastcgi_param SCRIPT_FILENAME
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    }   

    error_page 404 /404.html;
    location ~ /\.(ht|svn|git) {
        deny all;
    }
}
7、重启nginx

service nginx restart

四、安装redis

1、先装git

yum install git

2、git下扩展

cd /usr/local/src
git clone https://github.com/phpredis/phpredis.git

3、安装扩展

cd phpredis
phpize

4、修改php配置

vi /etc/php.ini 添加extension=redis.so

5、重启php

service php-fpm restart

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容