第一 先安装nginx
nginx在官方CentOS社区yum里面没有,需要在nginx的官方网站去下载yum的配置文件
官方:https://www.nginx.com/resources/wiki/start/topics/tutorials/install/
配置文件/etc/yum.repos.d/nginx.repo(还有一种,官方做了rpm的nginx yum repo,安装rpm,就会在/etc/yum.repo.d/目录下生产文件)
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/basearch/ $releasever 是linux 的版本号centos 7
gpgcheck=0 enabled=1</pre>
配置后查看 yum list nginx ,就会发现有了nginx,然后我们就可以安装了。
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">yum install nginx</pre>
看到nginx安装成功,就是启动它了, which nginx (rpm -ql nginx)可以看它的目录
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">/etc/init.d/nginx start //CentOS6
/bin/systemctl start nginx //CentOS7 //还可以在目录文件中启动 //加入开机启动以后研究</pre>
验证:输入ip地址查看默认网页
参考查看 : https://www.cnblogs.com/fps2tao/p/7577378.html
第二 安装 php
(我是感觉安装php会一块安装依赖把(apache)httpd也安装上去,但是单纯安装(apache)httpd,再安装php需要配置apache的配置文件支持php扩展)
如下:
[](javascript:void(0); "复制代码")
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">编辑 /usr/local/apache2/conf/httpd.conf 文件时要注意:
找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在后面添加:
AddType application/x-httpd-php .php(使Apcche支持PHP)
AddType application/x-httpd-php-source .php5
找到: <IfModule dir_module> DirectoryIndex index.html </IfModule> 添加: <IfModule dir_module> DirectoryIndex index.html index.php </IfModule> 找到: #ServerName www.example.com:80 修改为: ServerName 127.0.0.1:80或者ServerName localhost:80 记得要去掉前面的“#”
修改默认的Web站点目录
找到:DocumentRoot "/usr/local/apache2/htdocs" 修改为:DocumentRoot "/home/www/WebSite" --该目录为自己创建的目录
找到:<Directory "/usr/local/apache2/htdocs"> 修改为:<Directory "/home/www/WebSite"></pre>
[](javascript:void(0); "复制代码")
直接安装php这个配置可以不看
查看 yum list php php-fmp
这里为啥要安装php-fpm,因为php-fpm,是nginx和php的桥梁,php-fpm(快速进程管理),php-fpm默认进程为127.0.0.1:9000,一会php和php-fpm安装完成后,要配置nginx的配置文件,让其遇到客户端php请求是,转发给php-fpm(127.0.0.1:9000),php-fpm再让php解析完成,最后又给nginx.
安装:
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">yum install -y php php-fpm</pre>
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">yum install php php-pear php-devel httpd //可选,参数更新中 php-pear为php的扩展工具,安装后可以用pecl install 命令安装php扩展 </pre>
安装成功后,然后在配置nginx的配置文件,让它遇到php的时候转发给php-fpm
[](javascript:void(0); "复制代码")
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">
location ~ .phpfastcgi_script_name; //
/script要改成 $document_root 及/usr/share/nginx/html路径,后面是文件名,
就是这个绝对路径的文件名给php-fpm
include fastcgi_params;
}</pre>
](javascript:void(0); "复制代码")
然后重启nginx ,启动 php-fpm 后用phpinfo()测试.
[](javascript:void(0); "复制代码")
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">//CentOS7
/bin/systemctl restart nginx /bin/systemctl start php-fpm //CentOS6
/etc/init.d/nginx restart /etc/init.d/php-fpm start</pre>
](javascript:void(0); "复制代码")
此时 nginx 和php 已经安装成功,但是php还不能连接mysql,先别急往后看.
注:php7的安装方法:
http://www.cnblogs.com/fps2tao/p/7577544.html
第三 安装mysql
因为CentOS7现在已经 不支持 mysql了,取而代之的是mariadb.所以mysql 的yum repo,要在官网获取.
网址 :https://dev.mysql.com/downloads/repo/yum/
安装一个适合自己系统的mysql,下载的是rpm包,安装后会在/etc/yum.repos.d/下面建立msyql的repo.( mysql-community.repo)
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm</pre>
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">rpm -ivh mysql57-community-release-el7-11.noarch.rpm</pre>
更新一下本地的yum库
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">yum clean yum makecache</pre>
安装
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">yum install mysql mysql-server php-mysql</pre>
php-mysql是php连接数据库的插件,不然php没有连接mysql的接口(msyql可以正常启动也没办法)。
安装完成后启动
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">#systemctl start mysqld</pre>
安装完成之后会自动在log中生成连接的密码
查看密码:
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@mysqlA ~]# cat /var/log/mysqld.log |grep password 2016-08-23T02:33:48.872073Z 1 [Note] A temporary password isgenerated for root@localhost: %IrczkB+J7Ez</pre>
你必须重新设置密码才能执行语句
[](javascript:void(0); "复制代码")
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">[root@mysqlA ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. commands end with ; or \g.
Your MySQL connection id is 4 Server version: 5.7.14 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.</pre>
](javascript:void(0); "复制代码")
修改密码~
这个安装后不用配置,直接重启php-fpm.
测试
扩展内容:mysql 密码修改
https://www.cnblogs.com/fps2tao/p/9950989.html
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">ALTER user 'root'@'localhost' IDENTIFIED BY 'L123#@'</pre>
其实想要重置 5.7 的密码很简单,就一层窗户纸:
1、修改/etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1
这一行配置让 mysqld 启动时不对密码进行验证
2、重启mysqld 服务:systemctl restart mysqld
3、使用 root 用户登录到 mysql:mysql -uroot
4、切换到mysql数据库,更新 user 表:
update user set authentication_string = password('123456'),password_expired = 'N', password_last_changed = now() where user = 'root';
在之前的版本中,密码字段的字段名是 password,5.7版本改为了 authentication_string
在修改了密码后 刷新一下缓存
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">flush privileges;</pre>
5、退出 mysql,编辑 /etc/my.cnf 文件,删除 skip-grant-tables=1的内容
6、重启mysqld 服务,再用新密码登录即可
不然 下面这些远程和 更改密码的sql 都不能运行
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">mysql> -- 下面我们另外添加一个新的 root 用户, 密码为空, 只允许 192.168.1.100 连接
mysql> GRANT ALL PRIVILEGES ON . TO 'root'@'192.168.1.100' IDENTIFIED BY '' WITH GRANT OPTION;</pre>
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">mysql> flush privileges;</pre>
<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">mysql> update user set password=PASSWORD('123456') where user='root';
mysql> flush privileges;</pre>
部署项目
mkdir -p /data/www
cd /usr/local/src/zabbix-3.2.6
cp -r ./frontends/php/ /data/www/项目名 若给出的源文件是一个目录文件,此时将复制该目录下所有的子目录和文件。
chown -R nobody.nobody /data/www/项目名/
使用chown -hR
h表示修改symbolic链接而不去修改对应的文件。
R表示在所有子目录及目录中的文件中递归执行。
具体参数说明:
-h, --no-dereference affect each symbolic link instead of any referenced
file (useful only on systems that can change the
ownership of a symlink)
-R, --recursive operate on files and directories recursively
chown -hR nobody:nobody /opt/lampp/htdocs/xxx
上面这个命令付给/opt/lampp/htdocs/xxx文件夹的所有者是nobody,还把这个文件夹赋予组nobody所有权限