1. 安装Apache 2.4

更新源:
rpm -Uvh https://dl.fedoraproject.org/...
rpm -Uvh https://mirror.webtatic.com/y...

安装服务:
yum -y install httpd

CentOS7启动服务:
systemctl start httpd.service

CentOS7设置开机启动服务:
systemctl enable httpd.service

2. CentOS7安装MySQL 5.6

更新源:
rpm -Uvh http://dev.mysql.com/get/mysq...

安装MySQL5.6:
yum -y install mysql-community-server

安装成功后,将其加入开机启动:
systemctl enable mysqld

启动mysql服务进程:
systemctl start mysqld

配置MySQL:
mysql_secure_installation
具体设置项:新安装MySQL之后设置
示例版本是MySQL5.6,操作系统CentOS6.5 - 7.3均可。

配置MySQL初始设置:
进行一些安全性配置
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

  SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y <--是否设置Root密码?
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

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? [Y/n] 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? [Y/n] n <--是否允许Root远程登录?一般选择Y,不过我为了方便测试,先选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? [Y/n] y <--是否删除测试数据库?

  • Dropping test database...

ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...

  • 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? [Y/n] y <--是否刷新权限?
... Success!

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

配置远程访问
MySQL不允许远程用户访问主机服务器 1130连接报错:
ERROR 1130: Host ... is not allowed to connect to this MySQL server
说明所连接的用户帐号没有远程连接的权限,只能在本机(localhost)登录。 需更改 mysql 数据库里的user表里的host项把localhost改称%。

具体步骤:
登陆mysql :
[root@localhost ~]# mysql -uroot -p
mysql> use mysql
mysql> update user set host='%' where user = 'root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
有时候会报错,但是不要紧,查看一下成功否。

mysql> select host from user where user = 'root';
host
%
127.0.0.1
::1
izm5edi5djftntq1oes7sfz

4 rows in set (0.00 sec)
host已经有了%这个值,所以没问题了。
mysql> flush privileges;

mysql> set global max_allowed_packet = 210241024*10;
设置最大可存入数据库字段的值长度。

Query OK, 0 rows affected (0.00 sec)
可以远程访问了

3. 安装PHP 7.1

安装与设置
安装最新版:
yum -y install mod_php71w php71w-bcmath php71w-cli php71w-common php71w-devel php71w-fpm php71w-gd php71w-mbstring php71w-mcrypt php71w-mysql php71w-snmp php71w-xml php71w-process php71w-ldap net-snmp net-snmp-devel net-snmp-utils rrdtool

查看版本:
php -v

基础配置(保证一些基本使用):
vi /etc/php.ini

修改时区:把;date.timezone改为date.timezone =PRC;
memory_limit = 2048M
upload_max_filesize = 64M

测试
vim /var/www/html/index.php
<?php
phpinfo();
保存退出,浏览器访问:
附加:安装git、npm、composer(如果有需要)
yum install -y git
yum install -y npm
cd ~
curl -sS https://getcomposer.org/insta... | php --
mv composer.phar /usr/local/bin/composer
chmod -R 777 /usr/local/bin/composer

附加:配置PHP7-FPM与nginx(如果有需要)
vi /etc/php-fpm.d/www.conf

在第 8 行和第 10行,user 和 group 赋值为 nginx:
  user = nginx  
  group = nginx
在第 22 行,确保 php-fpm 运行在指定端口:
  listen = 127.0.0.1:9000
取消第 366-370 行的注释,启用 php-fpm 的系统环境变量:
  env[HOSTNAME] = $HOSTNAME  
  env[PATH] = /usr/local/bin:/usr/bin:/bin  
  env[TMP] = /tmp  
  env[TMPDIR] = /tmp  
  env[TEMP] = /tmp
保存文件并退出。

在 /var/lib/ 目录下创建一个新的文件夹 session,并将其拥有者变更为 nginx 用户:

mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/
启动 php-fpm 和 Nginx,并将它们设置开机启动
systemctl start php-fpm.service
systemctl start nginx.service
systemctl enable php-fpm
systemctl enable nginx


Mrlijie
219 声望4 粉丝

php工程师