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

WBOY
Release: 2016-08-08 09:33:21
Original
1007 people have browsed it

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

Foreword

 Recently, I suddenly wanted to build a personal blog. Although the author is good at java-web, 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. Centos6.4 installed on a 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 versions downloaded by the author are specifically, 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, it is installed (the 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. Installation of apr-util:

 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 just searched Baidu at that time, it was not official. If you need official information, please use your own search capabilities

In fact, the installation is basically the same as above, just simply 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

 This will install libxml2.

The next step is to install php

 The official download address is:

 http://php.net/downloads.php

 Then it’s installed

After copying the file to /opt/php

Decompression:

 tar -zxvf php-5.6.3.tar.gz

 Then:

 cd php-5.6.3

Execute 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 mysql that has been installed)

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

  --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 it)

 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 that when accessing http:localhost/*.php, it will be downloaded directly instead of opened)

 Screenshots 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, it means 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 everyone is setting up a PHP environment, please refer to several more 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

 

Copy after login

The above introduces how to build a PHP environment with php5.6+apache2.4+linux, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!