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

How to install and configure the Nginx+MySQL+PHP environment

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Most people do not understand the knowledge points of this article "how to install and configure the Nginx+MySQL+PHP environment", so the editor summarizes the following contents, detailed contents, clear steps, and certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to install and configure the Nginx+MySQL+PHP environment" article.

First, install nginx

One order is done:

Use=fastcgi emerge nginx

Create new users and groups:

Groupadd www

Useradd www-g www

After nginx is installed, nginx groups and nginx users will be added by default, but I am used to creating a new www group and www users to be http service users. If the http server is changed to apache or lighttpd in the future, the user name and user group can remain the same.

Second, install mysql

Mysql must be installed before installing php, because the mysql operation function in php requires the support of mysql header files and libraries.

Emerge dev-db/mysql

Initialize the database:

The default path to the database is / var/lib/mysql, which this article installs in / work/db/3306/data.

The copy code is as follows:

Mkdir-p / work/db/3306/data

Mysql_install_db-basedir=/usr-datadir=/work/db/3306/data-user=mysql

Modify the configuration file:

Vim / etc/mysql/my.cnf

Modify the datadir to:

Datadir = / work/db/3306/data

Start mysql:

/ etc/init.d/mysql start

Change the root password:

Mysqladmin-uroot password hily

Test database:

Mysql-uroot-p

Display:

Gentoo setup # mysql-uroot-p

Enter password:

Welcome to the mysql monitor. Commands end with; or\ g.

Your mysql connection id is 2

Server version: 5.0.84-log gentoo linux mysql-5.0.84-r1

Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.

Mysql >

The test was successful!

Third, install php

To run php as fastcgi, you need to install php-fpm.

At present, the last version of php that needs to install php-fpm as patch is 5.3.0 dint php 5.3.2, which will probably integrate php-fpm directly.

Here I will use php 5.3.0 to install.

Because there is no portage for integrating php-fpm into the directory in gentoo, the installation is done directly through source code compilation.

Download php 5.3.0:

Wget http://cn.php.net/distributions/php-5.3.0.tar.bz2

Download the php-fpm patch:

Wget http://php-fpm.org/downloads/php-5.3.0-fpm-0.5.12.diff.gz

Extract php and patch fpm:

Tar jxf php-5.3.0.tar.bz2

Gzip-cd php-5.3.0-fpm-0.5.12.diff.gz | patch-d php-5.3.0- p1

Install the libraries required by php (according to your own needs):

Emerge libpng

Emerge jpeg

Emerge freetype

Use= "png jpeg truetype" emerge gd

Or directly:

Use= "png jpeg truetype" emerge gd

Configure and compile php (according to your own needs):

The copy code is as follows:

Cd php-5.3.0

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

-with-mysql=/usr-- with-mysqli=/usr/bin/mysql_config-- enable-fpm-- enable-sockets

-enable-pdo-- with-pdo-mysql=/usr-- with-gd-- with-jpeg-dir-- with-png-dir

-with-freetype-dir-with-zlib

Make & & make install

Php profile:

The copy code is as follows:

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

Php-fpm profile:

Vim / usr/local/php/etc/php-fpm.conf

Change listen_address to socket address (socket is more efficient than ip:port):

/ tmp/php-fpm.sock

Modify the user group and user name:

The copy code is as follows:

Unix user of processes

Www

Unix group of processes

Www

Change the php-fpm operation mode to apache-like mode:

The copy code is as follows:

Apache-like

one

one

five

Startservers, minspareservers and maxspareservers are set up according to the actual needs. I am a virtual machine here, so there is no need to be too big.

Php-fpm startup script:

Cp / usr/local/php/sbin/php-fpm / etc/init.d/php-fpm

Start php-fpm

/ etc/init.d/php-fpm start

Add Startup Service

The copy code is as follows:

Rc-update add nginx default

Rc-update add mysql default

Rc-update add php-fpm default

Test nginx+php

Add the test site directory:

The copy code is as follows:

Mkdir-p / work/www/test

Echo "" > / work/www/test/index.php

Add the nginx configuration for the test site:

Vim / etc/nginx/nginx.conf

Comment out the server paragraph and add the following at the end of the http paragraph:

Include sites/*.enable

After that, the configuration files for each site are saved in a separate file in the / etc/nginx/sites directory, which is easy to manage and maintain.

Mkdir / etc/nginx/sites

Vim / etc/nginx/test.enable

The test.enable configuration is as follows:

The copy code is as follows:

Server {

Listen 80

Server_name test.local

Access_log / work/www/logs/test.access.log main

Error_log / work/www/logs/test.error.log

Location / {

Root / work/www/test

Index index.html index.htm index.php

}

Location ~\ .php$ {

Root / work/www/test

Fastcgi_index index.php

Fastcgi_param script_filename $document_root$fastcgi_script_name

Include fastcgi_params

Fastcgi_pass unix:/tmp/php-fpm.sock

}

}

Create a new storage log directory:

Mkdir / work/www/logs

Add a record to the local hosts:

192.168.1.10 test.local

192.168.1.10 is the ip of my gentoo machine.

Reload the nginx configuration

/ etc/init.d/nginx reload

Visit:

Http://test.local/

If the normal phpinfo information is displayed, the installation is complete.

The above is the content of this article on "how to install and configure the Nginx+MySQL+PHP environment". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

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

Development

Wechat

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

12
Report