Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Build centos7+apache+mongodb+php environment

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Build centos7+apache+mongodb+php environment

Recently, we are doing an experiment on nosql injection, and we need to build a database website environment in which the database is mongodb. But I know little about mongodb database, so I encountered a lot of problems in the process of building. Because of the food, so learn. I don't know if there are any children's boots that have encountered a lot of problems in setting up the environment.

This article was written after the experiment, so I didn't find a way to take screenshots of the problems I encountered, so I just asked a few questions that are still fresh in my memory. If some students encounter the same problem, I hope I can help you solve it. Don't build the environment all day long and it's not finished yet (that's what I am, laugh at me! )

Problems encountered:

1. The installation of the php version affects the extension of php's mongodb database.

Choose the version of php5.6 for this installation

2. Dependency package problem during installation

3. Installation sequence

4. the problem of configuration file and startup mode after installation

5. Carelessness

Environment introduction:

Linux:CentOS7

Apache:2.4.6

MongoDB:3.2.10

Php:5.6

Installation source code and other source code that need to be downloaded

Php-5.6: http://cn2.php.net/downloads.php

Mongodb-3.2.10: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.10.tgz

Mongodb's php extension: http://pecl.php.net/get/mongo-1.5.5.tgz

Installation steps: 1. Install the apache service

There are no special requirements for apache service installation, just install it from the yum source.

Answer point: (dependency question)

Note that httpd-devel must be installed because this package is related to the apxs command, which is used to load the php module, which is used when installing php. This belongs to the problem of installing dependencies and packages. There is no way to load the libphp5.so module without this later compilation and installation of the php,Apache service.

To avoid accidents where individual packages need to be installed but not installed, directly:

Yum install httpd*-y

2. Install mongodb database

(1) upload the downloaded source code to the server, and then decompress and install it.

(2) create relevant directories and files before installation

Mkdir / data/mongodb/dbs-p

Touch / data/mongodb/log

Function, the first directory is used to store database data, and the second file is used to store database logs, which will be used later.

(3) decompress the package to the specified directory

Tar-xvf mongodb-linux-x86_64-rhel62-3.2.10.gz-C / usr/local

(4) for the convenience of using the command, add the file path of the database to the environment variable.

Vi .bash _ prefile

For the environment variable to take effect, you need to execute a command:

Source .bash _ prefile

(4) create a configuration file for the database and start the database

Vi / etc/mongodb.conf

Dbpath=/date/mongodb/dbs / / data file address

Logpath=/data/mongodb/log / / Log File address

Port=27071 / / Port number (default 27017)

Fork=true / / running in the background

Journal=true / / enable logging option

Start the database:

Mongod-f / etc/mongodb.conf

Answer point (database startup mode question)

Mongodb database default port is 27017, you can enter the command mongo directly when entering the database, but because of my temporary carelessness, I wrote 27071 in the configuration file, so there is no way to start it with the start method. When the port is changed, the way to enter the database is:

Mongo localhost: Port number

For example, here I am: mongo localhost:27071

3. Install php

(1) upload the downloaded source code to the server

(2) decompression

Tar-zxvf php-5.6.39.tar.gz

(3) install related dependencies:

Yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel gcc

Here compilation and installation will require a lot of related dependencies, in order to facilitate, avoid errors, collected some needed dependencies on the Internet, at the same time, compilation and installation requires gcc, you can see if you have this compilation tool, if not, you also need to install.

(4) enter the decompressed directory, compile and install

Cd php-5.6.39

. / configure-- prefix=/usr/local/php-- with-config-file-path=/etc-- with-apxs2=/usr/bin/apxs

-- prefix specifies the installation location

-- with-config-file-path specifies the location of the php.ini

-- the with-apxs2 integration apache,apxs function uses the LoadModule instruction in mod_so to load the specified module into apache, and requires apache to open the SO module.

Here, the command of apxs depends on the path of your personal situation. Check the path method of apxs file:

Which apxs

(5) installation

Make & & make install

Cp php.ini-production / etc/php.ini

(6) similarly, set the environment variable

Make the environment variable effective: source .bash _ prefile

After installation, check to see if there is libphp5.so in the / etc/httpd/modules/ directory. If so, there is no problem with the module installation. If there is no module here, there will be an error when apache parses php.

4. Install the extension

(1) upload the extended source code to the server

(2) decompression: tar-zxvf mongo-1.5.5.tgz

(3) enter the decompressed directory and generate the execution file configure

Execute command: phpize

It's wrong, and there's a way to solve it.

How to resolve the error:

Wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz

Tar-zvxf M4-1.4.9.tar.gz

Cd M4-1.4.9 /

. / configure & & make & & make install

Yum install autoconf.

Re-execute the phpize command and ok.

(4) execute configure file to generate Makefile file

. / configure-enable-mongo=share-with-php-config=php-config

(5) installation

Make & & make install

At this point, the basic installation is almost complete, but the environment is still not available, and then there are changes to the configuration file.

5. Modification of configuration file

(1) when the installation of the extension is complete, the sentence "extension_dir=/usr/lib/php/extensions/debug-non-zts-20151012/" appears.

It may be different from mine, but it's all similar. Copy this sentence, open the / etc/php.ini file, add it, and add extension=mongo.so at the same time.

Both are mongodb-enabled extensions. There is no way to operate on the database without this.

Vi / etc/php.ini

Add:

Extension_dir=/usr/lib/php/extensions/debug-non-zts-20151012/

Extension=mongo.so

(2) Open the configuration file of apache and modify it.

Add:

AddType application/x-httpd-php .php

AddType application/x-httpd-php .htm

AddType application/x-httpd-php .html

DirectoryIndex index.html index.cgi index.php index.phtml index.php3

The location of these statements has been given in the file, search AddType and DirectoryIndex will find

Explanation point: (issues between php version and extension)

Some people may directly use the yum source of mongodb, and then execute the installation extension of pecl install momgodb. At this time, if your php is 5.4 or less, it will directly report an error, indicating that you need a version of php5.5.99 or above. So in order to avoid conflicts, the version of php5.6 is also used here.

Explanation point: (installation sequence problem, sloppy)

We all know the order in which lamp (linux+apa+mysql+php) is installed, which is the order in which amp is installed, and here apa+mongo+php is also installed in this order. The reason for my installation error is that I installed php when I didn't install apa. I have a habit of creating a snapshot without installing a service in an environment I don't understand, so I can come back and do it again. But because of this, when I returned to the snapshot, I thought I had returned to the snapshot where the Apache service was installed, but I didn't want to know.

All right, we have basically solved the installation of all the services here. As long as you start all the services, you can visit the website and write a php page for testing. If there is an error about mongo class, it means that your extension is not ready, either modify php.ini or reinstall it.

Note: be sure to turn off the firewall and selinux when visiting the website. Shutdown method: systemctl stop firewalld and setenforce 0

I hope it can help people who make a lot of mistakes like me.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report