Centos 7 PHP开发环境搭建

来源:互联网 发布:学淘宝美工需要多少钱 编辑:程序博客网 时间:2024/06/07 06:14

软件包安装

安装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.rpmshell# 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.rpmshell# wget https://mirror.webtatic.com/yum/el7/webtatic-release.rpmshell# rpm -ivh epel-release.rpmshell# rpm -ivh webtatic-release.rpm

安装PHP及一些需要的扩张

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

PHP配置

#/etc/php.inidate.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 runtimeshell# chmod 757 runtime
0 0
原创粉丝点击