: This article describes how to build a PHP environment in Ubuntu. For more information about PHP tutorials, see. My server environment is Ubuntu 14.04 64-bit
Install Apache2:
Sudo apt-get install apache2
Install the PHP module:
Sudo apt-get install php5
Install Mysql
Sudo apt-get install mysql-server
Install other modules:
Sudo apt-get install libapache2-mod-php5
Sudo apt-get install libapache2-mod-auth-mysql
Sudo apt-get install php5-mysql
Sudo apt-get install php5-gd
The first two are easy to understand. to use apache to parse PHP, you need to use these two modules to find the php engine.
Third, it is used in php operations on mysql databases. most people have database programming experience, so there is no need to explain this.
The fourth GD database.
Apache2 configuration:
After the above modules are installed, the basic configuration is actually OK, but it is just a few small details.
Basically, most of the configurations are completed in the/etc/apache2 directory and its subdirectories. Therefore, you must clarify the directory structure.
1. apache root directory
After apache2 is installed, the root directory is under/var/www. you can use http: // localhost/to test whether it is easy to use.
You can also create a new file test.html in the directory to try http: // localhost/test.html.
2. PHP parsing problems
After the installation, it seems that php parsing is a bit problematic. browsing the php web page will save it, and apache does not parse it as a web page.
Generally, you need to add XXXX to httpd. conf. This may be true for other linux systems, but Ubuntu is a little special.
The apache2 configuration of Ubuntu is in the/etc/apache2 directory.
This directory contains an apache2.conf file that contains all the apache2 system configuration information.
Php parsing is configured in php5.conf and php5.load under/etc/apache2/mod-available. the apache2.conf file does not include these two files, as long as it is included, it is OK.
**************************************** *********
In apache2.conf, find
# Include module configuration:
Include/etc/apache2/mod-enabled/*. load
Include/etc/apache2/mod-enabled/*. conf
Add
Include/etc/apache2/mod-available/php5.load
Include/etc/apache2/mod-available/php5.conf
**************************************** *********
Another way is to link the two files to the Directory of the "mod-enabled" Directory:
Sudo ln-s/etc/apache2/mod-available/php5.load/etc/apache2/mod-enabled/php5.load
Sudo ln-s/etc/apache2/mod-available/php5.conf/etc/apache2/mod-enabled/php5.conf
This method is better, without damaging the configuration structure of apache2 itself.
**************************************** *********
3. change the default directory of apache2 to the current development directory.
The default directory of apache2 is configured in the/etc/apache2/sites-enabled/000-default file.
Find the DocumentRoot item in the file and change/var/www to your development directory.
Of course, another way is to create a link to your directory under var/www.
For example, if your Directory is in/home/username/phptest
Sudo ln-s/home/username/phptest/var/www/phptest
In this way, you can access your working directory through http: // localhost/phptest.
[Note] The link file name cannot contain ".". otherwise, apache2 treats it as a file and tries to parse it, which cannot achieve the effect of the link directory.
I personally recommend using the latter method, so that multiple working directories can be developed in parallel.
Restart apache
Sudo/etc/init. d/apache2 restart
Or
Service apache2 restart
In a simple test, create a new PHP file in the phptest Directory: test. php
PHP Site
Echo "Hello, This is my first PHP webpage \ n ";
Phpinfo ();
?>
Save and exit.
Press ESC to jump to the command mode, and then:
: W save the file but do not exit vi;
: W file saves the changes to the file and does not exit vi;
: W! Force save, do not launch vi;
: Wq: Save the file and exit vi;
: Wq! Force save the file and exit vi;
Q: Exit vi without saving the file;
: Q! Do not save the file, force exit vi;
: E! Discard all modifications and start editing the last saved file;
Open your browser and enter localhost/phptest/test. php to view the PHP running result. Good Luck! :-)
The above section describes how to set up the PHP environment in Ubuntu, including some content, and hopes to help those who are interested in the PHP Tutorial.