欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

安装php的问题

程序员文章站 2022-05-29 08:19:05
...

安装php的时候报错:

[email protected]-HP-ProDesk-600-G3-SFF:~$ sudo apt-get install php5
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package php5 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'php5' has no installation candidate

查阅相关资料,找到知乎大神的解决方案,记录下来
先看了下我电脑之前是否安装:
whereis php
结果有一个php安装
看下版本:
php -v
是php7
先删除:

 sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`

sudo apt-get install -y language-pack-en-base
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
apt-cache search php5
sudo apt-get install php5.5-common
sudo apt-get install libapache2-mod-php5.5

上面是大神的方法,关键在于apt-cache search命令
搜索你需要的安装包,比如这里我找到的没有5.5的版本,都是5.6以上,所以我选择了
sudo apt-get install php5.6-common
sudo apt-get install libapache2-mod-php5.6

bingo:

[email protected]-HP-ProDesk-600-G3-SFF:/$ php -v
PHP 5.6.40-38+ubuntu16.04.1+deb.sury.org+1 (cli) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

下面配置apache,masql,php,
命令前面加sudo执行

apt install -y mysql-server mysql-client
apt-get install libapache2-mod-php7.0
apt-get install php7.0-mysql
dpkg-reconfigure php7.0-mysql
apt-get install php7.0-xml
apt-get install php7.0-gd
apt-get install phpmyadmin
在安装过程中会要求选择Web server:apache2或lighttpd,使用空格键选定apache2,然后确定,下面界面输入你刚才安装Mysql时设置的密码,确定。再确认一次Mysql密码,确定。
然后将phpmyadmin与apache2建立连接,
sudo ln -s /usr/share/phpmyadmin /var/www/html
重启apache2
sudo /etc/init.d/apache2 restart

其他
重启mysql
/etc/init.d/mysql restart

运行下面代码:

<?php


echo "<h2>PHP 很有趣!</h2>";
echo "Hello world!<br>";
echo "我要学 PHP!<br>";
echo "这是一个", "字符串,", "使用了", "多个", "参数。";
$q = isset($_GET["q"]) ? intval($_GET["q"]) : '';
 
if(empty($q)) {
    echo '请选择一个网站';
    // exit;
}
 
$con = mysqli_connect('127.0.0.1:3306','root','123456');
if (!$con)
{
    die('Could not connect: ' . mysqli_error($con));
}
// 选择数据库
mysqli_select_db($con,"analysis_test");
// 设置编码,防止中文乱码
mysqli_set_charset($con, "utf8");
 
$sql="SELECT * FROM Websites WHERE id = '".$q."'";
 
$result = mysqli_query($con,$sql);
 
echo "<table border='1'>
<tr>
<th>ID</th>
<th>网站名</th>
<th>网站 URL</th>
<th>Alexa 排名</th>
<th>国家</th>
</tr>";
 
while($row = mysqli_fetch_array($result))
{
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['url'] . "</td>";
    echo "<td>" . $row['alexa'] . "</td>";
    echo "<td>" . $row['country'] . "</td>";
    echo "</tr>";
}
echo "</table>";
 
mysqli_close($con);
?>

运行结果:

<h2>PHP 很有趣!</h2>Hello world!<br>我要学 PHP!<br>这是一个字符串,使用了多个参数。请选择一个网站<table border='1'>
<tr>
<th>ID</th>
<th>网站名</th>
<th>网站 URL</th>
<th>Alexa 排名</th>
<th>国家</th>
</tr>PHP Warning:  mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/hp/Mygo/src/mqtt/html/newp.php on line 38

mysql哪里语句还有问题,明天排查…

本文参考链接:
https://www.cnblogs.com/xiede/p/8999419.html
https://blog.csdn.net/tdbtx_j/article/details/79464535

相关标签: php