使用 Eclipse 在 Fedora 上进行 PHP 开发
PHP Eclipse
![](/data/attachment/album/202003/06/232441czseqnmy7ez2ssnn.png)


[Eclipse](https://projects.eclipse.org/projects/eclipse) 是由 Eclipse 基金会开发的功能全面的自由开源 IDE。它诞生于 2001 年。你可以在此 IDE 中编写各种程序，从 C/C++ 和 Java 到 PHP，乃至于 Python、HTML、JavaScript、Kotlin 等等。


### 安装


该软件可从 Fedora 的官方仓库中获得。要安装它，请用：



```
sudo dnf install eclipse
```

这将安装基本的 IDE 和 Eclipse 平台，能让你开发 Java 应用。为了将 PHP 开发支持添加到 IDE，请运行以下命令：



```
sudo dnf install eclipse-pdt
```

这将安装 PHP 开发工具，如 PHP 项目向导、PHP 服务器配置，composer 支持等。


### 功能


该 IDE 有许多使 PHP 开发更加容易的功能。例如，它有全面的项目向导（你可以在其中为新项目配置许多选项）。它还有如 composer 支持、调试支持、浏览器、终端等内置功能。


### 示例项目


现在已经安装了 IDE，让我们创建一个简单的 PHP 项目。进入 “File →New → Project”。在出现的对话框中，选择 “PHP project”。输入项目的名称。你可能还需要更改其他一些选项，例如更改项目的默认位置，启用 JavaScript 以及更改 PHP 版本。请看以下截图。


![Create A New PHP Project in Eclipse](/data/attachment/album/202003/06/232442s06c8hv6h3zz28cn.png)


你可以单击 “Finish” 按钮创建项目，或按 “Next” 配置其他选项，例如添加包含和构建路径。在大多数情况下，你无需更改这些设置。


创建项目后，右键单击项目文件夹，然后选择 “New→PHP File” 将新的 PHP 文件添加到项目。在本教程中，我将其命名为 `index.php`，这是每个 PHP 项目中公认的默认文件。


![add a new PHP file](/data/attachment/album/202003/06/232443djsh5nszqmqq9lc0.png)


接着在新文件中添加代码。


![Demo PHP code](/data/attachment/album/202003/06/232444g7tj7or4ey0oo07h.png)


在上面的例子中，我在同一页面上使用了 CSS、JavaScript 和 PHP 标记，主要是为了展示 IDE 能够支持所有这些标记。


页面完成后，你可以将文件移至 Web 服务器文档根目录或在项目目录中创建一个 PHP 开发服务器来查看输出。


借助 Eclipse 中的内置终端，我们可以直接在 IDE 中启动 PHP 开发服务器。只需单击工具栏上的终端图标，然后单击 “OK”。在新终端中，进入项目目录，然后运行以下命令：



```
php -S localhost:8080 -t . index.php
```

![Terminal output](/data/attachment/album/202003/06/232445qrbemsdmsarn88bb.png)


现在，打开浏览器并进入 <http://localhost:8080>。如果按照说明正确完成了所有操作，并且代码没有错误，那么你将在浏览器中看到 PHP 脚本的输出。


![PHP output in Fedora](/data/attachment/album/202003/06/232445ruuubsjbpbhu7bgh.png)




---


via: <https://fedoramagazine.org/php-development-on-fedora-with-eclipse/>


作者：[Mehdi Haghgoo](https://fedoramagazine.org/author/powergame/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
[Eclipse](https://projects.eclipse.org/projects/eclipse) is a full-featured free and open source IDE developed by the Eclipse Foundation. It has been around since 2001. You can write anything from C/C++ and Java to PHP, Python, HTML, JavaScript, Kotlin, and more in this IDE.

## Installation

The software is available from Fedora’s official repository. To install it, invoke:

sudo dnf install eclipse

This will install the base IDE and Eclipse platform, which enables you to develop Java applications. In order to add PHP development support to the IDE, run this command:

sudo dnf install eclipse-pdt

This will install PHP development tools like PHP project wizard, PHP server configurations, composer support, etc.

## Features

This IDE has many features that make PHP development easier. For example, it has a comprehensive project wizard (where you can configure many options for your new projects). It also has built-in features like composer support, debugging support, a browser,a terminal, and more.

## Sample project

Now that the IDE is installed, let’s create a simple PHP project. Go to *File →New → Project*. From the resulting dialog, select *PHP project*. Enter a name for your project. There are some other options you might want to change, like changing the project’s default location, enabling JavaScript, and changing PHP version. See the following screenshot.

![](https://fedoramagazine.org/wp-content/uploads/2020/02/Screenshot-from-2020-02-07-01-58-39.png)

You can click the *Finish* button to create the project or press *Next* to configure other options like adding include and build paths. You don’t need to change those in most cases.

Once the project is created, right click on the project folder and select *New → PHP File* to add a new PHP file to the project. For this tutorial I named it *index.php*, the conventionally-recognized default file in every PHP project.

![](https://fedoramagazine.org/wp-content/uploads/2020/02/Screenshot-from-2020-02-07-02-02-05-1024x576.png)

Then add the your code to the new file.

![](https://fedoramagazine.org/wp-content/uploads/2020/02/code-1024x916.png)

In the example above, I used CSS, JavaScript, and PHP tags on the same page mainly to show that the IDE is capable of supporting all of them together.

Once your page is ready, you can see the result output by moving the file to your web server document root or by creating a development PHP server in the project directory.

Thanks to the built-in terminal in Eclipse, we can launch a PHP development server right from within the IDE. Simply click the terminal icon on the toolbar () and click

*OK*. In the new terminal, change to the project directory and run the following command:

php -S localhost:8080 -t . index.php

![](https://fedoramagazine.org/wp-content/uploads/2020/02/terminal-1024x239.png)

Now, open a browser and head over to http://localhost:8080. If everything has been done correctly per instructions and your code is error-free, you will see the output of your PHP script in the browser.

![](https://fedoramagazine.org/wp-content/uploads/2020/02/output.png)

## Truls Gulbrandsen

Unfortunately eclipse seems to be broken:

[root@localhost ~]# dnf install eclipse –skip-broken

Last metadata expiration check: 0:50:05 ago on fr. 14. feb. 2020 kl. 10.33 +0100.

Dependencies resolved.

Problem: package eclipse-jdt-1:4.14-5.fc31.noarch requires eclipse-platform = 1:4.14-5.fc31, but none of the providers can be installed

– package eclipse-platform-1:4.14-5.fc31.x86_64 requires glassfish-el >= 3.0.1, but none of the providers can be installed

– cannot install the best candidate for the job

– package glassfish-el-3.0.1-0.12.b08.module_f31+6519+12cd0b27.noarch is filtered out by modular filtering

– package glassfish-el-3.0.1-0.12.b08.module_f31+6793+1c93c38e.noarch is filtered out by modular filtering

– package glassfish-el-3.0.1-0.11.b08.fc31.noarch is filtered out by modular filtering

Package Architecture Version Repository Size

Skipping packages with broken dependencies:

eclipse-jdt noarch 1:4.14-5.fc31 updates 31 M

eclipse-platform x86_64 1:4.14-5.fc31 updates 40 M

Transaction Summary

Skip 2 Packages

Nothing to do.

Complete!

## Alexander Borro

Download it from the eclipse website and install that way, that usually worked for me. While I do not use it any more eclipse installations have been broken/problematic since forever in Fedora as I recall. I wonder how the author just got it to work.

Also, it has proven to be a pain in any case braking with Java open SDK updates and third party dependencies. I was often fixing things manually with updates.

Today I would not recommend this IDE. I switched to vscode on Fedora a long time ago and everything “just works” once you know what you are doing. Pardon the NVidia ray-tracing quote 🙂

## Mehdi Haghgoo

I have had my problems with Eclipse, mostly in terms of its complexity and very intricate configurations, but I don’t remember seeing its packages broken, at least during the last 4-5 releases I can recall.

## Jeremie Barnes

I was able to install by doing “sudo dnf module enable eclipse:latest”

## Mark LaDoux

That should have been in the article. This fixed mine, I couldn’t install without enabling the module that the article fails to mention. Seeing as the module isn’t enabled by default, it should have been mentioned.

## pgar

true !

## qbl

Thanks, agree it should be in article

## Alexander Yurchenko

I prefer netbeans 😉

netbeans.apache.org

## Mehdi Haghgoo

There was a discussion in Fedora mailing lists to include NetBeans in Fedora. I hope that succeeds. I like NetBeans too.

## Raphael Groner

https://www.quora.com/How-does-PHP-in-the-context-of-Laravel-compare-with-Node-js-for-realtime-web-applications-in-terms-of-real-world-performance-and-development-experience

## Maciej

Yes you can do that, but first add another 32GB of RAM to your PC or you can just use VScode…

## Ben Knobi

… then let the language server consume the 32G of RAM with a few projects open.

## Fedora lover

No one gonna make development like that in 2020 with PHP

Why you make pointless articles about software development. But not making articles directly related with the OS.

## Gregory Bartholomew

“Fedora lover”:

Eclipse is used by millions of developers. Also, the Fedora Project is not

justabout creating an operating system. The Fedora Project’s main goal is actually to “advance free software“.## Bill Chatfield

I think people just like VSCode because it has a black theme. If they actually explored the functionality differences between VSCode and Eclipse, they would not bother with VSCode because it is just a toy compared to Eclipse.

## Kevin

Jetbrains best!