CentOS 7.6 部署 Apache Nginx PHP MySQL Phpmyadmin Redis phpRedisAdmin

本文详细介绍了如何在CentOS 7.6上部署LNMP环境,包括Apache、Nginx、PHP、MySQL、Phpmyadmin、Redis以及phpRedisAdmin的安装和配置过程。首先更新系统,然后依次安装Apache、MySQL、PHP7.3,接着配置Nginx并确保其能正确处理PHP请求,将Apache配置为监听特定端口。同时,还涉及了MySQL的初始化、Redis的安装和phpMyAdmin的配置。最后,提到了如何升级Nginx以及安装phpRedisAdmin。
摘要由CSDN通过智能技术生成

CentOS 7.6 部署 Apache Nginx PHP MySQL Phpmyadmin Redis phpRedisAdmin

Step 1 更新系统

yum -y update

Step 2 安装 Apache

yum -y install httpd

安装完成后,打开 httpd 的配置文件

vim /etc/httpd/conf/httpd.conf

把 ServerName 前的 # 去掉,并修改为:ServerName localhost 并保存,启动 httpd

service httpd start

浏览器访问服务器IP,可以看到欢迎页面了。说明安装成功

Step 3 安装 MySQL

下载MySQL Yum源

wget https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm

下载完成执行下面命令安装MySQL Yum源

yum localinstall mysql80-community-release-el7-1.noarch.rpm

现在可以安装最新版本的MySQL了

yum install mysql-community-server

启动MySQL

service mysqld start

查询MySQL初始化默认密码

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

比如我这里的结果是

[root@iZ2zebfvkmy1wcs3yeowl8Z ~]# grep 'temporary password' /var/log/mysqld.log
2019-02-24T19:21:59.954017Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 3D).aNZSw/Lw

初始化MySQL

mysql_secure_installation

[root@iZ2zebfvkmy1wcs3yeowl8Z ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : yes
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

Step 4 安装 PHP

安装PHP源

yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

yum -y install epel-release yum-utils

删除PHP5.4的源

yum-config-manager --disable remi-php54

启动PHP7.3的源

yum-config-manager --enable remi-php73

安装PHP7.3

yum -y install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json

安装完成。检查PHP版本 php -v

[root@iZ2zebfvkmy1wcs3yeowl8Z ~]# php -v
PHP 7.3.2 (cli) (built: Feb  5 2019 13:10:03) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.2, Copyright (c) 1998-2018 Zend Technologies

Step 5 安装 Nginx

先关闭 Apache

service httpd stop

CentOS 官方 rpm 源是没有 nginx 安装包的,需要手动添加

cd /etc/yum.repos.d/

vim nginx.repo

往 nginx.repo 文件里添加如下代码

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch
gpgcheck=0
enabled=1

保存后,即可开始安装 Nginx

yum -y install nginx

安装结束后,启动 Nginx

service nginx start

浏览器访问服务器IP,可以看到欢迎页面了。说明安装成功

Step 6 配置 Nginx

vim /etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  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;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

解注释掉第24-26行,也就是这行

    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1:8080;
    #}

修改第10行代码,添加index.php

        index  index.php index.html index.htm;

即当 Nginx 接收 http 请求遇到需要解析 php 脚本时,则交给 127.0.0.1:8080 端口来处理,而我们等下配置让 Apache 来监听处理这个端口发来的请求。

Step 7 编辑 Apache 的配置文件

vim /etc/httpd/conf/httpd.conf

找到 Listen 字段,并改为:Listen 127.0.0.1:8080,让 Apache 来监听这个端口,修改 Apache 的网站根目录为:”/usr/share/nginx/html”,与上述 Nginx 对应的网站目录保持一致

找到下面的行,然后按照下面的内容来修改

Listen 127.0.0.1:8080
...
ServerName localhost
...
DocumentRoot "/usr/share/nginx/html"
...
<Directory "/usr/share/nginx/html">
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值