search
HomeBackend DevelopmentPHP Tutorial【php】本土开发环境的部署与helloworld

【php】本地开发环境的部署与helloworld

搭建php的开发环境其实难度与jsp相当,mysql数据库、apache服务器,等一系列的繁琐操纵,

不过针对php,网络上有一些很好的整合组件,让php初学者能够迅速上手,

而且不止一个,easyphp等许许多多,下面推荐使用phpnow,一键安装,


一、php本地开发环境的搭建与部署


首先在phpnow的官网上(点击打开链接)下载phpnow1.5.6,虽然官网上有点广告,但是可谓是良心之作,

把下载之后的phpnow-1.5.6.zip解压缩到你喜欢的文件夹,这个目录一定要选好,以后的php服务器,开发程序都在这里扎根,不能乱移动了


得到如下所示的文件:


点击setup.cmd开始安装,

开始会询问apache版本与mysql版本,其实没有什么大的区别,分别输入20与50,默认推荐版本安装就可以


之后会出现一系列的文件解压过程,等待文件解压完毕,

会要求用户初始化php,直接输入y按回车就可以


之后,如果你的80端口与3306段端口已经被使用,设置完mysql密码则可以退出安装了,phpnow安装完毕之后,会自动帮你创建test数据库。

如果你的80端口与3306段端口已经被使用,就像笔者的机器上如果这两个端口上已经拉着其他开发程序就会提示需要你改端口的询问信息:


http端口改掉是没有任何问题的,输入一个你喜欢的数字,比如笔者喜欢7777,就输入7777,以后调试php页面在网址之后拉上这个端口号即可

mysql的端口号就不要改了,笔者进行过实验,改完之后是有问题的,机器上最好没有mysql,如果机器上已经有mysql可以采取如下的办法:

先把自己mysql上的数据库备份成.sql文件,之后,随便给一个端口号给phpnow要安装的mysql,之后按回车,继续进行安装,输入完密码结束安装

打开phpnow根目录下的pncmds中的stop.cmd(路径如:D:\Program Files\php\PnCmds\stop.cmd)与绝对强制卸载.cmd,把php卸载,重启一下电脑,再重复上面的步骤,重新安装phpnow,再把原来mysql的数据库还原,那么就没有任何问题了,只是你的mysql数据库版本降级为5.0而已,暂时没有看出有什么影响,反正笔者原来javaweb工程挂在mysql的数据库经过这样之后还能正常使用,

不过还是推荐尽可能在不同机器上或者使用不同的虚拟机开发php与jsp……


二、测试搭建与部署是否成功


1.直接在任意浏览器输入:http://localhost:7777/index.php,刚才没有提示端口冲突的,去掉:7777直接http://loclhost/index.php即可,下同,

并于MySQL 用户密码一栏输入刚才你设置的mysql密码,则显示如下信息:


由于笔者改过php的apache端口与强行让php与jsp同时使用同一端口的数据库,所以可能导致eAccelerator失效,

不过不管它了,因为eAccelerator只是一个无关大局的使php代码执行起来更有效的加速器而已


2.再在浏览器地址烂输入:http://localhost:7777/phpmyadmin/index.php输入mysql的用户名,一般是root,与密码,就是你刚才设置的mysql密码点执行,得到如下的php数据库图形化管理画面,则表示php的数据库配置成功,点一下退出,就终于可以愉快地开发php了!



三、php的helloworld


php用什么写?有人推荐phpdesigner等工具

其实,这并不是必须的,

想vbscript,asp使用记事本与dreamweaver写同样是没问题的,把写好的页面扔在php的htdocs目录下就可以了,如:D:\Program Files\php\htdocs\index.php,其实这个index.php,就是你刚才看到的http://localhost:7777/index.php

笔者是如下用dreamweaver配置php的开发环境的,

以adobe dreamweaver cs5为例,dreamweaver 8就不要用了,不支持asp,php,javascript等动态代码高亮

先在htdocs下新建一个myphp文件夹,以后myphp就是我的工程名,你改成其他也可以

在dw中新建一个站点,然后,指定站点目录就是这里,站点名称随意,反正站点名称只是站点在dw的化名而已


直接点“保存”

之后在dw中输入如下代码,其实最关键是之间的部分

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title><?phpecho "hello world";?>

ctrl+S保存之后,在浏览器输入http://localhost:7777/myphp/helloworld.php则显示:


这就是我们php的第一步!


四、asp.net,jsp,php的对比


其实镶嵌动态代码与网页之后的asp变成拖控件的asp.net之后,php重新撑起动态代码镶嵌与网页中的大旗~jsp则依旧独树一帜地通过ssh或者servlet把所有动态代码镶嵌在java文件内,

这种把动态代码镶嵌于网页中的方式,有人说会导致代码不好维护,个人反而其实这样更好维护,毕竟所有代码都在一个文件内,不用到处翻,关键是要求程序猿读通读透每一段代码是干什么。

同时基于动态代码镶嵌于网页中的方式,除去大家都需要的数据库,php的开发仅仅一个简单的服务器即可,甚至使用windows自带的iis去作为php也可以完全没有问题,不过由于网上已经有大量的php整合软件,所以用户则可以更加轻松地一键安装。

php因此鉴于asp.net需要用到iis,visual studio,sql server,jsp需要用到eclipse/myeclipse(不用的话,写java程序实在是太麻烦了,尤其你用到ssh等框架的时候,web.xml会写死人!)与tomcat更加轻便,仅仅需要一个过时的dreamweaver甚至记事本书写就可以,根本就不会出现低配置电脑运行visual studio与eclipse/myeclipse卡爆的问题,同时与jsp一样比起asp.net的前端维护更加简单。



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP: The Foundation of Many WebsitesPHP: The Foundation of Many WebsitesApr 13, 2025 am 12:07 AM

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

Beyond the Hype: Assessing PHP's Role TodayBeyond the Hype: Assessing PHP's Role TodayApr 12, 2025 am 12:17 AM

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

What are Weak References in PHP and when are they useful?What are Weak References in PHP and when are they useful?Apr 12, 2025 am 12:13 AM

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

Explain the __invoke magic method in PHP.Explain the __invoke magic method in PHP.Apr 12, 2025 am 12:07 AM

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.