Getting Started with PHP-installation configuration Summary

Source: Internet
Author: User
Tags getting started with php php tutorial

This paper draws on the respective road and the <21-day learning Tong Php>. Passed its own validation as practical. It is recorded here.

This article environment for Ubuntu 14.04

First of all, install. PHP is an abbreviation for hypertext preprocessor. is a scripting language. Often used in web development. Apache MySQL is required.

Run sudo apt-get install apache2 mysql-server php5 libapache2-mod-php5

After the installation, the PHP environment is almost a prototype.

The configuration file for Apache2 is apache2.conf. In the directory/etc/apache2 directory. It records what files are loaded when the apache2 is started. and some basic information.

A commonly used file is a conf file in the/sites-enabled directory. The purpose of this file is to specify the working path of the apache2.

The default is/var/www/html, which can be modified to other paths. (but I tried to change it, it didn't work.)

During the MySQL installation, you will be asked to configure some information, including the root password or something. I've already installed it.

Once the installation is complete, we can verify the success.

Open the browser and enter localhost. The following window is displayed as a success.

Verify that PHP is working.

In the HTML directory to create the php suffix file test.php, type the following code:

<?phpphpinfo ();? >

Then enter localhost/test.php in the browser address bar. The following interface is displayed, which is the success.

You can also verify that PHP is working properly with MySQL. Create a mysql.php in the HTML directory. Add the following code:

<?php$link = mysql_connect ("localhost", "root", "w122122"), if (! $link)    echo "failed"; else    echo "Success"; Mysql_close ();? >
This code, even if you have not learned PHP, should also be able to read. Results if the output success that means that you can link mysql.

Ok. The above is a simple installation and testing of PHP.

Next, as I went further, the problem arose. PHP is embedded in an HTML file. The method is not difficult. It is nothing more than to put the above code similar to the body of the HTML. This file is called php.html.

Put in the address bar to try what effect. Why? Look up the information, it is because, did not add support for PHP in the apache2. Maybe some classmates doubt, obviously above support ah. I think maybe it's just not supported on the inside. whatever.

Add support. But the internet says to add two words in httpd.conf:

AddHandler php5-script. php. html
AddType text/html. php. html

These two words are together, can not be less, otherwise still do not support. But the problem comes again. My system is Ubuntu, no httpd.conf. What do you do?

Turned an article, reference a bit, it turned out to be so. is to the article said, in fact, apache2 configuration file strictly meaning should be called apache2.conf. All other files must be allowed to be loaded by this file.

Then there are two solutions, the first directly into the apache2.conf file, the second to create a httpd.conf file, and then add a paragraph in the apache2.conf file, include httpd.conf can also.

I'm using the second method. The problem is solved. Students can try it on their own. I run the following results:

Well, the coding problem. There is a problem with the code above. How to solve it? It's OK to modify the HTML file. The modified file is as follows:

Running the code again is normal.

The above is a few days to the PHP summary, basically did not involve too much PHP content, are configuration-related. But the beginning of the difficult, write down, back to the province in the detours.




Getting Started with PHP-installation configuration Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.