CentOS + Apache2.4 + MySQL5.7 + PHP5.6 环境构筑

安装VirtualBox

按照安装向导安装VirtualBox-5.1.14-112924-OSX.dmg

安装CentOS7

CentOS-7-x86_64-DVD-1611.iso

安装Guest Additions

安装Apache2.4

  1. 安装

    # yum -y install httpd

  2. 启动httpd

    # systemctl restart httpd

  3. 外部可访问

    # firewall-cmd –add-service=http –permanent
    # firewall-cmd –reload

安装MySQL5.7

\$ sudo rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
\$ sudo yum install -y mysql-community-server

\$ mysqld –version # mysql server 版本确认
mysqld Ver 5.7.12 for Linux on x86_64 (MySQL Community Server (GPL))

\$ mysql –version # mysql client 版本确认
mysql Ver 14.14 Distrib 5.7.12, for Linux (x86_64) using EditLine wrapper

确认MySQL的初始化密码

启动MySQL

\$ sudo systemctl start mysqld.service

※MySQL 5.7初次启动时,自动生成初始化密码、可以在MySQL的LOG文件中确认

\$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root‘@’localhost’ (using password: YES)

\$ sudo cat /var/log/mysqld.log | grep ‘temporary password’ # 确认初始化密码
2016-04-21T14:20:10.491632Z 1 [Note] A temporary password is generated for root@localhost: xeqaVmIrY4=e

MySQL安全设定

\$ mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: # 输入初始化密码

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:

The ‘validate_password’ plugin is installed on the server.

The subsequent steps will run with the existing >configuration of the plugin.

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) : y

New password:

Re-enter new password:

Estimated strength of the password: 100

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

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) : y

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

Success.

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) : y

- Dropping test database…

Success.

- Removing privileges on test database…

Success.

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!

MySQL登录确认

\$ mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 6

Server version: 5.7.12 MySQL Community Server (GPL)

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;

+———————-+

| Database |

+———————-+

| information_schema |

| mysql |

| performance_schema |

| sys |

+———————-+

4 rows in set (0.00 sec)

mysql>

编辑设定文件,自启动设定

\$ sudo vi /etc/my.cnf

my.cnf

[mysqld]

character-set-server = utf8

default_password_lifetime = 0

\$ sudo systemctl restart mysqld.service

\$ sudo systemctl enable mysqld.service

\$ systemctl list-unit-files -t service | grep mysqld

mysqld.service enabled

外部访问设定

firewall-cmd –add-port=3306/tcp –permanent

mysql -uroot -p

grant all privileges on . to ‘root‘@’192.168.0.1’ identified by ‘password’ with grant option;

※IP:192.168.0.1可以访问,如果需要全部允许,需要设置成’%’

安装PHP5.6

# 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 install php56w php56w-common php56w-gd php56w-mbstring php56w-mcrypt php56w-mysqlnd

確認

# php -v

编辑httpd.conf

vi /etc/httpd/conf/httpd.confOptions Indexes FollowSymLinks

<Directory “/var/www/test”>

Options Indexes FollowSymLinks

AllowOverride None

Require all granted

</Directory>

Alias /test /var/www/test

</IfModule>

Alias /test /var/www/testAddType application/x-httpd-php .php <- 追加

php运行确认

vi /var/www/html/info.php

1
2
3
4
5
<?php

phpinfo();

?>

http://localhost/info.php

补充:

  1. 设定权限

    chmod -R 777 /var/www/test
    chown -R apache:apache /var/www/test

  2. selinux设定

    vi /etc/sysconfig/selinux
    selinux=disabled

Author: jimmy367
Link: http://www.ohtudou.com/2017/06/21/make-php5-dev/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
支付宝打赏