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
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
相关文章推荐
- 如何从Apache官网下载windows版apache服务器
- Apache 学习笔记
- Apache Spark 初识
- linux服务器 Apache服务的源码安装与基本配置
- django apache error.log过大
- Apache Spark 1.6发布(新特性介绍)
- 【通信框架】Apache的开源通信框架thrift概述
- org.apache.log4j.Logger用法
- 入门: FreeBSD10.1+Apache2.4+PHP5.4+MySQL5.5
- chapter1 Apache ActiveMQ简介
- apache开源项目 --Struts
- apache开源项目--subversion
- apache开源项目--Syncope
- apache开源项目--Synapse
- apache开源项目 -- tez
- apache开源项目 -- tajo
- apache开源项目 -- tomee
- apache开源项目-- Turbine
- apache开源项目 -- Tuscany
- apache开源项目-- UIMA