资讯专栏INFORMATION COLUMN

Centos7.3安装Apache2.4 mysql5.6 PHP7

oysun / 541人阅读

摘要:安装更新源安装服务启动服务设置开机启动服务安装更新源安装安装成功后,将其加入开机启动启动服务进程配置具体设置项新安装之后设置示例版本是,操作系统均可。需更改数据库里的表里的项把改称。设置最大可存入数据库字段的值长度。

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

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/29411.html

相关文章

  • 在Ubuntu18.04服务器安装Apache2.4/MariaDB10.3/PHP7.2

    摘要:在这篇文章中,我们将分享在最新系统镜像中安装常规的软件环境。出于安全的考虑,以及我们后续安装网站,需要禁止默认根目录执行。这个其实与安装后设置相似。这样,在安装完毕之后,我们可在中安装完毕,且软件都是比较新的。 在这篇文章中,我们将分享在最新Ubuntu18.04系统镜像中安装LAMP常规的软件环境。其中软件包括Apache2.4/MariaDB10.3/PHP7.2,这里我们看到不安...

    dockerclub 评论0 收藏0
  • php7 + mysql5.7 +apache2.4 on Ubuntu 14.04

    摘要:如果想通过来安装,则需要添加源。目前网上给出的大部分答案是这样的这样是找不到版本的。通过,找到了正确的安装步骤这样才能通过来安装在安装过程中,会要求输入的密码。排错如果页面空白,请尝试强制刷新页面。此时应该可以看见中的内容了。 Ubuntu 14.04 安装并配置LAMP 标签:Ubuntu Linux Apache2.4 Mysql5.7 php7.0 开始之前 系统版本 Ubu...

    gougoujiang 评论0 收藏0

发表评论

0条评论

oysun

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<