Linux installation PHP and memcache process logging

Source: Internet
Author: User
Installation environment is UBUNTU13.10 version i386, has installed Nginx server and MySQL server, now the task is to install PHP and memcache. Direct dry goods, needless to say.

1, PHP Installation and error troubleshooting

Because many library files need to be installed before PHP is installed, you need to be patient to install them in a certain order. I install them in the following order:

LIBGD2, Libpng, LIBXML2, FreeType, zlib, Libmcrypt

It is also dependent on the installation of GD2 need to use zlib, FreeType, libpng (libjpeg), etc., so you need to install these before installing GD2. The installation here follows the common directory configuration to the/usr/local/xxx directory, which generally does not cause problems, and may cause problems when installing FreeType:

Note that you may be prompted with the following error when installing FreeType: either set the Libpng_cflags and LIBPNG_LDFLAGS environment variables this is a hint that the LIBPNG installation location could not be found, Therefore, the Libpng bin directory needs to be configured into environment variables: Workaround: Edit: Vi/etc/profilelib_png=/usr/local/libpng/binpath= $LIB _png: $PATH  Export PATH takes effect:.  /etc/profile
Here I would like to record that I installed the GD2 when no error, the installation was successful. But later when the installation of PHP, configured in the configuration of GD2 installation directory, error, and configure is no problem, is in the installation of error, to know that when installing PHP configure would have been a long time, and then yes, make the time also to be long, It's been a long, long time since I suddenly said compile error, really a bit of a crash. The error is as follows:

/usr/local/src/php-5.5.6/ext/gd/gd.c:57:22:error:x11/xpm.h:no such file or directorymake: * * * [Ext/gd/gd.lo] Error 1
Description: This is a hint that the LIBXPM library is not installed and is not configured to open when installing the GD2 library.

So I went to check before configuring the installation Gd2 when prompted, did find that the LIBXPM library is not supported, as follows:

* * Configuration Summary for LIBGD 2.1.0: "Support for   Zlib: yes" for   PNG Library:          Yes   support For JPEG Library: no-support for   VPX Library: No-support for   TIFF Library:         No   -support for Freetype 2.x library:yes support for   fontconfig Library:   no support for   XPM Library:          no   Support for pthreads:             Yes

So the workaround is to download the LIBXPM library installation:

sudo apt-get install Libxpm-dev
After this installation, I thought it was possible to reinstall the GD2 library and add a--with-xpm=/usr/lib when configuring GD2.

However, the configuration will be prompted to find the XPM library, here I found a solution on the Internet, under the/usr/lib to establish a soft connection file to the real xpm library file, as follows:

Ln-s/usr/lib/(x86_64 or i386)/LIBXPM.A  /usr/lib/libxpm.a ln-s/usr/lib/(x86_64 or i386)/libxpm.so  /usr/li b/libxpm.so ln-s/usr/lib/(x86_64 or i386)/libxpm.so.4  /usr/lib/libxpm.so.4 ln-s/usr/lib/(x86_64 or i386)/lib xpm.so.4.11  /usr/lib/libxpm.so.4.11

Once the operation is complete, the GD2 library can be reinstalled and the configuration completed successfully:


You will find the "support for XPM Library:yes" item, stating that the configuration was successful, then make && make install to complete the installation of the GD2 library.

After the installation of all the library files, you can configure the PHP installation, because the configuration is successful, compile error, so this configuration will need to join the--with-xpm-dir=/usr/lib/to compile successfully. The complete configuration is as follows:

./configure \    --prefix=/usr/local/php5.5 \      --with-libxml-dir=/usr/local/libxml2/\    --with-png-dir=/ usr/local/libpng/\    --with-freetype-dir=/usr/local/freetype/\    --with-gd=/usr/local/gd2/\    -- with-zlib-dir=/usr/local/zlib/\    --with-mcrypt=/usr/local/libmcrypt/\    --with-xpm-dir=/usr/lib/\    -- With-mysql \    --with-mysqli \    --enable-pdo \    --with-pdo-mysql \     --with-iconv \   --enable-soap \    --enable-mbstring=all \    --enable-sockets \  --enable-fpm
This completes the installation of PHP after the configure and make, makes install. Then use

sudo/usr/loca/php5.5/sbin/php-fpm
To turn on the PHP-FPM service, you can add this command to the/etc/rc.local file as a self-starting service.

Adding PHP support to the Nginx configuration file can be used in PHP development.

2. Installation Memcache and error handling

Memcache is divided into server-side and PHP extensions, server-side use of memcached, complete the storage of all the data delete and other management, PHP extension is PHP using memcache an extension of the library, with Memcache, The Memcache service for invoking and accessing the system, using the new memcache directly in PHP.

(1) The first need to install the server, this direct use of Ubuntu default installation can be:

sudo apt-get install memcached

After installing the Memcache server, start the service using the following command:

Memcached-d-M 128-p 11111-u Root

Description of the startup parameters for the memcached service:
-P TCP Listener port, default is 11211
-L connected IP address, default is native
-D Start memcached service
-D Restart Restart memcached service
-D Stop|shutdown Close the running memcached service
-D Install memcached service
-d Uninstall Uninstall memcached service
-U Running identity (only valid when run as root)
-M Maximum memory usage, in megabytes. Default 64MB
-M running out of memory and returning an error instead of deleting an item
-C Maximum number of simultaneous connections, default is 1024
-C prohibit use of CAs
-P Sets the name of the PID saved file, only called with the-D option
-F Block size growth factor, default is 1.25-n minimum allocation space, key+value+flags default is 48
-T Number of threads used, default is 4
-B Set the size of the backup log queue, default is 1024
-R Sets the maximum number of requests per event, default is 20
-H Display Help

You can check whether the memcached server is turned on:


You can see port 11211 in the listen state, indicating that the memcached server is turned on.

(2) Installing the Memcache client

This installation is actually in PHP has been installed on the basis of the installation of new extensions to PHP, similar to a not configured to install the socket PHP without uninstalling PHP under the premise of reinstalling a socket extension principle is similar.

You can start with the Pecl installer that comes with PHP:

/usr/local/php5.5/bin/pecl Install Memcache
Second, you can also download the source package with the following command to unzip the installation:

wget http://pecl.php.net/get/memcache-2.2.6.tgz

However, the problem I encountered is that regardless of which method is used above, the end result is to use the Phpize tool to generate a configuration file for Memcache, and this need to autoconf this library, from the previous installation of PHP configuration can be seen, I have installed autoconf library, So I'm going to use both of these methods to report the same error:


Similarly, when I use the source package installation, enter into the memcache source package, you need to use the/usr/local/php5.5/bin/phpize tool to generate configure files, and the same error reported. From here can also be explained that the above two installation methods are the same, the principle is the same.

To do this, I need to install the Autoconf library, but when I install this library, I also get an error:


It is obvious here that the M4 version is too low and needs to be updated. By accessing the information, Autoconf uses the M4 macro processor to process the Configure.in file, which allows the configure file to be generated for the installation configuration.

Then, is to download M4 source for installation, here there is a pit, I install the hint to download the recommended M41.4.16 version of the source package, the configuration is successful, but the compilation will appear similar to the following problems:

./stdio.h:477:1: Error: ' gets ' undeclared here (not in a function) _gl_warn_on_use (gets, "gets is a security hole-use FG ETS instead "); ^
This problem I find on the internet, found that not only the installation of M4 will appear, many people install other libraries when there will be similar problems, but also find someone to change the _gl_warn_on_use to hack, also some people say patching (the specific cause of the problem may be more complex, not clear). But I think my Ubuntu is 13.10 is a relatively new version, there should be a fix it! So I re-downloaded the latest version of a M4:

wget  http://ftp.gnu.org/gnu/m4/m4-latest.tar.gztar-zxf m4-latest.tar.gz;mv m4-1.4.17  /usr/local/m4cd/usr /local/m4./configuremakemake insatll

Follow the above steps to install the time, the miracle appeared, sure enough to compile the installation completed, there is no problem. The conclusion here is that as software users and developers, we must be suitable to keep the software updated, try to use the latest stable version, so as to avoid encountering many strange problems.

Install the unpacking package into the/USR/LOCAL/M4, and then directly configure do not specify prefix to install autoconf, otherwise you will not find the same M4 error.

Install autoconf as follows:

Export  path=/usr/local/m4: $PATHCD autoconf./configure--prefix=/usr/local/autoconfmakemake Install
The installation of autoconf is completed as per the above command.

Then, to install memcache, importing/usr/local/autoconf/bin into path using export does not work, so I try to use the following command:

sudo ln-s/usr/local/autoconf/bin/autoconf autoconfsudo ln-s/usr/local/autoconf/bin/autoheader autoheadersudo ln-s/u Sr/local/autoconf/bin/autom4te autom4tesudo ln-s/usr/local/autoconf/bin/autoreconf autoreconfsudo ln-s/usr/local/ Autoconf/bin/autoscan autoscansudo ln-s/usr/local/autoconf/bin/autoupdate autoupdatesudo ln-s/usr/local/autoconf/ Bin/ifnames Ifnames

After making these symbolic links, I re-entered the memcache source file using the Phpize tool is no problem, successfully generated the Configure file:


The installation process is as follows:

./configure  \ >--with-php-config=/usr/local/php5.5/bin/php-config \ >--enable-memcache=/usr/bin/ Memcachedmakemake Install
Installation complete as shown, the last installed shared extensions is configured in the PHP configuration file memcache need to be used and need to be saved.



To configure the php.ini file, in/usr/local/php5.5/lib/php.ini, locate the Extension_dir line:

Extension_dir = "./" To Extension_dir = "directory path after installation memcache completed" extension = "memcache.so"; add this row for adding memcache extensions

Use the following PHP code to test:

!--? php//test memcache$mem = new Memcache; $mem--->connect (' 127.0.0.1 ', 11211); Echo ' 
 
Results




Through all the above hardships, not only did the task of installation, but also let me become more familiar with the Linux installation of the software of all kinds of noteworthy places. When installing the GD2 library, you need to rely on the XPM library, which is actually installed in the GD2 after the installation of PHP, and then reinstall GD2, especially after installing XPM, after using the symbolic link, you can install the GD2 library with XPM. This method is a revelation! After the installation of the autoconf is complete, the use of the path variable when it is invalid is suddenly remembered the symbolic link method, so you try to use and solve the problem. There is the installation of M4, the version of the problem may involve a lot of the underlying problems, which I did not know, was also a trial use of the latest version of the installation can be solved. The final installation of the memcache when it was more smooth. Also found that there are many online installation of PHP using the configuration options--with-autoconf option to install the autoconf directly, so that you can directly use the Phpize tool, but I do not install here, although I have to make a lot of trouble, However, after the autoconf is installed separately, the autoconf path of the installation is specified using the symbolic link, and the phpize can be found from the path/usr/bin. So it also shows that installing PHP is a specific configuration option that specifies a search path when PHP needs to be called for this dependency. Dinner time, toss a day, see everything can be used when still feel pretty good! I hope to have predecessors can answer some of the doubts I mentioned earlier!

  • 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.