admin 管理员组

文章数量: 1086019


2024年2月23日发(作者:matlab中的求导函数有那些)

Centos7.1 配置apache+mysql+php环境

1. 配置固定IP

cd /etc/sysconfig/network-scripts/

ls

该目录下文“ifcfg-enp2s0”就是网络配置文件,使用vi命令编辑它:

TYPE=Ethernet

BOOTPROTO=none

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

IPV6_FAILURE_FATAL=no

NAME=enp2s0

UUID=90273957-5584-4c2f-90c8-e32ab7883be9

DEVICE=enp2s0

ONBOOT=yes

IPADDR0=192.168.1.5

GATEWAY0=192.168.1.1

DNS1=192.168.1.1

修改完配置文件后,按下Esc并输入命令 :wq! 保存并退出

重启网络服务,输入命令: service network restart

2. 关闭firewall

#停止firewall

systemctl stop e

#禁止firewall开机启动

systemctl disable e

3. 安装iptables防火墙

yum install iptables-services

#编辑防火墙配置文件

vi /etc/sysconfig/iptables

4. 关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing

#SELINUXTYPE=targeted

SELINUX=disabled

#保存

:wq!

#使配置立即生效

setenforce 0

5. 安装Apache

yum install httpd

# 开机自启动

systemctl enable httpd

# 启动httpd 服务

systemctl start httpd

### 安装apache 一些扩展

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

6. 安装MySQL

#安装rpm包

rpm -Uvh /get/

#查看mysql可用的源

yum repolist enabled | grep "mysql.*-community.*"

#yum安装mysql5.6

yum -y install mysql-community-server

# 开机启动

systemctl enable mysqld

# 启动mysqld服务

systemctl start mysqld

说明:Centos7.1已经使用MariaDB替代了MySQL数据库,可以使用yum install mariadb

mariadb-server进行安装,这里仍安装mysql

7. 安装php

yum install php

#安装php组件

yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc

php-mbstring php-bcmath php-mhash

8. 安装mcrypt扩展

yum install php-devel

yum install libmcrypt

yum install libmcrypt-devel

yum install mhash

wget /php5/

tar -xvzf

cd php-5.4.16/ext/mcrypt/

phpize

php-config

./configure

make && make install

修改文件,添加extension=

9. 安装ZendGurdloader(5.3/5.4只能安装对应版本的ZendGuardLoader)

mkdir /usr/zend

32位下载:

64位下载:ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_

tar zxvf ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_

cd ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/

cp /usr/zend/

#修改文件,在最后添加:

zend_extension=/usr/zend/

zend_=1

zend_e_licensing=0

zend_ation_level_support=3

zend_e_path=

#重启apache

systemctl restart httpd

常见问题:mysql_connect 错误

mysql_connect(): Headers and client library minor version mismatch.

Headers:这样的错误是由于高版本的MySQL,低版本的MySQL Client API引起的,我在CentOS 7上安装MySQL-Server的时候出现了这个错误,解决办法:

卸载php-mysql

1. yum remove php-mysql -y

安装php-mysqlnd

1. yum install php-mysqlnd -y

重启httpd

1. systemctl restart httpd

配置篇

一、Apache配置

vi /etc/httpd/conf/ #编辑文件

ServerSignature On #添加,在错误页中显示Apache的版本,Off为不显示

Options Indexes FollowSymLinks #修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)

#AddHandler cgi-script .cgi #修改为:AddHandler cgi-script .cgi .pl (允许扩展名为.pl的CGI脚本运行)

AllowOverride None #修改为:AllowOverride All (允许.htaccess)

AddDefaultCharset UTF-8 #修改为:AddDefaultCharset GB2312 (添加GB2312为默认编码)

#Options Indexes FollowSymLinks #修改为 Options FollowSymLinks(不在浏览器上显示树状目录结构)

DirectoryIndex #修改为:DirectoryIndex

(设置默认首页文件,增加)

MaxKeepAliveRequests 500 #添加MaxKeepAliveRequests 500 (增加同时连接数)

:wq! #保存退出

systemctl restart e #重启apache

rm -f /etc/httpd/conf.d/ /var/www/error/ #删除默认测试页

二、php配置

vi /etc/ #编辑

ne = #把前面的分号去掉,改为ne = PRC

disable_functions =

passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,

posix_getegid,posix_geteuid,posix_getgid,

posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit,

posix_getsid,posix_getuid,posix_isatty,

posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,

posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

expose_php = Off #禁止显示php版本的信息

short_open_tag = ON #支持php短标签

open_basedir = .:/tmp/ #设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题(例如:织梦内容管理系统),可以注销此行,或者直接写上程序的目录/data//:/tmp/

:wq! #保存退出

systemctl restart e #重启MariaDB

systemctl restart e #重启apache


本文标签: 目录 安装 文件