Home  >  Article  >  Backend Development  >  php5.6+apache2.4+linux builds php environment, php5.6apache2.4_PHP tutorial

php5.6+apache2.4+linux builds php environment, php5.6apache2.4_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:13:54845browse

php5.6+apache2.4+linux to build a php environment, php5.6apache2.4

Foreword

Recently I suddenly wanted to build a personal blog. Although the author is good at java-web, but for various reasons, I chose the popular php+mysql to build a personal blog. For PHP, I have only heard of its name, but have never learned it. Therefore, the author will record the entire process one by one, starting from the establishment of PHP environment, to the leasing of servers and domain names, and the selection of PHP blog templates. It is planned to take one month to learn PHP and one month to rent a server and find blog templates and other related final processes. Now let us start by setting up the php environment. Note that this is a tutorial on a linux server. The centos6.4 installed on the virtual machine has been successfully tested. As for windows, the author is stuck in the loading module part, alas. . . .

There are three main steps to build a php environment. The first step is

 Install apache (2.4) server :

Before installing apache, you need to install APR, APR-Util and PCRE dependency packages, because apache depends on them. The specific download address is as follows

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

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

The download address of apache is:

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

The specific versions I downloaded are apache(httpd-2.4.10.tar.gz), apr(apr-1.5.1.tar.gz), apr-util(apr-util-1.5.4 .tar.gz), pcre(pcre-8.36.tar.gz).

After downloading, install it (relevant directories need to be created by yourself)

 1.apr installation:

 Decompression: Execute in the apr file path (the downloaded file has been mv to the apr directory)

tar -zxvf apr-1.5.1.tar.gz, the file will be decompressed to the current path

Create soft link and install:

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

 (2) cd apr-1.5.1

 (3)./configure --prefix=/usr/local/apr (prefix is ​​to set the installation directory, and there is a space in front of configure, please pay attention)

 (4)make

 (5)make install

2.apr-util installation:

Decompression: Execute 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 will be decompressed to the current path

Create soft link and install:

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

 (2) cd apr-util-1.5.4

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

 (4)make

 (5)make install

3.pcre installation:

Decompression: Execute in the pcre file path (the downloaded file has been mv to the pcre directory)

tar -zxvf pcre-8.36.tar.gz, the file will be decompressed to the current path

Create soft link and install:

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

(2) cd pcre-8.3.6

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

 (4)make

 (5)make install

 

 4. The last step is to install apache:

Decompression: Execute in the apache file path (the downloaded file has been mv to the apache directory)

tar -zxvf httpd-2.4.10.tar.gz, the file will be decompressed to the current path

Create soft link and install:

 (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 (the path is the installation path of apr, the same below)

--with-apr-util=/usr/local/apr-util

--with-pcre=/usr/local/pcre

Please help

for the specific meaning of the installation parameters.

 (4) make

 (5) make install

At this point, apache has been installed. The next step is to start and test whether it started successfully

Execute command:

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

Check if there is an apache process

ps aux | grep httpd

The following is the result of the author executing the command

 

If there is a process, you can enter http://localhost. The author’s result is

 

Since it is deployed in a virtual machine, it is accessed using the IP address of the virtual machine.

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

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

Service httpd start

You can start the service directly

 Install php

Before installing php, you need to make sure that libxml2 has been installed. The download address is:

 http://download.chinaunix.net/download.php?id=28497&ResourceID=6095

The author also used Baidu casually at that time, and it was not official. If you need an official one, please use your own search capabilities

The installation is actually 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

The official download address is:

 http://php.net/downloads.php

Then install

After copying the file to /opt/php

Unzip:

tar -zxvf php-5.6.3.tar.gz

Then:

cd php-5.6.3

Perform installation:

 ./configure

--prefix=/usr/local/php (the path is the path where php needs to be installed)

--with-mysql=/usr/local/mysql (the path is the installation path of the installed mysql)

--with-apxs2=/usr/local/apache2.4/bin/apxs (In some tutorials, --with-apxs is written, here it is apxs2, 2 means version 2 or above. Set it like this)

--with-libxml2=/usr/local/libxml2 (this is the path where we installed libxm2 above)

Then just make, make install

 

The last step is to configure apache to support php

Modify the apache configuration file httpd.conf

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

Then add

at the end of the text

 LoadModule php5_module modules/libphp5.so (Note that in the apache installation directory, there is libphp5.so under modules. This is added during PHP installation. If not, PHP, you Need to reinstall)

 AddType application/x-httpd-php .php (. There is a space in front of it)

(Note that if the above item is not configured properly, it will result in direct downloading instead of opening when accessing http:localhost/*.php)

Screenshot of the author’s configuration

 

Next, copy the php startup file

cp 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 installed successfully

Write a simple php page, as follows

 

Isn’t it very simple? Then save it as welcome.php. The file needs to be placed in the htdocs directory of apache

Enter http://localhost/welcome.php

in the browser

If you see the page below, the installation is successful

 

 

 Summary:

When setting up a PHP environment, please refer to several tutorials. Various factors such as the version of each tutorial may be different, so it may not be suitable for everyone. This is also the author's experience and has referred to many tutorials. The reason for writing this tutorial is that many tutorials are not comprehensive, so I hope to use my experience to give some help to coders who are learning PHP. If you encounter difficulties with children's shoes during the installation process, you can leave me a message and I will try my best to help you

 


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/913103.htmlTechArticlephp5.6+apache2.4+linux to build a php environment, php5.6apache2.4 Preface Recently, I suddenly wanted to build a personal Blog, although the author is good at java-web, but for various reasons, I chose the popular p...
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