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

AI Hentai Generator
Generate AI Hentai for free.

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

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov
