这次的环境搭建,都是通过yum进行安装的,而没有通过编译源码进行安装。
先来看目标版本,这是安装后的信息:
点击(此处)折叠或打开
- # uname -a
- Linux localhostww.localdomain 4.1.12-112.14.13.el7uek.x86_64 #2 SMP Thu Jan 18 11:38:29 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
- # httpd -version
- Server version: Apache/2.4.6 ()
- Server built: Apr 11 2018 05:56:48
- # mysqld --version
- /usr/sbin/mysqld Ver 8.0.11 for Linux on x86_64 (MySQL Community Server - GPL)
- # php -v
- PHP 7.1.19 (cli) (built: Jun 25 2018 13:58:17) ( NTS )
- Copyright (c) 1997-2018 The PHP Group
- Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
1. 安装Apahce (httpd)
1.1 安装
这个很简单:
点击(此处)折叠或打开
- # yum install httpd
1.2 小插曲
然而,遇到了个小问题:点击(此处)折叠或打开
- Loaded plugins: langpacks, ulninfo
- Existing lock /var/run/yum.pid: another copy is running as pid 2657.
- Another app is currently holding the yum lock; waiting for it to exit...
这是个常见的问题,原因是yum在尝试更新。
我们来查一下进程以及父进程信息:
点击(此处)折叠或打开
- # ps -ef | grep yum
- root 2657 1571 0 07:23 ? 00:00:00 /usr/bin/python /usr/share/PackageKit/helpers/yum/yumBackend.py get-updates none
- # ps -ef | grep 1571
- root 1571 1 0 07:21 ? 00:00:01 /usr/libexec/packagekitd
- root 2657 1571 0 07:23 ? 00:00:00 /usr/bin/python /usr/share/PackageKit/helpers/yum/yumBackend.py get-updates none
把父进程1571杀掉,然后再查,此时已经没有相关进程了。
点击(此处)折叠或打开
- # kill -9 1571
- # ps -ef | grep yum | grep -v grep
- #
1.3 再次安装
再通过yum安装httpd,一切OK。点击(此处)折叠或打开
- # yum install httpd
1.4 启动httpd, 测试
默认的httpd是80端口,先查看一下;很好,这个端口没有被监听。
点击(此处)折叠或打开
- # netstat -an | grep 80
启动 httpd
点击(此处)折叠或打开
- # systemctl start httpd.service
再看一下监听端口,有了:
点击(此处)折叠或打开
- # netstat -an | grep 80
- tcp6 0 0 :::80 :::*
也可以通过浏览器来查看apache默认的测试界面:
点击(此处)折叠或打开
- http://localhost:80
2. 安装PHP
2.1 检查并删除现有的PHP版本
参考连接
最终,执行如下命令查看是否已经完全删除:
点击(此处)折叠或打开
- # php -v
- bash: php: command not found...
- # rpm -qa|grep php <-- 没有返回就对了
2.2 下载rpm并安装
我是通过yum安装的,所以可以掠过此处.参考官方连接
根据上述描述,需要下载php 7.1.9的rpm,可以从这里下载。
2.3 更新yum的repo,并且安装PHP
仍旧参考官方连接。更新yum的repo:
点击(此处)折叠或打开
- # cd /etc/yum.repos.d
- # mv public-yum-ol7.repo public-yum-ol7.repo.bak
- # wget http://yum.oracle.com/public-yum-ol7.repo
在repo中设置要安装的PHP版本:
点击(此处)折叠或打开
- # yum install yum-utils
- # yum-config-manager --enable ol7_developer_php71
安装
点击(此处)折叠或打开
- # yum install php
2.4 测试安装
点击(此处)折叠或打开- # which php
- /usr/bin/php
- # php -v
- PHP 7.1.19 (cli) (built: Jun 25 2018 13:58:17) ( NTS )
- Copyright (c) 1997-2018 The PHP Group
- Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
2.5 安装其他相关组件
这些在后续开发中会用到,一起安装了吧点击(此处)折叠或打开
- yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash libmcrypt
遇到一个不能成功安装的,暂时略过,不影响环境搭建
点击(此处)折叠或打开
- # yum install php-mcrypt
- Loaded plugins: langpacks, ulninfo
- Resolving Dependencies
- --> Running transaction check
- ---> Package php-mcrypt.x86_64 0:5.4.16-7.el7 will be installed
- --> Processing Dependency: php(zend-abi) = 20100525-64 for package: php-mcrypt-5.4.16-7.el7.x86_64
- --> Processing Dependency: php(api) = 20100412-64 for package: php-mcrypt-5.4.16-7.el7.x86_64
- --> Finished Dependency Resolution
- Error: Package: php-mcrypt-5.4.16-7.el7.x86_64 (epel)
- Requires: php(api) = 20100412-64
- Installed: php-common-7.1.19-1.0.1.el7.x86_64 (@ol7_developer_php71)
- php(api) = 20160303-64
检查一下我们的安装:
点击(此处)折叠或打开
- # yum list installed | grep php
- gd-last.x86_64 2.1.1-2.el7 @ol7_developer_php71
- php.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-bcmath.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-cli.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-common.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-gd.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-imap.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-ldap.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-mbstring.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-mysqlnd.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-odbc.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-pdo.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-pear.noarch 1:1.9.4-21.el7 @ol7_latest
- php-process.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-xml.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
- php-xmlrpc.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
2.6 测试PHP是否工作
在"/etc/www/html"下创建这样一个测试文件:(不知什么原因,简单的插入php代码,会导致我后面的章节统统给删掉;在经历了2次这样的事情后,还是简单的在代码中加入几个##吧)。
- #touch /etc/www/html/index.php
- with content
- ##<##?php
- phpinfo();
- ##?##>
在浏览器里访问"http://localhost:80/index.php",结果不对。
需要重新启动httpd,之后就OK了。
- # syystemctl start httpd.service
3. 安装mysql
参考链接3.1 添加mysql的repo
从这里下载mysql的repo,我下载的是"mysql80-community-release-el7-1.noarch.rpm"然后添加到本地repo里:
- # yum localinstall mysql80-community-release-el7-1.noarch.rpm
# yum repolist enabled | grep"mysql.*-community.*"
mysql-connectors-community/x86_64 MySQLConnectorsCommunity 51
mysql-tools-community/x86_64 MySQL ToolsCommunity 63
mysql80-community/x86_64 MySQL 8.0 CommunityServer 17
- [mysql80-community]
- name=MySQL 8.0 Community Server
- baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
- enabled=1
- gpgcheck=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
- # sudo yum-config-manager --disable mysql57-community
- # sudo yum-config-manager --enable mysql80-community
3.2 安装mysql
- # sudo yum install mysql-community-server
- # yum list installed | grep mysql
- mysql-community-client.x86_64 8.0.11-1.el7 @mysql80-community
- mysql-community-common.x86_64 8.0.11-1.el7 @mysql80-community
- mysql-community-libs.x86_64 8.0.11-1.el7 @mysql80-community
- mysql-community-libs-compat.x86_64 5.7.16-1.el7 @Server-Mysql/7.3
- mysql-community-server.x86_64 8.0.11-1.el7 @mysql80-community
- mysql80-community-release.noarch el7-1 installed
- php-mysqlnd.x86_64 7.1.19-1.0.1.el7 @ol7_developer_php71
3.3 启动
- # systemctl start mysqld.service
3.4 获取并修改临时密码
密码存在log文件里,获取临时密码后,修改密码- # grep 'temporary password' /var/log/mysqld.log
- 2018-06-28T07:40:46.220757Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fh!dh_o)z8fD
# mysql -uroot -p'fh!dh_o)z8fD'
mysql> ALTER USER 'root'@'localhost'IDENTIFIED BY 'HHhh0011_2233';
4. 总体测试 (Aphache/PHP/Mysql)
4.1 创建数据库
- mysql> create database root_db1;
- mysql> use root_db1;
- mysql> create table MyGuests(id int auto_increment, firstname varchar(20), lastname varchar(20), primary key (id));
- mysql> desc MyGuests;
- +-----------+-------------+------+-----+---------+----------------+
- | Field | Type | Null | Key | Default | Extra |
- +-----------+-------------+------+-----+---------+----------------+
- | id | int(11) | NO | PRI | NULL | auto_increment |
- | firstname | varchar(20) | YES | | NULL | |
- | lastname | varchar(20) | YES | | NULL | |
- +-----------+-------------+------+-----+---------+----------------+
- 3 rows in set (0.00 sec)
- mysql> insert into MyGuests (firstname, lastname) values( 'aa', 'bb');
- mysql> insert into MyGuests (firstname, lastname) values( 'xx', 'yy');
- mysql> select * from MyGuests;
- +----+-----------+----------+
- | id | firstname | lastname |
- +----+-----------+----------+
- | 1 | aa | bb |
- | 2 | xx | yy |
- +----+-----------+----------+
- 2 rows in set (0.01 sec)
4.2 创建php代码
- ##<span style="font-size:14px;"##>
- ##<##?php
- $servername = "127.0.0.1";
- $port=3306;
- $username = "root";
- $password = "HHhh0011_2233";
- $dbname = "root_db1";
- $socket="mysqli.default_socket";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname,$port,$socket);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed 1: " . $conn->connect_error);
- }
- $sql = "SELECT id, firstname, lastname FROM MyGuests";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "
"; - }
- } else {
- echo "0 results";
- }
- $conn->close();
- ##?##>
4.3 测试
直接测试PHP程序,报错。
- #php /var/www/testMysql01.php
- return err:
- PHP Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in /var/www/html/testMysql01.php on line 10
- PHP Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in /var/www/html/testMysql01.php on line 10
- Connection failed 1: The server requested authentication method unknown to the client
- # mysql -uroot -pHHhh0011_2233
- mysql> select user,plugin from mysql.user;
- +------------------+-----------------------+
- | user | plugin |
- +------------------+-----------------------+
- | mysql.infoschema | mysql_native_password |
- | mysql.session | mysql_native_password |
- | mysql.sys | mysql_native_password |
- | root | caching_sha2_password|
- +------------------+-----------------------+
- mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '0racle_Nis';
- mysql> select user,plugin from mysql.user;
- +------------------+-----------------------+
- | user | plugin |
- +------------------+-----------------------+
- | mysql.infoschema | mysql_native_password |
- | mysql.session | mysql_native_password |
- | mysql.sys | mysql_native_password |
- | root | mysql_native_password |
- +------------------+-----------------------+
- mysql> exit
- # php testMysql01.php
- id: 1 - Name: aa bb
id: 2 - Name: xx yy