• 对于注定会优秀的人来说,他所需要的,只是时间----博主
  • 手懒得,必受贫穷,手勤的,必得富足----《圣经》
  • 帮助别人,成就自己。愿君在本站能真正有所收获!
  • 如果你在本站中发现任何问题,欢迎留言指正!
  • 宝剑锋从磨砺出,梅花香自苦寒来!
  • 本站开启了防爆破关小黑屋机制,如果您是正常登录但被关进小黑屋,请联系站长解除!

用yum的方式快速安装lnmp环境(MySQL5.5&5.7,php5.x&7.x)

网站服务 eryajf 1个月前 (10-14) 130°C 已收录 0个评论
本文预计阅读时间 12 分钟

1,yum安装lnmp-5.x。

  • mysql-5.5
  • php-5.x

1,准备。

安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等

yum install epel-release -y

2,安装nginx

yum install nginx -y
systemctl start nginx
systemctl enable nginx

3,安装php

yum install -y php php-devel php-fpm php-mysql php-common php-devel php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel
systemctl start php-fpm
systemctl enable php-fpm

4,安装mysql

yum -y install mariadb mariadb-server
systemctl enable mariadb
systemctl restart mariadb

初始化数据库:

mysql_secure_installation << EOF

Y
123456
123456
Y
Y
Y
Y
EOF

密码是123456

然后验证一下:

[root@localhost ~]$mysql -u root -p123456 -e 'show databases'
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+

5,添加nginx配置

[root@jenkins ~]# cat /etc/nginx/conf.d/default.conf 
server {
    listen       80;
    server_name  10.0.40.245;

    root   /usr/share/nginx/html;

        location / {
            root   /usr/share/nginx/html;
            index index.php index.html index.htm;
        }

    error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html  
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        root           /usr/share/nginx/html;
        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即可

6,测试php是否正常运行

[root@jenkins ~]# cat /usr/share/nginx/html/index.php 
<?php

// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?>

web访问index.php

10.0.40.245/index.php

2,yum安装lnmp(MySQL-5.7,PHP-7.x)。

  • mysql-5.7
  • php-7.x

1,安装nginx。

安装nginx最新源

yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum repolist enabled | grep "nginx*"

安装nginx

yum -y install nginx

启动nginx

service nginx start

设置nginx服务器开机自启动

systemctl enable nginx.service

检查开机自动是否设置成功

systemctl list-dependencies | grep nginx

浏览器中输入本机ip,检测是否安装成功

http://127.0.0.1

2,安装mysql5.7

安装mysql源

yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"

安装mysql

yum -y install mysql-community-server mysql-community-devel

启动mysql

service mysqld start

检查mysql启动是否正常

service mysqld status 或者 ps -ef | grep mysql

设置mysqld服务开机自启动

systemctl enable mysqld.service

检查mysqld开机自启动是否设置成功

systemctl list-dependencies | grep mysqld

mysql5.7以后的争强了安全机制, 所以使用yum安装,启动会系统会自动生成一个随机的密码,修改mysql密码

查看mysql的随机密码

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

使用查询得到的随机密码在终端登录

mysql -u root -p 更改密码(mysql文档规定,密码必须包括大小写字母数字加特殊符号>8位)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Yourpassword';

退出mysql客户端,用刚才修改的密码登录确保密码修改成功

exit;
mysql -u root -p 

3,安装php7.1

安装php源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

检查源是否安装成功

 yum repolist enabled | grep "webtatic*"

安装php扩展源

yum -y install php71w php71w-fpm
yum -y install php71w-mbstring php71w-common php71w-gd php71w-mcrypt
yum -y install php71w-mysql php71w-xml php71w-cli php71w-devel
yum -y install php71w-pecl-memcached php71w-pecl-redis php71w-opcache

验证php7.1.x和扩展是否安装成功
验证php是否安装成功

php -v

验证对应的扩展是否安装成功

php -m

设置php-fpm并检测php-fpm的运行状态
启动php-fpm

service php-fpm start

检查启动是否成功

service php-fpm status

设置开机自启动

systemctl enable php-fpm.service

检查开机自启动是否设置成功

systemctl list-dependencies | grep php-fpm
ps -ef | grep php-fpm

4,配置nginx。

$ cat /etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  localhost;

    root   /usr/share/nginx/html;

        location / {
            root   /usr/share/nginx/html;
            index index.php index.html index.htm;
        }

    error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        root           /usr/share/nginx/html;
        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;
    }
}

weinxin
扫码订阅本站,第一时间获得更新
微信扫描二维码,订阅我们网站的动态,另外不定时发送WordPress小技巧,你可以随时退订,欢迎订阅哦~

二丫讲梵 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明用yum的方式快速安装lnmp环境(MySQL5.5&5.7,php5.x&7.x)
喜欢 (0)
[如果想支持本站,可支付宝赞助]
分享 (0)
eryajf
关于作者:
学无止境,我愿意无止境学。书山有路,我愿意举身投火,淬炼成金!

您必须 登录 才能发表评论!