Install PHP5.5 and memcached in Centos5.8

Source: Internet
Author: User
Tags zts
License cdgit-1.9.0.

To install GIT, install gcc-c ++ (sudo yum install gcc-c ++) first) sudo yum install gettext-devel expat-devel cpio perl openssl-devel zlib-devel wget tar-zxvf git-1.9.0.tar.gz cd git-1.9.0./

Install GIT

Install gcc-c ++ (sudo yum install gcc-c ++) first)
Sudo yum install gettext-devel expat-devel cpio perl openssl-devel zlib-devel
Tar-zxvf git-1.9.0.tar.gz
Cd git-1.9.0
Sudo make
Sudo make install

Install memcached

Sudo yum install libevent-devel
Tar-zxvf memcached-1.4.17.tar.gz
./Configure-prefix =/opt/memcache
Sudo make
Sudo make install
Sudo cp scripts/memcached. sysv/etc/rc. d/init. d/memcached
Sudo vim/etc/rc. d/init. d/memcached

Two places need change:
= 1 =
PORT = 11211
USER = memcached
MAXCONN = 1024

= 2 =
Start (){
Echo-n $ "Starting $ prog :"
# Insure that/var/run/memcached has proper permissions
Chown $ USER/opt/memcache/bin/memcached
Daemon/opt/memcache/bin/memcached-d-p $ PORT-u $ USER-m $ CACHESIZE-c $ M
AXCONN-P/opt/memcache/bin/memcached. pid $ OPTIONS

Add user memcached before starting memcached service:
Sudo/usr/sbin/groupadd memcached
Sudo/usr/sbin/useradd-g memcached
Sudo passwd memcached

Install PHP5.5

Yum-y install bzip2 bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxml2-devel

(Mysql is compiled and installed)
. /Configure-prefix =/opt/php-with-apxs2 =/opt/apache2/bin/apxs-with-libxml-dir =/usr/lib64-with-mysql =/opt/mysql -with-mysqli =/opt/mysql/bin/mysql_config-with-gd-enable-gd-native-ttf-with-zlib-with-mcrypt-with-pdo-mysql = /opt/mysql-enable-shmop-enable-soap-enable-sockets-enable-wddx-enable-zip-with-xmlrpc-enable-fpm-enable-mbstring-with-zlib -dir-with-bz2-with-curl-enable-exif-enable-ftp-with-jpeg-dir =/usr/lib64-with-png-dir =/usr/lib64- -freetype-dir =/usr/lib64

(Mysql is installed through the rpm provided by the official website. Note that the rpm must be installed in addition to the server, client, share, and devel, the last one-with-mysql-with-libdir =/usr/lib64 has been successfully tried for a long time)
. /Configure-prefix =/opt/php-with-apxs2 =/usr/sbin/apxs-with-libxml-dir =/usr/lib64-with-pdo-mysql =/usr/bin /mysql-with-mysqli =/usr/bin/mysql_config-with-mysql-with-libdir =/usr/lib64-with-gd-enable-gd-native-ttf- -zlib-with-mcrypt-enable-shmop-enable-soap-enable-sockets-enable-wddx-enable-zip-with-xmlrpc-enable-fpm-enable-mbstring- -zlib-dir-with-bz2-with-curl-enable-exif-enable-ftp-with-jpeg-dir =/usr/lib64-with-png-dir =/usr/lib64 -with-freetype-dir =/usr/lib64

If you cannot find apxs from apache2.2 that comes with centos5.8, you can install yum install httpd-devel.

Sudo make
Sudo make install

See the following output. has been added to the modules directory of httpd, and httpd. conf has been updated.
Installing php sapi module: apache2handler
/Usr/lib64/httpd/build/instdso. sh SH_LIBTOOL = '/usr/lib64/apr-1/build/libtool '
/Usr/lib64/apr-1/build/libtool-mode = install cp
Cp. libs/
Cp. libs/libphp5.lai/usr/lib64/httpd/modules/
Libtool: install: warning: remember to run 'libtool-finish/home/milton/backup/php-5.5.13/libs'
Chmod 755/usr/lib64/httpd/modules/
[Activating module 'php5 'in/etc/httpd/conf/httpd. conf]

Add php. conf under/etc/httpd/conf. d and write the following lines:
# PHP is an HTML-embedded scripting language which attempts to make it
# Easy for developers to write dynamically generated webpages.
DirectoryIndex index. php

AddType application/x-httpd-php. php. phtml
AddType application/x-httpd-php-source. phps

Restart httpd

Sudo cp/data/backup/php-5.4.26/php. ini-production/opt/php/etc/php. ini
This is incorrect. If you do not specify a path (-with-config-file-path =/opt/php/etc), you can see it in phpinfo, this path points to/opt/php/lib, so you have to put it in/opt/php/lib. Otherwise, the subsequent modifications will not work.

Additionally, modify sudo vim conf/httpd. conf as needed (you do not need to modify the file already in php. conf)

1. Add php support.

AddType application/x-httpd-php. php. phtml
AddType application/x-httpd-php-source. phps

2. Click "index. php" next to "index. php" on the index page"

DirectoryIndex index.html index. php

3. If the directory structure is not displayed, find "Options Indexes FollowSymLinks" and change it

Options FollowSymLinks

4. Enable Apache to support pseudo-static state. Find "AllowOverride None" and change it

AllowOverride All

Httpd enables non-80 ports

Because of selinux restrictions
Starting httpd: (13) Permission denied: make_sock: cocould not bind to address [:]: 10080
(13) Permission denied: make_sock: cocould not bind to address 10080
No listening sockets available, shutting down
Unable to open logs
You can view the current port status through sudo/usr/sbin/semanage port-l
(Check whether selinux is Enabled: sudo/usr/sbin/sestatus)
(View selinux status: sudo/usr/sbin/getenforce)
(Set selinux status: sudo/usr/sbin/setenforce 0 or 1)
Semanage port-a-t http_port_t-p tcp 10080
Add, system prompt/usr/sbin/semanage: Port tcp/10080 already defined
Sudo/usr/sbin/semanage port-l | grep 10080
Amanda_port_t tcp 10080,100 81, 10082,100 83
Amanda_port_t udp 10080,100 81
Semanage port-a-t http_port_t-p tcp 10088

Install memcached php Extension

Sudo yum install gcc44 gcc44-c ++ libstdc ++ 44-devel
These must be installed. Otherwise, libmemcached will report an error (error: cinttypes: No such file or directory) during make)

Install libmemcached first (this is a client class library of memcache, which is used to compile pecl memcached)
Tar-zxvf libmemcached-1.0.18.tar.gz
Cd libmemcached-1.0.18
CC = gcc44 CXX = g ++ 44./configure // Replace the compiler with gcc44.
Sudo make
Sudo make install

Sudo yum install cyrus-sasl-devel

Sudo yum install autoconf
This must be installed because phpize is required

Tar-zxvf memcached-2.1.0.tgz
Cd memcached-2.1.0
./Configure-enable-memcached-with-php-config =/opt/php/bin/php-config-with-libmemcacheddir =/usr/local/lib
The above is wrong. I tried it for half a day. If the parameter is incorrect, this directory should also be well-noted. The file that must be included is include/libmemcached/memcached. h (note the path !), Otherwise, an error occurs: error: Can't find libmemcached 1.0.x headers.
The following is true:
./Configure-enable-memcached-with-php-config =/opt/php/bin/php-config-with-libmemcached-dir =/usr/local/

Then make, make install,
Open/opt/php/lib/php. ini and find
; Directory in which the loadable extensions (modules) reside.
; Extension_dir = "./"
The above line uncomment, replace with the path provided at the end of make install, usually extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20121212 /"
Extension = memcached. so

After restarting httpd, we found that memcached was not enabled. Check the httpd error_log and find
PHP Warning: PHP Startup: Unable to load dynamic library '/opt/php/lib/php/extensions/no-debug-non-zts-20121212/memcached. so '-/opt/php/lib/php/extensions/no-debug-non-zts-20121212/memcached. so: failed to map segment from shared object: Permission denied in Unknown on line 0
This is an error caused by selinux security settings.
Disable selinux (sudo/usr/sbin/setenforce 0) and restart httpd. memcached can be used.
Solution, see
View the Security Information of the so file:
-Rwxr-xr-x root user_u: object_r: usr_t memcached. so
Sudo/sbin/restorecon/opt/php/lib/php/extension/ no-debug-non-zts-20121212/memcached. so
View again
-Rwxr-xr-x root system_u: object_r: lib_t memcached. so
-Rwxr-xr-x root user_u: object_r: usr_t opcache.
-Rwxr-xr-x root user_u: object_r: usr_t opcache. so
Enable selinux
Sudo/usr/sbin/setenforce 1
Restart httpd again.

Enable OPcache
Because opcache is already installed by default in PHP5.5, it is used to replace apc, but is not enabled.
You need to add
Zend_extension =/opt/php/lib/php/extensions/no-debug-non-zts-20121212/opcache. so
Note that zend_extension must be used
When you restart httpd, the above Permission denied in Unknown on line 0 problem will still be encountered. You can use restorecon to handle the same problem.

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