centos搭建php环境
安装Apache
1.安装
yum -y install httpd
2.开启apache服务
systemctl start httpd.service
3.设置apache服务开机启动
systemctl enable httpd.service
CentOS7用的是Firewall-cmd,CentOS7之前用的是iptables防火墙;要想让外网能访问到apache主目录,就需要做以下的操作:
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
安装PHP
立即学习“PHP免费学习笔记(深入)”;
1.安装
yum -y install php
2.重启apache服务
systemctl restart httpd或者systemctl restart httpd.service
然后,你可以写一个php文件在浏览器中运行一下了;
eg:
vi /var/www/html/info.php
i
Esc
:wq
然后,在自己电脑浏览器输入 192.168.1.1/info.php
运行,会出现php的一些信息
安装MySQL
我这里根据所学的那个教程,也安装了MariaDB
1.安装
yum -y install mariadb-service mariadb
2.开启MySQL服务
systemctl start mariadb.service
3.设置开机启动MySQL服务
systemctl enable mariadb.service
4.设置root帐户的密码
mysql_secure_installation
然后会出现一串东西,可以仔细读一下,如果你懒得读,就在提示出来的时候,按Enter就好了,让你设置密码的时候,你就输入你想要的密码就行,然后继续在让你选择y/n是,Enter就好了;当一切结束的时候,你可以输入mysql -uroot -p的方式,验证一下;
将PHP和MySQL关联起来
yum search php,选择你需要的安装:yum -y install php-mysql
安装常用的PHP模块
例如,GD库,curl,mbstring,...
1.安装:
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
重启apache服务
systemctl restart httpd.service
以上就是centos php环境如何安装搭建的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号