Install php and memcache in linux

Source: Internet
Author: User
The installation environment of php and memcache in linux is Ubuntu13.10 i386, and nginx and mysql servers have been installed. The current task is to install php and memcache. Dry goods directly, not to mention anything.

1. php installation and troubleshooting

Many library files need to be installed before php installation, so you need to install them in a certain order. Install the SDK in the following sequence:

Zlib-> freetype-> libxml2-> libpng-> libgd2-> libmcrypt

It also depends on zlib, freetype, libpng (libjpeg) and so on for gd2 installation. Therefore, you need to install these before installing gd2. Here, the installation is configured in the/usr/local/xxx directory according to the general directory, which generally does not cause problems, and may occur during freetype installation:

 
Note: the following error may be prompted when installing freetype: either set the LIBPNG_CFLAGS and LIBPNG_LDFLAGS environment variables. This indicates that the installation location of libpng cannot be found. Therefore, you need to configure the bin directory of libpng to the environment: solution: edit: vi/etc/profileLIB_PNG =/usr/local/libpng/binPATH = $ LIB_PNG: $ PATH export PATH effective :. /etc/profile
Here I want to record that no error was reported when I installed GD2, and the installation was successful. However, when installing php later, after configuring the GD2 installation directory in the configuration, an error occurs, and configure is okay, and an error occurs during the installation, you need to know that it will take a long time for configure to be installed in php, and it will take a long time for you to make it. after a long time, it suddenly says that the compilation fails, which is 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
Note: This prompt indicates that the libXpm library is not installed. it is not enabled when the gd2 Library is installed.

In this case, when I checked the previous configuration and installed gd2, I found that the libXpm library is not supported, as shown below:

** Configuration summary for libgd 2.1.0:   Support for Zlib:                 yes   Support 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

Therefore, the solution is to download the libXpm library for installation:

sudo apt-get install libXpm-dev
After the installation, you can reinstall the gd2 library and add one more entry -- with-xpm =/usr/lib when configuring gd2.

However, during configuration, the system will prompt that the xpm library cannot be found. here I have found a solution on the Internet, and set up a soft connection file under/usr/lib to the actual xpm library file, as shown below:

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/lib/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 ) /libXpm.so.4.11  /usr/lib/libXpm.so.4.11

After the operation is complete, you can reinstall the gd2 Library. the configuration is successful:


The "Support for Xpm library: yes" option is displayed, indicating that the configuration is successful. then, make & make install can install the gd2 library.

After installing all the library files, you can configure php to install the files. the configuration is successful and compilation fails, therefore, during this configuration, you must add the -- with-xpm-dir =/usr/lib/option 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
In this way, after configure, make, and make install, php installation can be completed. Then use

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

Add php support in the nginx configuration file to use php for development.

2. install memcache and handle errors

Memcache is divided into server-side and php extensions. the server-side uses memcached to complete various management such as storage and deletion of all data. The php extension is an extension library used by php to use memcache, represented by memcache, to call and access the memcache service of the system, use new Memcache directly in php.

(1) first, you need to install the server. you can directly use the default installation of ubuntu:

sudo apt-get install memcached

After installing the Memcache server, run the following command to start the service:

memcached -d -m 128 -p 11111 -u root

Description of memcached service startup parameters:
-P TCP listening port. the default value is 11211.
-L connected IP address. the default value is local
-D. start the memcached service.
-D restart: restart the memcached service.
-D stop | shutdown the running memcached service
-D install the memcached service
-D uninstall memcached service
-U Running identity (only valid when running as root)
-M Maximum memory usage, in MB. The default value is 64 MB.
-An error is returned when M memory is used up, instead of deleting items.
-C Maximum number of simultaneous connections. the default value is 1024.
-C disable CAS
-P Set the name of the file saved by the PID, which is called only with the-d option.
-F Block size growth factor. the default value is 1.25-n. the minimum allocation space is 48 for key + value + flags.
-T The number of threads used. the default value is 4.
-B. set the size of the backup log queue. the default value is 1024.
-R: sets the maximum number of requests for each event. the default value is 20.
-H Show Help

You can check whether the memcached server is enabled:


You can see that port 11211 is in the LISTEN status, indicating that the memcached server is enabled.

(2) install the memcache Client

In fact, this installation is based on the installation of php, to install new extensions for php, similar to the principle of re-installing a socket extension for a php without configuring and installing a socket without uninstalling php.

First, you can use the pecl installation program that comes with php:

/usr/local/php5.5/bin/pecl install memcache
You can also use the following command to download the source code package and decompress the package for installation:

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

However, no matter which method is used, the final result is to use the phpize tool to generate a configuration file for memcache, which requires the autoconf Library, as you can see from the previous php installation configuration, I have installed the autoconf library, so the same error will be reported when I use the above two methods for installation:


Similarly, when I use the source code package to install the memcache source code package, I need to use the/usr/local/php5.5/bin/phpize tool to generate the configure file, the same error will be reported. From this point, it can be noted that the above two installation methods are all the same, and the principles are the same.

For this reason, I need to install the autoconf library, but when installing this library, the same error will be reported:


It can be seen that the M4 version is too low and needs to be updated. By checking the information, autoconf uses the M4 macro processor to process the configure. in file, so that the configure file can be generated for configuration installation.

Then download the M4 source code and install it. there is another issue here. I am prompted to download the recommended M41.4.16 source code package. the configuration is successful, however, the following problems may occur during compilation:

./stdio.h:477:1: error: 'gets' undeclared here (not in a function)_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");^
I found this problem on the Internet not only when installing M4, but also when many people install other libraries. I also found someone who changed _ GL_WARN_ON_USE for hack, some people also say that patching (the specific cause of this problem may be complicated and I have not figured it out ). However, I think ubuntu 13.10 is a relatively new version. it should be fixed! So I downloaded a new version of 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

When I installed the SDK by following the steps above, the installation was successful and compilation was completed without any problems. The conclusion here is that, as software users and developers, we must be able to maintain software updates and use the latest and stable versions whenever possible to avoid many strange problems.

During installation, decompress the package to/usr/local/m4, and then directly configure can install autoconf without specifying a prefix. Otherwise, the same M4 error cannot be found.

Install autoconf as follows:

export  PATH=/usr/local/m4:$PATHcd autoconf./configure --prefix=/usr/local/autoconfmakemake install
Install autoconf according to the above command.

Then install memcache. at this time, importing/usr/local/autoconf/bin to PATH using export does not work, so I tried to use the following command:

sudo ln -s /usr/local/autoconf/bin/autoconf autoconfsudo ln -s /usr/local/autoconf/bin/autoheader autoheadersudo ln -s /usr/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 these symbolic links, I re-enter the memcache source code file and use the phpize tool. The configure file is successfully generated:


The installation process is as follows:

./configure  \ >--with-php-config=/usr/local/php5.5/bin/php-config \ >--enable-memcache=/usr/bin/memcachedmakemake install
As shown in figure below, the installed shared extensions is used to configure memcache in the php configuration file and needs to be saved.



Configure the php. ini file and find the line extension_dir in/usr/local/php5.5/lib/php. ini:

; Extension_dir = "./" to extension_dir = "directory path after installing memcache" extension = "memcache. so"; add this row to add memcache extension

Use the following php code for testing:

        Connect ('1970. 0.0.1 ', 127); echo'
';var_dump($mem);var_dump(class_exists("Memcache"));?>

Result




Through the above hardships, I not only completed the installation task, but also made me more familiar with the various precautions for installing software in linux. When installing the gd2 library, you need to rely on the Xpm Library. this problem occurs when you install php after installing gd2, and then reinstall gd2, especially after installing Xpm, after the symbolic link is used, you can install the gd2 library with Xpm. This method is an inspiration! After autoconf is installed, when the PATH variable becomes invalid, the symbolic link method is suddenly remembered. Therefore, the problem is solved. In addition, during the M4 installation, the version issue may involve many underlying problems, which I did not know yet. at that time, we also tried to use the latest version for installation. Finally, it was quite smooth to install memcache. At the same time, I also found that many php installation methods on the Internet use the configuration option -- with-autoconf option to directly install autoconf, so that you can directly use the phpize tool, but I have not installed it here, although I paid a weekly discount, after installing autoconf separately, use the symbolic link to specify the PATH to install autoconf. then phpize can be found in the PATH/usr/bin, therefore, this also indicates that the configuration option for installing php should be a search path for php to call this dependency. It's time for dinner. after a day, I feel pretty good when I see everything is ready for use! I hope some predecessors can answer some of the questions I mentioned above!

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.