centos 6.5 Yum安装LNMP

安装nginx

第一步:第一步,获取 yum 源

nginx官方yum源

复制红框中的内容

第二步,在 CentOS 中新建 yum 源

[root@i-op5nhxmi ~]# cd /etc/yum.repos.d/
[root@i-op5nhxmi yum.repos.d]# vim nginx.repo
//将复制的内容写进去,保存退出

测试 yum 源安装是否成功

yum list | grep nginx

会出现下面的列表表示成功

第三步,安装 nginx

yum -y install nginx

测试nginx 是否安装成功

[root@i-op5nhxmi yum.repos.d]# nginx -v
nginx version: nginx/1.16.0

启动 nginx

nginx -t //测试nginx文件是否正确
nginx -s start //启动nginx
nginx -s stop //停止nginx 
nginx -s restart //重启nginx

安装php7

先安装 epel-release

php7 版本的 yum 源在 webtatic 上,但还有一部分需要依赖 epel-release 。

[root@i-op5nhxmi yum.repos.d]# yum -y install epel-release

安装webtatic yum 源

不同系统的rpm源不同,请注意自己的系统版本:具体参考我上一篇文章的rpm源。我的是centos6.5,所以我使用:

[root@i-op5nhxmi yum.repos.d]# rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
Retrieving http://mirror.webtatic.com/yum/el6/latest.rpm
warning: /var/tmp/rpm-tmp.LP7qRD: Header V4 DSA/SHA1 Signature, key ID cf4c4ff9: NOKEY
Preparing...                ########################################### [100%]
   1:webtatic-release       ########################################### [100%]

注意:必须成功后才能下一步。

查看php可安装的包

[root@i-op5nhxmi ~]# yum list | grep php7
mod_php71w.x86_64                          7.1.30-1.w6                  webtatic
php70w.x86_64                              7.0.33-1.w6                  webtatic
php70w-bcmath.x86_64                       7.0.33-1.w6                  webtatic
php70w-cli.x86_64                          7.0.33-1.w6                  webtatic
php70w-common.x86_64                       7.0.33-1.w6                  webtatic
php70w-dba.x86_64                          7.0.33-1.w6                  webtatic
php70w-devel.x86_64                        7.0.33-1.w6                  webtatic
php70w-embedded.x86_64                     7.0.33-1.w6                  webtatic
php70w-enchant.x86_64                      7.0.33-1.w6                  webtatic
php70w-fpm.x86_64                          7.0.33-1.w6                  webtatic
php70w-gd.x86_64                           7.0.33-1.w6                  webtatic
php70w-imap.x86_64                         7.0.33-1.w6                  webtatic
php70w-interbase.x86_64                    7.0.33-1.w6                  webtatic
php70w-intl.x86_64                         7.0.33-1.w6                  webtatic
php70w-ldap.x86_64                         7.0.33-1.w6                  webtatic
php70w-mbstring.x86_64                     7.0.33-1.w6                  webtatic
php70w-mcrypt.x86_64                       7.0.33-1.w6                  webtatic
php70w-mysql.x86_64                        7.0.33-1.w6                  webtatic
php70w-mysqlnd.x86_64                      7.0.33-1.w6                  webtatic
php70w-odbc.x86_64                         7.0.33-1.w6                  webtatic
php70w-opcache.x86_64                      7.0.33-1.w6                  webtatic
php70w-pdo.x86_64                          7.0.33-1.w6                  webtatic
php70w-pdo_dblib.x86_64                    7.0.33-1.w6                  webtatic
php70w-pear.noarch                         1:1.10.4-1.w6                webtatic
php70w-pecl-apcu.x86_64                    5.1.9-1.w6                   webtatic
php70w-pecl-apcu-devel.x86_64              5.1.9-1.w6                   webtatic
php70w-pecl-geoip.x86_64                   1.1.1-1.w6                   webtatic
php70w-pecl-igbinary.x86_64                2.0.5-1.w6                   webtatic
php70w-pecl-igbinary-devel.x86_64          2.0.5-1.w6                   webtatic
php70w-pecl-imagick.x86_64                 3.4.3-1.w6                   webtatic
php70w-pecl-imagick-devel.x86_64           3.4.3-1.w6                   webtatic
php70w-pecl-memcached.x86_64               3.0.4-1.w6                   webtatic
php70w-pecl-mongodb.x86_64                 1.5.3-1.w6                   webtatic
php70w-pecl-redis.x86_64                   3.1.6-1.w6                   webtatic
php70w-pecl-xdebug.x86_64                  2.6.1-1.w6                   webtatic
php70w-pgsql.x86_64                        7.0.33-1.w6                  webtatic
php70w-phpdbg.x86_64                       7.0.33-1.w6                  webtatic
php70w-process.x86_64                      7.0.33-1.w6                  webtatic
php70w-pspell.x86_64                       7.0.33-1.w6                  webtatic
php70w-recode.x86_64                       7.0.33-1.w6                  webtatic
php70w-snmp.x86_64                         7.0.33-1.w6                  webtatic
php70w-soap.x86_64                         7.0.33-1.w6                  webtatic
php70w-tidy.x86_64                         7.0.33-1.w6                  webtatic
php70w-xml.x86_64                          7.0.33-1.w6                  webtatic
php70w-xmlrpc.x86_64                       7.0.33-1.w6                  webtatic
php71w-bcmath.x86_64                       7.1.30-1.w6                  webtatic
php71w-cli.x86_64                          7.1.30-1.w6                  webtatic
php71w-common.x86_64                       7.1.30-1.w6                  webtatic
php71w-dba.x86_64                          7.1.30-1.w6                  webtatic
php71w-devel.x86_64                        7.1.30-1.w6                  webtatic
php71w-embedded.x86_64                     7.1.30-1.w6                  webtatic
php71w-enchant.x86_64                      7.1.30-1.w6                  webtatic
php71w-fpm.x86_64                          7.1.30-1.w6                  webtatic
php71w-gd.x86_64                           7.1.30-1.w6                  webtatic
php71w-imap.x86_64                         7.1.30-1.w6                  webtatic
php71w-interbase.x86_64                    7.1.30-1.w6                  webtatic
php71w-intl.x86_64                         7.1.30-1.w6                  webtatic
php71w-ldap.x86_64                         7.1.30-1.w6                  webtatic
php71w-mbstring.x86_64                     7.1.30-1.w6                  webtatic
php71w-mcrypt.x86_64                       7.1.30-1.w6                  webtatic
php71w-mysql.x86_64                        7.1.30-1.w6                  webtatic
php71w-mysqlnd.x86_64                      7.1.30-1.w6                  webtatic
php71w-odbc.x86_64                         7.1.30-1.w6                  webtatic
php71w-opcache.x86_64                      7.1.30-1.w6                  webtatic
php71w-pdo.x86_64                          7.1.30-1.w6                  webtatic
php71w-pdo_dblib.x86_64                    7.1.30-1.w6                  webtatic
php71w-pear.noarch                         1:1.10.4-1.w6                webtatic
php71w-pecl-apcu.x86_64                    5.1.9-1.w6                   webtatic
php71w-pecl-apcu-devel.x86_64              5.1.9-1.w6                   webtatic
php71w-pecl-geoip.x86_64                   1.1.1-1.w6                   webtatic
php71w-pecl-igbinary.x86_64                2.0.5-1.w6                   webtatic
php71w-pecl-igbinary-devel.x86_64          2.0.5-1.w6                   webtatic
php71w-pecl-imagick.x86_64                 3.4.3-1.w6                   webtatic
php71w-pecl-imagick-devel.x86_64           3.4.3-1.w6                   webtatic
php71w-pecl-memcached.x86_64               3.0.4-1.w6                   webtatic
php71w-pecl-mongodb.x86_64                 1.5.3-1.w6                   webtatic
php71w-pecl-redis.x86_64                   3.1.6-1.w6                   webtatic
php71w-pecl-xdebug.x86_64                  2.6.1-1.w6                   webtatic
php71w-pgsql.x86_64                        7.1.30-1.w6                  webtatic
php71w-phpdbg.x86_64                       7.1.30-1.w6                  webtatic
php71w-process.x86_64                      7.1.30-1.w6                  webtatic
php71w-pspell.x86_64                       7.1.30-1.w6                  webtatic
php71w-recode.x86_64                       7.1.30-1.w6                  webtatic
php71w-snmp.x86_64                         7.1.30-1.w6                  webtatic
php71w-soap.x86_64                         7.1.30-1.w6                  webtatic
php71w-tidy.x86_64                         7.1.30-1.w6                  webtatic
php71w-xml.x86_64                          7.1.30-1.w6                  webtatic
php71w-xmlrpc.x86_64                       7.1.30-1.w6                  webtatic

可以看出有php7.1 和php7.0两个版本可以安装。那么我们就安装php7.0版本。

安装php7.0

yum install php70w  php70w-devel php70w-fpm php70w-gd php70w-mysqli php70w-mbstring

漫长的过程过后:查看一下安装版本:

[root@i-op5nhxmi ~]# php -v
PHP 7.0.33 (cli) (built: Dec  7 2018 00:21:29) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

启动 php-fpm服务

因为nginx与php通信就是靠php-fpm,所以启动一下php-fpm.

[root@i-op5nhxmi ~]# service php-fpm status
php-fpm is stopped
[root@i-op5nhxmi ~]# service php-fpm
Usage: /etc/init.d/php-fpm {start|stop|status|restart|reload|force-reload|condrestart|try-restart|configtest}
[root@i-op5nhxmi ~]# service php-fpm start
Starting php-fpm:                                          [  OK  ]
[root@i-op5nhxmi ~]#

我们来测试一下:

现在/usr/share/nginx/html下面新建一个test文件夹,

[root@i-op5nhxmi html]# mkdir test

然后在该文件夹下新建一个文件

vim index.php

写入

<?php

phpinfo();

保存退出。

然后在/etc/nginx/conf.d/下新建一个配置文件

vim test.conf

写入一下内容保存退出:

server {
    listen 8080;
    server_name localhost;
    root /usr/share/nginx/html/test;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.php index.html index.htm;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        root /usr/share/nginx/html/test;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

然后重启nginx服务:

nginx -s reload

特别提示:如果启动过程中出现一下错误:

[root@i-op5nhxmi conf.d]# nginx -s reload
nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)

执行一下以下命令然后再重启:

nginx -c /etc/nginx/nginx.conf

然后访问ip:8080,就可以看见以下:

表示php和nginx都安装成功。

安装mysql

一、检查系统是否安装其他版本的MYSQL数据

[root@i-op5nhxmi conf.d]# yum list installed | grep mysql
mysql-libs.x86_64    5.1.73-3.el6_5     @updates
php70w-mysql.x86_64  7.0.33-1.w6        @webtatic

发现有,直接卸载:

yum -y remove mysql-libs.x86_64

二、安装及配置

wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
rpm -ivh mysql-community-release-el6-5.noarch.rpm
yum repolist all | grep mysql //查看可安装的mysql列表

安装mysql 数据库

yum install mysql-community-server -y

设置为开机启动(2、3、4都是on代表开机自动启动)

chkconfig --list | grep mysqld
chkconfig mysqld on

启动mysql

service mysqld start

设置root密码

mysql_secure_installation

登陆root账号

mysql -uroot -p 

设置utf-8编码

vi /etc/my.cnf

对比下面的参数,如果不存在就不补上:

[mysqld]
character-set-server=utf8 
collation-server=utf8_general_ci 
performance_schema_max_table_instances=400 
table_definition_cache=400 
table_open_cache=256
# 修改严格模式 如果不需要严格模式 直接注释掉
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysql]
default-character-set = utf8
[mysql.server]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
[client]
default-character-set = utf8

重启mysql

 service mysqld restart
暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇