如何为PHP应用程序制作安装程序?

3

我有一个PHP应用程序,想要为它创建一个安装程序。是否有现成的框架可以使用?有没有关于这种事情的好教程?


1
为什么需要制作安装程序?如果您创建普通网站,只需创建安装脚本即可。或者您正在使用PHP-GTK吗? - slier
你需要详细说明你的问题。是什么类型的安装程序?类似于WordPress的还是其他的? - thirtydot
我正在使用PHP制作通讯录,并且想要将它制作成桌面应用程序。 - Abhijeet
安装程序就像我们安装 VLC 一样。 - Abhijeet
@Abhijeet PHP不适用于桌面应用程序。它会带来比它值得的更多麻烦。再次强调,PHP不适用于桌面应用程序。 - Rafe Kettler
显示剩余2条评论
4个回答

2

1
为什么有人会想用PHP编写桌面应用程序,这完全让我无法理解。真的,为什么呢? - Rafe Kettler
也许是因为他们不知道更好的方法,也许是因为他们想将一个开源现有脚本移植到桌面应用程序中,或者只是纯粹的受虐狂 :) - Luis

1

创建PHP脚本安装系统

图片预览

在您的根目录(htdocs)中创建两个新文件夹(include和install)。 在include文件夹中创建新文件connect.phpDB_Info.php | 在代码编辑器中打开connect.php并写入@mysql_connection代码 | 始终使用connect.php文件包括/需要连接数据库的文件 |

<?php  // Always Include/Require This File For Connect Database
    require_once "DB_Info.php";  // this is connect.php file

    @mysqli_connect(
        $HOST_name,
        $DB_username,
        $DB_password
    ) or die(
        "<h2>Database Error, Contact With Admin </h2>"
    );

    @mysqli_select_db(
        $DB_name
    ) or die(
        "<h2>Database Error, Contact With Admin</h2>"
    );
?>

require_once DB_Info.php保持不变 | 您可以在connect.php中看到$HOST_name,$DB_username,$DB_password变量没有值 | 我们在DB_Info.php(需要文件)中通过表单动态提供值 | 现在将index.phpinstalling.phpinstalled.php三个文件创建到 install文件夹 中。首先,在index.php中创建表单->

<link rel='stylesheet' href='style.css' />

<?php  // create form
    $HOST_name = "<input class='input' type='text' name='dbhost' placeholder='Enter Host Name' />";
    $DB_username = "<input class='input' type='text' name='dbuser' placeholder='Enter DB User Name' />";
    $DB_password = "<input class='input' type='password' name='dbpass' placeholder='***********' />";
    $DB_name = "<input class='input' type='text' name='dbname' placeholder='Enter DB Name' />";
    echo "<div class='box' >
            <form class='ins' method='post' action='installing.php' >
                    <p>Enter Host Name:<p>
                    $HOST_name
                    <p>Enter DB User Name:<p>
                    $DB_username
                    <p>Enter DB PassWord:<p>
                    $DB_password
                    <p>Enter DB Name:<p>
                    $DB_name
                    <input class='submit' type='submit'name='install' value='NEXT' />
            </form>
        </div>";
?>

现在form action是installing.php,我们正在使用文件处理函数fwrite()将三个变量的值写入DB_Info.php(connect.php$HOST_name,$DB_username,$DB_password)

<link rel='stylesheet' href='style.css' />
<?php  
    $writer="<?php".'
    '.'$HOST_name = '."'".$_POST['dbhost']."'".';
    '.'$DB_name = '."'".$_POST['dbname']."'".';
    '.'$DB_username = '."'".$_POST['dbuser']."'".';
    '.'$DB_password = '."'".$_POST['dbpass']."'".';
    '."?>";

    $write=fopen('..\include/DB_Info.php' , 'w');
    if(empty($_POST['dbhost']&&
             $_POST['dbname']&&
             $_POST['dbuser']&&
             $_POST['dbpass'])){
                 echo"<h2 align=center >All Fields are required! Please Re-enter</h2>";

    }else{
        if(isset($_POST['install']))
        {
            fwrite($write,$writer);
            fclose($write);
            echo "<div class='box'>
                <form class='ins' action='installed.php' method='post'>
                    <h2 align=center color=red>Database Info Succecfully Entered<h2>
                    <input class='submit' type='submit' value='NEXT' name='next'/>
                </form>
                </div>";
        }else{ echo "<h2 align=center >Error<h2>"; }}
?>

最后一步,为了在phpmyadmin中创建表格,需要安装installed.php文件。

<?php
    if(isset($_POST['next'])){
        /*  enter your
         sql code for
         teble creating */
        echo"<h2 align=center >Finished</h2>";
    }else{
        echo"<h2 align=center >Error</h2>";
    }
?>

我们的CSS
* {
    margin: 0;
    padding: 0;
}

.box {
    position: absolute;
    width: 300px;
    top: 16%;
    left: 35%;
    background-color: rgb(0, 0, 0);
    padding: 15px;
    padding-top: auto;
}

.ins {
    margin: 0;
    padding: 0;
    font-weight: bold;
    color: lawngreen;
    font-size: 1rem;
}

.input {
    border: none;
    border-bottom: 2px solid lawngreen;
    margin-bottom: 20px;
    width: 100%;
    height: 40px;
    background: transparent;
    outline: none;
    color: cyan;
    font-size: 1rem;
}

.submit {
    background-color: lawngreen;
    width: 100%;
    height: 40px;
    font-size: 1.5rem;
    border: none;
    margin-top: 10px;
    outline: none;
    cursor: pointer;
    border-radius: 20px;
}

0

安装程序?

如果您正在安装PHP脚本/设置某些设置等,则是的。vBulletin和phpBB有一些很棒的“安装程序”——它们可以创建配置文件,而无需弄脏手。

但是,如果您说的是Windows/Linux/OS X等可执行安装程序,我认为您不能这样做。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接