您的位置:首页 > 运维架构 > Apache

CentOS 7.0 yum安装Apache、PHP和MySQL

2016-01-06 23:08 866 查看
1. 安装Apache, PHP, MySQL以及php连接mysql库组件。

yum -y install httpd php mariadb mariadb-server php-mysql

2. 安装apache扩展

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

3. 安装php的扩展

yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc

4. 安装MySQL的扩展

yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

5. 配置开机启动服务

systemctl start httpd.service [启动httpd服务]

systemctl enable httpd.service [设置httpd服务开机启动]

systemctl start mariadb.service [启动mysql服务]

systemctl enable mariadnysmysqeixb.service [设置mysql服务开机启动]

注意: MySQL默认安装的后,root密码为空.

mysql_secure_installation [设置mysql安全性,设置root密码,远程访问,去除test数据库等]

登录mysql

使用mysql数据库

添加外网访问帐号:

GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY 'root' WITH GRANT OPTION;

6. 配置firewalld,开启80端口和mysql数据库端口

a. 安装net-tools

yum install net-tools

b. 查看开放端口

netstat -lntp #查看监听(Listen)的端口

c. firewall 添加80,3306端口

firewall-cmd --permanent --add-port=80/tcp

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

d. 用该命令查询是否添加成功

firewall-cmd --permanent --query-port=80/tcp

firewall-cmd --permanent --query-port=3306/tcp

e. firewall-cmd --reload

7. 绑定域名

在/etc/httpd/conf/httpd.conf配置文件中,提供了范例:

#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for requests without a known

# server name.

#

#<VirtualHost *:80>

# ServerAdmin webmaster@dummy-host.example.com

# DocumentRoot /www/docs/dummy-host.example.com

# ServerName dummy-host.example.com

# ErrorLog logs/dummy-host.example.com-error_log

# CustomLog logs/dummy-host.example.com-access_log common

#</VirtualHost>

所以绑定域名可以跟着提供的范例来配置即可。

8. 其他常见问题

a.selinux 常用命令

查看SELinux状态:sestatus

临时关闭(不用重启机器)setenforce 0 ,重启后失效,1为开启

查看文件属性:ls -Z

b. centos httpd 访问新目录无权限的问题

默认的selinux规定httpd只能访问httpd_sys_content_t类的文件,因此$ chcon -Rt httpd_sys_content_t <你的目录>就可以了。

c. 数据目录(临时文件或缓存目录)无法读写问题

semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/m30_data(/.*)?"

restorecon -R /var/www/m30_data

这样就可以解决在/var/www/m30_data目录下的读写问题了。

另外:semanage的安装命令是:yum -y install policycoreutils-python

d. selinux 报错日志查看

yum install setroubleshoot

它本身是一个GUI套件,不过其中包含的一个sealert命令对我们命令行用户很有用:

$ sealert -a /var/log/audit/audit.log

e. php无法发送邮件问题:因为selinux默认设置不能发送邮件

sendmail: fatal: chdir /var/spool/postfix: Permission denied

解决办法:

setsebool httpd_can_sendmail on
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: