PHP入门-安装配置小结
本文借鉴自各路大神以及.通过了自己的验证为切实可行.故记录于此.
本文环境为ubuntu 14.04
首先说下安装.PHP为超文本预处理器的缩写.是一种脚本语言.常用于web开发.故需要apache mysql .
运行sudo apt-get install apache2 mysql-server php5 libapache2-mod-php5
安装结束以后,PHP的环境就差不多有一个雏形了.
apache2的配置文件是apache2.conf.在目录/etc/apache2目录下.里面记录着apache2启动的时候加载哪些文件.以及一些基本信息.
比较常用的一个文件就是/sites-enabled目录下的一个conf文件.这个文件的作用是指定apache2的工作路径.
默认是/var/www/html ,可以修改成其它路径.(不过我试着修改了,没有效果.暂时还没有找到原因)
在mysql安装的过程中会要求你配置一些信息,包括root的密码什么的.我因为已经安装过了.就不截图了.
安装完成了以后,我们就可以验证一下是否成功了.
打开浏览器输入localhost即可.弹出如下窗口即为成功.
验证php是否能够工作.
在html目录创建php后缀文件test.php,键入如下代码:
<?phpphpinfo ();?>
然后在浏览器地址栏输入localhost/test.php.弹出如下界面,即为成功.
还可以验证一下php能否和mysql正常合作.在html目录下创建mysql.php.加入如下代码:
<?php $link = mysql_connect("localhost", "root", "w122122");if (!$link) echo "failed";else echo "success";mysql_close();?>
ok.上面是简单的对php的安装和测试.
接下来,当我进一步的进行学习的时候,问题出现了.我要吧php嵌入到html文件中.方法也不难.无非就是把上面那段代码类似的放到html的body体里面.这个文件叫php.html.
<title> this is test php echo </title><?phpecho "PHP教程.";print "PHP教程.";print("PHP教程");$a=5;echo "变量a的值是$a";print "变量a的值是$a";print ("变量a的值是$a");echo '变量a的值是$a';print '变量a的值是$a';?>
添加一下支持吧那就.但是网上说要在httpd.conf中添加两句话:
AddHandler php5-script .php .html
AddType text/html .php .html
这两句话是一起的,不能少,否则还是不支持.可是问题又来了.我的系统是ubuntu,没有httpd.conf.咋办啊?
转了一篇文章,参考了一下,原来是这么回事.正向那篇文章说的,其实apache2的配置文件严格意义的说应该叫apache2.conf.其它的文件都得经过这个文件的允许才能加载.
那么就有两个解决方案,第一直接放到apache2.conf文件中,第二创建一个httpd.conf文件,然后在apache2.conf文件中添加一段话Include httpd.conf也可以.
我用的是第二种办法.问题解决.同学们可以自己去试试.我的运行结果如下:
额.编码问题.上面的代码有问题.怎么解决呢?好办.修改一下html文件就行了.修改后的文件如下:
<title> this is test php echo </title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!-- 设置页面的编码 --><?phpecho "PHP教程.";print "PHP教程.";print("PHP教程");$a=5;echo "变量a的值是$a";print "变量a的值是$a";print ("变量a的值是$a");echo '变量a的值是$a';print '变量a的值是$a';?>
以上就是这几天对PHP的一些总结,基本上没有涉及到PHP的太多内容,都是配置相关的.不过完事开头难,记下来,回头省的在走弯路.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

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 is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

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.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

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.
