Php5.6 + apache2.4 + build a php environment in linux

Source: Internet
Author: User
Preface recently I suddenly wanted to build my blog. Although I am good at java-web, I chose phpmysql to build my blog for various reasons. For php, I only heard about it, but never learned it. So I will record the entire process from the establishment of the php environment, to the leasing of servers and domain names, and the selection of the php blog template. Plan to learn

Preface recently I suddenly wanted to build my blog. Although I am good at java-web, I chose phpmysql to build my blog for various reasons. For php, I only heard about it, but never learned it. So I will record the entire process from the establishment of the php environment, to the leasing of servers and domain names, and the selection of the php blog template. Plan to learn

Preface

Recently I suddenly wanted to build my blog. Although I am good at java-web, I chose popular php + mysql to build my blog for various reasons. For php, I only heard about it, but never learned it. So I will record the entire process from the establishment of the php environment, to the leasing of servers and domain names, and the selection of the php blog template. We plan to spend one month learning php, and it takes one month to lease servers and search for blog templates. Now let's start with setting up the php environment. Note: This is a tutorial on a linux server. centos6.4 installed on a virtual machine has been tested successfully. For windows, I am stuck in the loading module ....

Building a php environment involves three steps:

Install the apache (2.4) server:

Before installing apache, you need to install the APR, APR-Util, and PCRE dependency packages, because apache depends on them. The details are as follows:

APR and APR-Util: http://apr.apache.org/download.cgi

PC: http://sourceforge.net/projects/pcre/files/pcre

Apache:

Http://httpd.apache.org/download.cgi

The example of this document is apache(httpd-2.4.10.tar.gz), apr(apr-1.5.1.tar.gz), apr-util(apr-util-1.5.4.tar.gz), and pcre(pcre-8.36.tar.gz ).

After the download is complete, it is installed. (You need to create the relevant directory)

1. apr installation:

Decompress: run the command in the apr file path (the downloaded file has been saved to the apr directory)

Tar-zxvf apr-1.5.1.tar.gz, the file is decompressed to the current path

Create a soft link and install it:

(1) ln-s/opt/apr/usr/local/apr

(2) cd apr-1.5.1

(3)./configure -- prefix =/usr/local/apr (prefix is used to set the installation directory, and there is a space before configure. Note that)

(4) make

(5) make install

2. Installation of apr-util:

Decompress: run the command in the apr-util file path (the downloaded file has been mv to the apr-util directory)

Tar-zxvf apr-util-1.5.4.tar.gz, the file is decompressed to the current path

Create a soft link and install it:

(1) ln-s/opt/apr-util/usr/local/apr-util

(2) cd apr-util-1.5.4

(3)./configure -- prefix =/usr/local/apr-util (prefix is set to the installation directory)

(4) make

(5) make install

3. Install pcre:

Decompress: run the command in the pcre file path (the downloaded file has been mv to the pcre directory)

Tar-zxvf pcre-8.36.tar.gz, the file is decompressed to the current path

Create a soft link and install it:

(1) ln-s/opt/apr/pcre/usr/local/pcre

(2) cd pcre-8.3.6

(3)./configure -- prefix =/usr/local/pcre (prefix is set to the installation directory)

(4) make

(5) make install

  

4. The last step is to install apache:

Decompress: run the command in the apache file path (the downloaded file has been saved to the apache directory)

Tar-zxvf httpd-2.4.10.tar.gz, the file is decompressed to the current path

Create a soft link and install it:

(1) ln-s/opt/apr/apache/usr/local/apache

(2) cd httpd-2.4.10

(3)./configure -- prefix =/usr/local/apache2.4

-- Enable-so-rewrite = shared

-- With-mpm = prefork

-- With-apr =/usr/local/apr (Path: apr installation path, the same below)

-- With-apr-util =/usr/local/apr-util

-- With-pcre =/usr/local/pcre

Help

(4) make

(5) make install

So far, apache has been installed, and the next step is to start and test whether it has been started successfully.

Run the following command:

/Usr/local/apache2.4/bin/apachectl start

Check whether an apache process exists.

Ps aux | grep httpd

The result is as follows:

  

If a process exists, you can enter http: // localhost. The result of the author is

  

Because it is deployed on a virtual machine, the ip address of the virtual machine is used for access.

If you can see "It works! ", It does work!

For future convenience, you can add it to the service and copy apachectl to/etc/init. d/httpd.

Service httpd start

You can start the service directly.

Install php

Before installing php, make sure libxml2 is installed:

Http://download.chinaunix.net/download.php? Id = 28497 & ResourceID = 6095

I was casual Baidu at the time, not official. If you need official services, please make full use of your search capabilities.

The installation is basically the same as above. Just list the commands.

(1) tar-zxvf libxml2-2.7.4.tar.gz

(2) cd libxml2-2.7.4

(3)./configure -- prefix =/usr/local/libxml2

(4) make

(5) make install

In this way, libxml2 is installed.

The next step is to install php.

Official Website:

Http://php.net/downloads.php

Then install

After you copy the file to/opt/php

Decompress:

Tar-zxvf php-5.6.3.tar.gz

Then:

Cd php-5.6.3

Install:

./Configure

-- Prefix =/usr/local/php (path: Path to which php needs to be installed)

-- With-mysql =/usr/local/mysql (path: the installation path of the installed mysql)

-- With-apxs2 =/usr/local/apache2.4/bin/apxs (in some tutorials, it is -- with-apxs, here it is apxs2, 2 is set in version 2 or above)

-- With-libxml2 =/usr/local/libxml2 (that is the path to libxm2 installed above)

Then make and make install.

  

Finally, configure apache to support php.

Modify the configuration file httpd. conf of apache

Vim/usr/local/apache2.4/conf/httpd. conf

Then add at the end of the text

LoadModule php5_module modules/libphp5.so (Note: In the apache installation directory, there is libphp5.so under modules. This is added during php installation. If not, you need to reinstall php)

AddType application/x-httpd-php. php (there is a space before)

(Note: If the above one is not configured, it will lead to direct download when accessing http: localhost/*. php, instead of opening it)

Configuration by the author

  

Next, copy the php Startup File.

Php-5.6.3/php. ini-development/usr/local/php/lib/php. ini

Save and restart

Service httpd start

If no error is reported, the startup is successful.

  

Test whether php is successfully installed.

Write a simple php page, as shown below:

  

Isn't it easy, and then save it as welcome. php, the file needs to be placed in the apache htdocs directory

Enter http: // localhost/welcome. php In the browser

If the following page is displayed, the installation is successful.

  

  

Summary:

When building a php environment, you can refer to several more tutorials. The versions and other factors of each tutorial may be different, so it is not necessarily suitable for everyone. This is also the author's experience. I have referenced many tutorials. The reason for writing this tutorial is that many tutorials are not comprehensive, so I hope to give some help to the coder who is learning php based on my experience. If you encounter any problems during installation, leave a message for me. I will try my best to help you.

Http://www.cnblogs.com/junyuhuang/p/4103980.html

According to this method, the test is successful.

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.