CentOS 7.0服务器PHP环境搭建

2024-10-13 10:00:20

1、CentOS 7默认使用的是Firewall作为防火墙,将其改为iptables防火墙关闭firewall服务命令:systemctl stop firewalld.service禁止firewall开机启动命令:systemctl disable firewalld.service

CentOS 7.0服务器PHP环境搭建

2、安装iptables防火墙命令:yum install iptables-services

CentOS 7.0服务器PHP环境搭建

3、编辑防火墙配置文件命令:vim /etc/sysconfig/iptables岳蘖氽颐按i进入insert模式,添加如下内容幻腾寂埒-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT然后按ESC退出INSERT模式,输入:wq保存并退出

CentOS 7.0服务器PHP环境搭建

4、重启防火墙使配置生效命令:systemctl restart iptables.service设置防火墙开机启动命令:systemctl enable iptables.service

CentOS 7.0服务器PHP环境搭建

5、关闭SELINUX修改配置文件命令:vim /etc/selinux/config按i进入INSERT模式,将SELINUXTYPE=targeted #注释掉按ESC退出,输入:wq保存并退出注:若与截图不相同,可按以上要求修改配置文件

CentOS 7.0服务器PHP环境搭建CentOS 7.0服务器PHP环境搭建

6、使配置立即生效命令:setenforce 0截图说明,SELinux已完全关闭注:setenforce 1 设置SELinux 成为enforcing模式setenforce 0 设置SELinux 成为permissive模式

CentOS 7.0服务器PHP环境搭建

7、安装apache命令:yum install httpd可能会用到的命令:systemctl start httpd.service #启动apach髫潋啜缅esystemctl stop httpd.service #停止apachesystemctl restart httpd.service #重启apachesystemctl enable httpd.service #设置apache开机启动

CentOS 7.0服务器PHP环境搭建

8、重启Apache重启后,在浏览器输入域名或IP地址,若是本机可以输入localhost进行测试出现如下截图,说明已经安装成功。

CentOS 7.0服务器PHP环境搭建

9、设置Apache开机启动命令:systemctl enable httpd.service

CentOS 7.0服务器PHP环境搭建

10、安装数据库命令:yum install mariadb mariadb-server注:CentOS 7.0中,已经使用MariaDB替代了MySQL数据库可能会用到的命令:systemctl start mariadb.service #启动MariaDBsystemctl stop mariadb.service #停止MariaDBsystemctl restart mariadb.service #重启MariaDBsystemctl enable mariadb.service #设置开机启动

CentOS 7.0服务器PHP环境搭建

11、拷贝配置文件命令:cp /usr/share/mysql/my-huge.cnf /etc/my.cnf注:拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)

CentOS 7.0服务器PHP环境搭建

12、重启MariaDB命令:systemctl restart mariadb.service若出现以下情况,说明MariaDB未启动,可按CTRL+C退出,并启动数据库。

CentOS 7.0服务器PHP环境搭建

13、为root设置密码命令:mysql_secure_installation此处直接按回车即可(一开始没有密码,以后改密码则需要输入已设定的密码)然后会要求你输入两次密码,然后回车然后一路按Y加回车直到出现Thanks for using MariaDB

CentOS 7.0服务器PHP环境搭建

14、重启MariaDB,并设置为开机启动命令:systemctl restart mariadb.service命令:systemctl enable mariadb.service

15、安装PHP命令:yum install php

CentOS 7.0服务器PHP环境搭建

16、安装PHP组件,使PHP支持 MariaDB命令:yum install php-mysql php-gd libjpeg* php-ldap p茑霁酌绡hp-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

CentOS 7.0服务器PHP环境搭建

17、重启Apache以及MariaDB命令:systemctl restart mariadb.service命令:systemctl restart httpd.service

CentOS 7.0服务器PHP环境搭建

18、配置Apache编辑配置文件命令:vim /etc/httpd/conf/httpd.con酆璁冻嘌f按i进去insert模式按照以下要求修改配置文件:ServerSignature On #添加,在错误页中显示Apache的版本,Off为不显示AllowOverride None  #修改为:AllowOverride All (允许.htaccess)Options Indexes FollowSymLinks(部分可能为Options None) #修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)#AddHandler cgi-script .cgi #修改为:AddHandler cgi-script .cgi .pl (允许扩展名为.pl的CGI脚本运行)AddDefaultCharset UTF-8 #修改为:AddDefaultCharset GB2312 (添加GB2312为默认编码)DirectoryIndex index.html #修改为:DirectoryIndex index.html index.htm Default.html Default.htm index.php(设置默认首页文件,增加index.php)MaxKeepAliveRequests 50 #添加MaxKeepAliveRequests 50 (增加同时连接数)若有域名,可以在ServerName处把域名改为自己的域名最后按ESC退出insert模式,输入:wq保存并退出

CentOS 7.0服务器PHP环境搭建

19、重启Apache命令:systemctl restart httpd.service

20、删除默认测试首页(可忽略此步)命令:rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html

21、配置PHP编辑配置文件命令:vim /etc/php.ini按i进入insert模式按以下要榨施氅汝求进行修改date.timezone = 霸烹钟爷PRC #把前面的分号去掉,改为date.timezone = PRCdisable_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/www.osyunwei.com/:/tmp/按ESC退出insert模式,输入:wq退出并保存

22、重启Apache和MariaDB命令:systemctl restart mariadb.service命令:systemctl restart httpd.service

23、测试进入服务器的根目录(默认是var/www/html,可在配置文件中修改)命令:cd /var/www/html

24、创建index.php文件命令:vim index.php

25、写入以下内容按i进入insert模式输入以下内容:<?phpphpinfo();?>按ESC退出insert模式,输入:wq保存并退出

26、查看最后成果在浏览器输入服务器ip或域名,本机可输入localhost,出现如下图所示结果则为成功

CentOS 7.0服务器PHP环境搭建
猜你喜欢