Home  >  Article  >  Backend Development  >  Ubuntu builds PHP environment

Ubuntu builds PHP environment

WBOY
WBOYOriginal
2016-08-08 09:20:36900browse

My server environment is: Ubuntu 14.04 64-bit

Install Apache2:

sudo apt-get install apache2

Install PHP module:

sudo apt-get install php5

Install Mysql

sudo apt -get install mysql-server

Other module installation:

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. If you want apache to be able to parse PHP, you need to use these two modules to find the php engine.

The third one is used when PHP operates the mysql database. Most people have database programming experience, so there is no need to explain it.

The fourth GD library.


apache2 related configuration:

After installing the above modules, the basic configuration is actually OK, except for some small details.

Basically, most configurations are completed in the /etc/apache2 directory and its subdirectories, so you must understand this directory structure.


1.apache root directory

After installing apache2, the root directory is under /var/www. You can test whether it works through http://localhost/.

Of course, you can also create a new file test.html in this directory to try http://localhost/test.html.


2. PHP parsing problem

After installation, it seems that there is a problem with php parsing. Browsing php web pages will save them, but apache does not parse them into web pages.

It is generally said on the Internet that XXXX needs to be added to httpd.conf. This may be true for other Linux systems, but Ubuntu is a bit special.

Ubuntu’s apache2 is configured in the /etc/apache2 directory.

There is a apache2.conf file in this directory. This file covers all apache2 system configuration information by including other configuration files.

The php parsing part is configured in php5.conf and php5.load under /etc/apache2/mods-available. These two files are not included in the apache2.conf file. As long as they are included, it will be OK. .

 ********************************************** ***

found in apache2.conf

  # Include module configuration:

 Include /etc/apache2/mods-enabled/*.load

 Include /etc/apache2/mods -enabled/*.conf

Add

after it

 ****************************************************** *

Another method is to link these two files to the mods-enabled directory:

  sudo ln -s /etc/apache2/mods-available/php5.load /etc/apache2/mods- enabled/php5.load

sudo ln -s /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php5.conf

This way is better, no Destroy 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, change /var/www to your development directory and it will be OK.

Of course, there is another way that is not to use the default directory, but just create a link to your directory under var/www.

For example, if your directory is in /home/username/phptest, then you only need to

  sudo ln -s /home/username/phptest /var/www/phptest

This way you can access your working directory through http://localhost/phptest.

[Note] The link file name cannot contain ".", otherwise apache2 will try to parse it as a file and cannot achieve the effect of the link directory.

I personally recommend 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


Let’s take a simple test , create a new PHP file in the phptest directory: test.php




PHP Site




echo "Hello, This is my first PHP webpagen";
phpinfo();
?>

< ;/p>

Save and exit.

Press the ESC key to jump to the command mode, then:
:w Save the file without exiting vi;
:w file Save the modifications to file without exiting vi;
:w! Force save without exiting vi ;
:wq Save the file and exit vi;
:wq! Force save the file and exit vi;
q: Exit vi without saving the file;
:q! Force exit vi without saving the file;
:e! Give up everything Modify, start editing from the last time you saved the file;

Open the browser, enter: localhost/phptest/test.php, you can see the running results of our PHP. Good Luck! :-)

The above introduces how to build a PHP environment in Ubuntu, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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
Previous article:monkey counting problemNext article:monkey counting problem