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">