一、官方主站:
https://www.php.net(PHP官方网站)参考:
https://www.centos.org/download/(CentOS下载地址)
二、PHP语言中文参考:
https://www.php.net/manual/zh/参考:
https://www.runoob.com/ (HTML参考手册)PHP入门
http://www.w3school.com.cn/index.html
三、CentOS安装PHP环境步骤:
0.有时候需要删除:yum.pid才能更新升级:
rm -f /var/run/yum.pid1.更新升级:
yum -y update2.安装必要的支持库(Apache会自动安装):
yum install gcc libcap libpcap libpcap-devel screen php dstat cmake gmp gmp-devel gengetopt byacc flex git json-c zmap iptraf nano3.验证安装:
yum groupinstall "Development Tools"4.安装ssh2扩展(安装支持的库文件):------------------------------------------------------------------------
yum install gcc php-devel php-pear libssh2 libssh2-develpecl install -f ssh2 //(建立ssh2扩展:之后会显示安装的日志,需要选择时直接按回车键就好)
touch /etc/php.d/ssh2.ini //(修改ssh2.ini)
echo extension=ssh2.so > /etc/php.d/ssh2.ini //(可以用vim打开/etc/php.d/ssh2.ini 确认是否已经包含extension=ssh2.so)
php -m | grep ssh2 //(验证是否安装成功:显示ssh2则表示安装成功)
5.关闭防火墙:
systemctl stop firewalld.service参考命令:
systemctl status firewalld.service //(查看状态)
6.设置允许httpd访问网络:
setsebool -P httpd_can_network_connect 1 //(允许反向代理)setsebool -P nis_enabled 1 //(关闭selinux)
getsebool -a | grep httpd_can_network_connect //(检查网络访问的配置:)
//(结果如下:httpd_can_network_connect --> on)
7.安装ssh(一般默认CentOS已经安装了OpenSSH,即使你是最小化安装也是如此。)
参考命令:
yum install openssh-server //(安装ssh)
systemctl start sshd.service //(启动ssh的服务)
systemctl enable sshd.service //(设置开机自动启动ssh服务)
rpm -qa | grep ssh //(检查是否安装ssh)
service sshd restart //重启SSH服务
service sshd start //启动服务
service sshd stop //停止服务
netstat -antp | grep sshd //查看是否启动22端口
8.重新启动web服务:
service httpd restart #重启参考命令:
systemctl start httpd.service #启动
systemctl stop httpd.service #停止
systemctl restart httpd.service #重启
第二、设置开机启动/关闭
systemctl enable httpd.service #开机启动
systemctl disable httpd.service #开机不启动
第三、检查httpd状态
systemctl status httpd.service
网站文件夹:
/var/www/html
然后把你的PHP文件上传到html文件夹里去浏览器中输入主机IP就可以了!
四、PHP中使用ssh2远程执行Linux命令代码:
<?php
ini_set("display_errors","On");
error_reporting(E_ALL);
if (!function_exists('ssh2_connect'))
{
die("Install ssh2 module.\n");
}
$conn = ssh2_connect('192.168.16.118',22);
if (!$conn) die('Connection failed');
if (!ssh2_auth_password($conn,'root','root'))
throw new Exception("Error with login credentials");
$stream=ssh2_exec($conn, "ls /");
stream_set_blocking($stream, true);
$output = stream_get_contents($stream);
fclose($stream);
echo $output ;
die('end.');
?>