search
HomeBackend DevelopmentPHP Tutorial那些年一起学习的PHP(一)_php基础

自从1994年PHP语言的创建,神奇般的被追捧为网站设计的首选语言。2000年PHP4.0的发布无疑为其注入新鲜的生命血液,更因其开源的胸怀受人尊敬。编程语言的学习入门无非是学习语法和基础的应用实例。这段时间我会一点一点地记录PHP的过程,一来是对自己的总结,二来为后续遇到同样问题的学习者解惑。

  笔记记录主要通过问题的方式出现,不会像书本上课似的,一点一点地探求语言的基础。主要是在PHP学习的基础阶段预见到问题一一解决记录,记录从不懂出去的过程。好了真正的PHP语言正是开始。

  1):PHP需要什么样的开发环境,开发工具?

  关于PHP语言的版本问题,了解是必须的,但我以为没太大的关系,百度/google就可以找到这些开发的版本问题。工欲善其事,必选利其器!首先第一次就是配置开发环境,我初次接触的开发环境是windows,但是这次我愿意在linux上进行后续的学习。现在我将两种开发环境的部署都会展示一次。

  2):windows安装步骤怎样?需要注意哪些方面?  

首先是windows,一般为了方便在windows 上都会选择安装工具套件实现,在这里我使用的是WampServer开发,Wamp就是Windows Apache Mysql PHP集成安装环境,即在window下的apache、php和mysql的服务器软件。简单的一键安装部署服务器,数据库等等不用考虑太多。直接下一步下一步就可以进行下去。不过安装过程中请注意有以下几点:

1、WampServer程序所在路径不能含有汉字和空格。

2、MySQL默认用户名:root,密码为空

3、MySQL数据库文件存放目录:wamp\bin\mysql\mysql5.5.8\data

4、网站根目录[HTML,PHP]wamp\www

5、访问本机请用http://127.0.0.1/ (如果80端口未被占用)

6、非默认端口,网址为http://127.0.0.1:端口/

如果安装了IIS服务器,端口80是被默认占用的,需要改wamp服务上网端口号码:C:\wamp\bin\apache\Apache2.2.17\conf文件夹下有文件httpd.conf的Listen节点,修改端口号80,或者你所需要的。修改后重启所有服务,运行即可。

开发工具:PHP开发工具:Zend Stodio ,PHPedit , EditPlus 2 ,easyeclipse ,DW 等都可以完成。继承的开发工具选择Zend比较好用。

  3):linux环境下也是安装包部署环境的吗?是否有图形管理界面? 

 然而在linux上我们依旧可以做开发PHP,这里我选择的开发环境是LAMP(linux+Apache+Mysql+PHP),以Ubuntu发行版本为例子安装开发环境。Apache官网卡可以下载离线安装包,亦可以在线安装。这里选择在线安装比较方便。首先使用Ubuntu系统,进入窗口命令(Ctrl+Alt+t)

    Apache的安装
Apache作为一个功能强大的Web程序,自然是架建Web服务器的首选,好了,下面我们就来安装Apache。在终端下输入下在面命令:
sudo apt-get install apache2
安装完毕后,接下来就要启动Apache了
sudo /etc/init.d/apache2 restart
在浏览器里输入http://localhost或者是http://127.0.0.1,如果看到了“It works!“,那就说明Apache就成功的安装了,Apache的默认安装,会在/var下建立一个名为www的目录,这个就是Web目录了,所有要能过浏览器访问的Web文件都要放到这个目录里。
PHP的安装
在Ubuntu下安装软件是一件非常简单的事,只需要一个命令就可以了,在终端下执行下面的命令:
sudo apt-get install libapache2-mod-php5 php5
安装完后,我们要重新启动Apache,让它加载PHP模块:
sudo /etc/init.d/apache2 restart
接下来,我们就在Web目录下面新建一个PHP文件来测试PHP是否能正常的运行,命令:
sudo gedit /var/www/phpinfo.php
然后输入:
(注意:使用时将bloginfo换成phpinfo,因为服务器的限制,不能使用phpinfo函数)
接着保存文件,在浏览器里输入http://127.0.0.1/phpinfo.php, 如果出现了一个显示PHP运行参数的页面,那就说明 PHP已经正常运行了。

但是如果没有显示出页面,而是提示你下载文件,这就说明Apaceh没有正确加载PHP模块,这时解决的方法是,在/etc /apache2/apache2.conf 或 /etc/apache2/mods-enabled/php5.conf文件里加入下面的一行命令:
AddType application/x-httpd-php .php .phtml .php3
在加入上面的命令后,再通过下面的命令应重启Apaceh该就能解决问题了:
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 restart

后有一种情况没有出现这个期望的页面,那有可能是文件夹www没有获得合适的访问权限,可以通过 sudo chmod +x ./www 改变www文件夹的权限。(熟悉linux的这个权限管理应该懂的)
     MySQL的安装
sudo apt-get install mysql-server
在安装的最后,它会要求里输入root的密码,注意,这里的root密码可不是Ubuntu的root密码啊,是你要给MySQL设定的root密码,当 然,如果你乐意的话,你设成一样也是可以的。因为主要是用作本地测试有的,所以到这里MySQL也就安装完成了,如果真的是要用作服务器的话,那可能还要 去参考一下其它的设置,至于这些设置,后续使用到我会写下的。

好了,开发环境安装就此结束,等待编写符合规则的程序吧!

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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software