Centos 7 PHP开发环境搭建

软件包安装

安装Apache

shell# yum install httpd

安装完成之后使用以下命令查看Apache版本

shell# apachectl -v

安装MySQL

由于Centos不再提供MySQL安装包,需要配置yum源

shell# wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
shell# rpm -ivh mysql57-community-release-el7-7.noarch.rpm

接下来安装MySQL

shell# yum install mysql-community-server

安装PHP

由于Centos 7提供的PHP版本与需求不一致,需要配置第三方yum源

shell# wget https://mirror.webtatic.com/yum/el7/epel-release.rpm
shell# wget https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
shell# rpm -ivh epel-release.rpm
shell# rpm -ivh webtatic-release.rpm

安装PHP及一些需要的扩张

shell# yum install php56w php56w-mysqlnd php56w-gd php56w-mbstring

PHP配置

#/etc/php.ini
date.timezone = Asia/Shanghai

MySQL配置

配置默认字符集

#/etc/my.cnf
#在mysqld下添加character_set_server配置参数
[mysqld]
#...
character_set_server=utf8
#...
#添加mysql和client配置项,并设置默认字符集
[mysql]
default-character-set = utf8

[client]
default-character-set = utf8

设置root用户密码

启动mysql服务

shell# service mysqld start

从/var/log/mysqld.log查找默认的root用户密码

shell# grep 'temporary password' /var/log/mysqld.log

修改密码

shell# mysqladmin -uroot -p 'old-password' password 'new-password'

配置sql_mode

在开发过程中,因为不全用select字句中的列作为group by字句的参数,因此需要把ONLY_FULL_GROUP_BY配置参数去掉。
在MySQL终端使用以下命令查看当前的sql_mode配置,将ONLY_FULL_GROUP_BY以外的配置参数复制下来

mysql> select @@GLOBAL.sql_mode

将上面复制下来的内容填写到MySQL配置文件中

#/etc/my.cnf
#在mysqld下添加sql_mode配置参数
[mysqld]
#...
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

其他

开放80端口。因为Centos 7默认只开放了ssh访问端口,想要访问WEB服务器,需在iptables中打开80端口。

shell# iptables -A IN_public_allow -p tcp -m tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT

配置httpd开机启动。安装Apache服务后并没有自动将httpd服务添加到开机启动配置中,因此需手动配置。

shell# systemctl enable httpd

目录写入权限。因为Centos默认开启SELinux,因此如果想在WEB目录下写入文件(如缓存/日志文件),则需要给该目录设置SELinux对应的权限。如下:

shell# chcon -R -t httpd_sys_content_rw_t runtime
shell# chmod 757 runtime
  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值