Home Backend Development PHP Tutorial PHP入门-安装配置小结

PHP入门-安装配置小结

Jun 23, 2016 pm 01:38 PM

本文借鉴自各路大神以及.通过了自己的验证为切实可行.故记录于此.

本文环境为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 ();?>
Copy after login

然后在浏览器地址栏输入localhost/test.php.弹出如下界面,即为成功.

还可以验证一下php能否和mysql正常合作.在html目录下创建mysql.php.加入如下代码:

<?php $link = mysql_connect("localhost", "root", "w122122");if (!$link)    echo "failed";else    echo "success";mysql_close();?>
Copy after login
这段代码,即使没有学过php,应该也能够看懂.结果如果输出success那就代表能够链接mysql.

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';?>
Copy after login
放在地址栏里面试试啥效果.为啥?查阅了一下资料,原来是因为,没有在apache2中添加对php的支持.可能有的同学疑惑,明明上面支持啊.我想可能只是对内嵌不支持吧.whatever.

添加一下支持吧那就.但是网上说要在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';?>
Copy after login
再次运行编码就正常了.

以上就是这几天对PHP的一些总结,基本上没有涉及到PHP的太多内容,都是配置相关的.不过完事开头难,记下来,回头省的在走弯路.




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

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

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

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

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-

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

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

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

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' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

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.

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

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

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

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

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

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

See all articles