Home Backend Development PHP Tutorial 那些年一起学习的PHP(一)_php基础

那些年一起学习的PHP(一)_php基础

May 17, 2016 am 09:12 AM
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 of this Website
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

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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles