Install nginx PHP MySQL memcached through Ubuntu Compilation

Source: Internet
Author: User
Tags mcrypt php mysql xslt

Let's take a look at this article and repost it from nginx.cn.

Nginx itself cannot process PHP. It is only a Web server. After receiving the request, if it is a PHP request, it is sent to the PHP interpreter for processing and the result is returned to the client.

Nginx generally sends requests to the FastCGI management process. The fascgi management process selects the CGI sub-process to process the results and returns the results

This document uses PHP-FPM as an example to describe how to enable nginx to support PHP

I. Compile and install PHP-FPM

What is PHP-FPM

PHP-FPM is a PHP FastCGI manager that is only used for PHP and can be downloaded at http://php-fpm.org/download.

PHP-FPM is actually a patch of PHP source code, designed to integrate FastCGI process management into the PHP package. You must patch it to your PHP source code before using it after compiling and installing PHP.

The new version of PHP has already integrated PHP-FPM and is no longer a third-party package. We recommend that you use. PHP-FPM provides a better way of PHP process management, can effectively control the memory and process, can smoothly load PHP configuration, than spawn-fcgi has more, so PHP officially included. You can enable PHP-FPM with the-enable-FPM parameter in./configure.

New version of PHP-FPM installation (recommended)

Wget http://cn2.php.net/distributions/php-5.4.7.tar.gz

Tar zvxf php-5.4.7.tar.gz

CD php-5.4.7

. /Configure -- prefix =/usr/local/PHP -- enable-FastCGI -- enable-FPM -- With-mcrypt -- With-zlib -- enable-mbstring -- disable-PDO -- With-curl -- disable-Debug -- enable-pic -- disable-rpath -- enable-inline-optimization -- with-bz2 -- With-XML -- With-zlib -- enable-sockets -- enable-sysvsem -- enable-sysvshm -- enable-pcntl -- enable-mbregex -- With-mhash -- enable-XSLT -- enable-memcache -- enable-zip -- With-PCRE-RegEx -- With-MySQL

Make all install

Install PHP-FPM manually in the old version

Wget http://cn2.php.net/get/php-5.2.17.tar.gz
Wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz

Tar zvxf php-5.2.17.tar.gz
Gzip-CD php-5.2.17-fpm-0.5.14.diff.gz | patch-D php-5.2.17-p1
CD php-5.2.17
. /Configure -- prefix =/usr/local/PHP -- enable-FastCGI -- enable-FPM -- With-mcrypt -- With-zlib -- enable-mbstring -- disable-PDO -- With-curl -- disable-Debug -- enable-pic -- disable-rpath -- enable-inline-optimization -- with-bz2 -- With-XML -- With-zlib -- enable-sockets -- enable-sysvsem -- enable-sysvshm -- enable-pcntl -- enable-mbregex -- With-mhash -- enable-XSLT -- enable-memcache -- enable-zip -- With-PCRE-RegEx -- With-MySQL

Make all install

You can install PHP-FPM in either of the preceding methods. After installation, the content is stored in the/usr/local/PHP Directory.

CD/usr/local/PHP

Cp etc/php-fpm.conf.default ETC/php-fpm.conf

Modify

Vi etc/php-fpm.conf.default ETC/php-fpm.conf

User = www-Data
Group = www-Data

2. Compile and install nginx

Then install nginx according to the http://www.nginx.cn/install

3. Modify the nginx configuration file to support PHP-FPM

After nginx is installed, change the nginx configuration file to nginx. conf.

The following configuration is added to the server segment. Pay attention to the configuration in red; otherwise, no input file specified will occur.

# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ \. Php $ {
Root HTML;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param script_filename $ document_root $ fastcgi_script_name;
Include fastcgi_params;
}

4. Create a PHP Test File

Create a PHP File

Create the index. php file in/usr/local/nginx/html and enter the following content:

<? Echo phpinfo () ;?>

5. Start the service

Start PHP-FPM and nginx

/Usr/local/PHP/sbin/PHP-FPM (manual patching startup method/usr/local/PHP/sbin/PHP-FPM start)

Sudo/usr/local/nginx

6. browser access

Access http: // your server IP Address/index. php, you can see the PHP information.

Possible errors when installing PHP-FPM:

1. phpconfigure Error

Configure: Error: xml configuration cocould not be found
Apt-Get install libxml2 libxml2-dev (under Ubuntu)
Yum-y install libxml2 libxml2-devel (under centos)

2. Please reinstall the Bzip2 Distribution

Wget http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
Tar-zxvf bzip2-1.0.5.tar.gz
CD bzip2-1.0.5
Make
Make install
3. There is a line in the PHP configuration file -- With-mysql =/usr. Prompt during installation:
Configure: Error: cannot find MySQL header files under yes.
Note that the mysql client library is not bundled anymore.

This is because the MySQL header file is not installed during MySQL installation, or the path is incorrectly specified, and PHP cannot find the MySQL header file.
Solution.
(1) Check whether your system has installed the MySQL header.
Find/-name mysql. h
If yes. Specify -- With-mysql =/and your normal path.
If not. Please refer to the next step.
(2) RedHat Installation
Rpm-IVH MySQL-devel-4.1.12-1.i386.rpm
(3) install Ubuntu
Apt-Get install libmysqlclient15-dev
(4.) add -- With-mysql =/usr to the configuration option of php In the last step!
4. No input file specified.

Location ~ \. Php $ {
Root HTML;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param script_filename $ document_root $ fastcgi_script_name;
Include fastcgi_params;
}

5. If the PHP configure library is missing, install the Library first (under Ubuntu)

Sudo apt-Get install make bison flex gcc patch Autoconf subversion locate
Sudo apt-Get install libxml2-dev libbz2-dev libpcre3-dev libssl-dev zlib1g-dev libmcrypt-dev libmhash-dev libmhash2 libcurl4-openssl-dev libpq-dev libpq5 libsyck0-dev

 

Let's talk about my problems.

1. After nginx is installed, start nginx and "unable to resolve host..." appears ..."

Solution: view the hostname in/etc/hostname. For example, I must use f83vf.

Add the hostname to/etc/hosts and add a line to the file

127.0.0.1 f83vf

 

2. Add the nginx service script and set nginx to start the service.

Modify nginx. conf in your nginx installation directory and start the PID file.

Pid/usr/local/nginx/var/run/nginx. PID;

Create a file in the/etc/init. d/folder named nginx. Copy the script content from here.

Https://github.com/JasonGiedymin/nginx-init-ubuntu/blob/master/nginx

Some of these paths must be changed to their own nginx installation path.

Then you can use/etc/init. d/nginx START | stop | restart | reload to control nginx.

Run the following command to add nginx to the startup service:

Chkconfig -- add nginx

If/sbin/insserv: no such file or directory appears at this time

Run the following code to solve the problem:

Ln-S/usr/lib/insserv/sbin/insserv

Add to service auto start

Chkconfig nginx on

 

3. Configure the PHP-FPM script and add it to the service.

Start with the php-fpm.pid, modify the PHP/etc/php-fpm.conf, add the following line

PID =/var/run/php-fpm.pid

This script is also available in the PHP source code package. Copy it to init. d and modify the directory path in the script, as shown below:

CP php-5.4.7/SAPI/FPM/init. d. php-fpm.in/etc/INI. d/PHP-FPM

Vim/etc/init. d/PHP-FPM

Prefix =
Exec_prefix =

Php_fpm_bin =/usr/local/PHP/sbin/PHP-FPM
Php_fpm_conf =/usr/local/PHP/etc/php-fpm.conf
Php_fpm_pid =/usr/local/PHP/var/run/php-fpm.pid

Chkconfig -- add PHP-FPM

Chkconfig PHP-FPM on

 

4. Configure PHP. ini

First use phpinfo () to view your php. ini path. By default, the PHP compiled and installed does not have PHP. ini. You need to copy it from the source package. For example, my

Php-5.4.7/PHP. ini-development/usr/local/PHP/lib/PHP. ini

In fact, this path can be specified during PHP compilation. The parameter is -- With-config-file-path.

I won't talk about how to configure it.

 

Compile and install MySQL

Group Add MySQL
Useradd mysql-G mysql-S/bin/bash

Go to the MySQL source code directory and run the following code:
Cmake .\
-Dcmake_install_prefix =/usr/local/MySQL \
-Dmysql_datadir =/usr/local/MySQL/data \
-Dwith_myisam_storage_engine = 1 \
-Dwith_innobase_storage_engine = 1 \
-Denabled_local_infile = 1 \
-Ddefault_charset = utf8 \
-Ddefault_collation = utf8_general_ci \
-Dextra_charsets = all \
-Dmysql_tcp_port = 3306 \
-Dmysql_user = MySQL \
-Dsysconfdir =/usr/local/MySQL \
-Dmysql_unix_addr =/usr/local/MySQL/mysqld. Sock \
-Dwith_ssl = Yes \
-Dwith_memory_storage_engine = 1 \
-Dinstall_plugindir =/usr/local/MySQL/plugin \
-Dwith_zlib = Yes \

Make
Make install

CD/usr/local
Chown-r mysql. MySQL

Su MySQL

CD MySQL
CP support-files/my-large.cnf my. CNF
CP support-files/MySQL. Server/etc/init. d/mysqld
CD/etc/init. d
Chmod + x mysqld
Chkconfig -- add mysqld
Chkconfig mysqld on

Initialize database tables
CD/usr/local/MySQL

./Scripts/mysql_install_db -- basedir =/usr/local/MySQL -- datadir =/usr/local/MySQL/data -- user = MySQL

Start MySQL
Service mysqld start

Initialize username and password and delete Anonymous Users
./Bin/mysqladmin-u Root Password "root"
./Bin/MySQL-uroot-proot

Execute SQL statements
Mysql> Delete from mysql. User where user = "";

Installation is now complete

 

Compile and install memcached


Download the libevent and memcached source code packages

Go to the libevent source code directory

./Configure -- prefix =/usr/local/libevent

Make

Make install

Go to the memcached source code directory

./Configure -- prefix =/usr/local/memcached -- With-libevent =/usr/local/libevent

Make

Make install

 

Configure memcached

# Configure the conf file

 

CD/etc

Vim memcached. conf

Add the following code:

# Cache memory
-M 128

# Listening host
-L 127.0.0.1

# Listening port
-P 11211

# Running user
-U Root

# Run as a daemon
-D

# PID file path
-P/usr/local/memcached. PID

# Be very verbose
-V
-VV
-Vvv

# Log
Logfile/usr/local/memcached/logs/memcached. Log

Save and exit

# Configure the start script

Go to the memcahed source code directory.

CP./scripts/start-memcached/usr/local/memcached/scripts/

Modify this file

CD/usr/local/memcached/scripts/

Vim start-memcached

Modify the following path:

My $ Params; my $ etchandle; my $ etcfile = "/etc/memcached. conf ";

# This script assumes that memcached is located at/usr/bin/memcached, and
# That the pidfile is writable at/var/run/memcached. PID

My $ memcached = "/usr/local/memcached/bin/memcached ";
My $ pidfile = "/usr/local/memcached. PID ";

# Configure the Startup Script

Go to the source code directory

CP./scripts/memcached-init/etc/init. d/memcached

Modify the following content of a file:

Path =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
Daemon =/usr/local/memcached/bin/memcached
Daemonname = memcached
Daemonbootstrap =/usr/local/memcached/scripts/start-memcached
Desc = memcached

Save and exit

# Set the startup Item

Chkconfig -- add memcached

Chkconfig memcached on

# Start memcached

Service memcached start

 

Compile and install PHP pdo_mysql and memcache

Because these two files are not compiled during PHP compilation

First compile pdo_mysql

Go to ext/pdo_mysql in the PHP source code directory and run phpize in the PHP installation directory.

/Usr/local/PHP/bin/phpize

Then compile and install

./Configure -- With-PHP-Config =/usr/local/PHP/bin/PHP-config -- With-PDO-mysql =/usr/local/MySQL

Modify the specific path

After installation, an extension of. So will be generated. It will tell you where to copy it to the extionsion_dir of PHP and then enable it in PHP. ini.

Extension = pdo_mysql.so

You can.

Compile and install memcache below. This is simple. You can directly install it using PECL of PHP and configure it in PHP. ini.

/Usr/local/PHP/bin/PECL install memcache

Just as above, copy the generated so file to your ext directory and enable it in PHP. ini.

 

Now, all environment configurations are complete, and you can finally write code .. T-t .. Tears ..

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.