安装php前的准备工作
当mysql服务器不在本地服务器时
我们可以不在本机进行mysql的编译安装
但是我们要解压mysql编译安装包放在/usr./local/mysql下
cd /usr/local
tar -xf mysql-5.5.32-linux2.6-x86_64.tar.gz
ln -sv mysql-5.5.32-linux2.6-x86_64 mysql
php5.3编译安装
系统:Centos 7.2
yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel libevent libevent-devel -y
cd /usr/local
编译libiconv库
tar xf libiconv-1.14.tar.gz
cd /usr/local/libiconv-1.14
./configure --prefix=/usr/local/libiconv
cd /usr/local/libiconv-1.14/srclib/
sed -i -e '/gets is a security/d' ./stdio.in.h
cd ../
make && make install
cd ../
编译 libmcrypt
tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
sleep 2
/sbin/ldconfig
cd /usr/local/libmcrypt-2.5.8/libltdl/
./configure --enable-ltdl-install
make && make install
cd ../../
编译mash
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make && make install
sleep 2
cd ../
echo "/usr/local/mhash/lib" > /etc/ld.so.conf.d/mhash.conf
#vim /etc/ld.so.conf.d/mhash.conf
/usr/local/mhash/lib
ldconfig -v
编译mcrypt
tar zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure LD_LIBRARY_PATH=/usr/local/lib
make && make install
cd ../
sleep 2
编译PHP
cd /usr/local
tar xf php-5.5.38.tar.gz
cd /usr/local/php-5.5.38/
./configure \
--prefix=/usr/local/php \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-iconv-dir=/usr/local/libiconv \
--with-config-file-scan-dir=/etc/php.d \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-signals \
--enable-static \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-opcache=no \
--enable-ftp
'./configure' '--prefix=/usr/local/php' '--with-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-iconv-dir=/usr/local/libiconv' '--with-config-file-scan-dir=/etc/php.d' '--with-freetype-dir' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--enable-fpm' '--enable-mbstring' '--with-mcrypt' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--enable-short-tags' '--enable-static' '--with-fpm-user=nginx' '--with-fpm-group=nginx' '--enable-opcache=no' '--enable-ftp'
如果报错 可以尝试下面
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl
make
make test
make install
没有报错进行下一步
cd /usr/local/php-5.5.38
为php提供配置文件:
# cp php.ini-production /etc/php.ini
为php-fpm提供Sysv init脚本,并将其添加至服务列表:
#cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
为php-fpm提供配置文件:
cp /usr/local/php-5.5.38/sapi/fpm/php-fpm.conf.in /usr/local/php/etc/php-fpm.conf
编辑php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pid = /usr/local/php/var/run/php-fpm.pid
接下来就可以启动php-fpm了:
service php-fpm start
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# ps aux | grep php-fpm
注意修改下面配置文件
cp /usr/local/php-5.5.38/sapi/fpm/php-fpm.conf.in /usr/local/php/etc/php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = nginx
group = nginx
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 1024
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 16
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 5
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 20
; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
;pm.process_idle_timeout = 15s;
; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
;pm.max_requests = 2048
php-fpm -t #### 检查下php-fpm配置是否有错误
[09-Feb-2017 20:38:22] NOTICE: configuration file /etc/php-fpm.conf test is successful
启动php-fpm
service php-fpm start
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# ps aux | grep php-fpm
root 1368 0.0 0.1 196428 5188 ? Ss 20:23 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nginx 1369 0.0 0.1 198512 4716 ? S 20:23 0:00 php-fpm: pool www
nginx 1370 0.0 0.1 198512 4716 ? S 20:23 0:00 php-fpm: pool www
nginx 1371 0.0 0.1 198512 4716 ? S 20:23 0:00 php-fpm: pool www
nginx 1372 0.0 0.1 198512 4716 ? S 20:23 0:00 php-fpm: pool www
nginx 1373 0.0 0.1 198512 4716 ? S 20:23 0:00 php-fpm: pool www
nginx 1374 0.0 0.1 198512 4716 ? S 20:23 0:00 php-fpm: pool www
nginx 1375 0.0 0.1 198512 4716 ? S 20:23 0:00 php-fpm: pool www
nginx 1376 0.0 0.1 198512 4716 ? S 20:23 0:00 php-fpm: pool www
root 1602 0.0 0.0 112660 964 pts/0 S+ 20:44 0:00 grep --color=auto php-fpm
四、整合nginx和php5
1、编辑/etc/nginx/nginx.conf,启用如下选项:
location ~ .*.(php|php5)?$
{
proxy_pass http://127.0.0.1:1081;
break;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
或者
rewrite ^(.*)$ /index.php$1 last;
}
location ~ .*\.php(\/.*)*$
{
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
并在所支持的主页面格式中添加php格式的主页,类似如下:
location / {
root html;
index index.php index.html index.htm;
}
而后重新载入nginx的配置文件:
# service nginx reload
3、在/usr/html新建index.php的测试页面,测试php是否能正常工作:
# cat > /usr/html/index.php << EOF
<?php
phpinfo();
?>
接着就可以通过浏览器访问此测试页面了。
安装xcache,为php加速:
1、安装
# tar xf xcache-2.0.0.tar.gz
# cd xcache-2.0.0
# /usr/local/php/bin/phpize
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make && make install
安装结束时,会出现类似如下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
2、编辑php.ini,整合php和xcache:
首先将xcache提供的样例配置导入php.ini
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d
说明:xcache.ini文件在xcache的源码目录中。
接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。
3、重新启动php-fpm
# service php-fpm restart
六、补充说明
如果要在SSL中使用php,需要在php的location中添加此选项:
fastcgi_param HTTPS on;
补充阅读材料:
Events is one of paradigms to achieve asynchronous execution. But not all asynchronous systems use events. That is about semantic meaning of these two - one is super-entity of another.
epoll and aio use different metaphors:
epoll is a blocking operation (epoll_wait()) - you block the thread until some event happens and then you dispatch the event to different procedures/functions/branches in your code.
In AIO you pass address of you callback function (completion routine) to the system and the system calls your function when something happens.
Problem with AIO is that your callback function code runs from system thread and so on top of system stack. A few problems with that as you can imagine.
/etc/rc.local这是使用者自订开机启动程序,把需要开机自动运行的程序写在这个脚本里
我们把mysql php nginx放在里面
vim /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
/etc/init.d/mysqld start
php-fpm
/etc/init.d/nginx start
查看php-fpm端口
netstat -lntup | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2458/php-fpm: mast
php结合nginx
编辑/etc/nginx/nginx.conf
修改范例如下:
sed -n '67,74p ' /etc/nginx/nginx.conf.bak
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
去除文档里的#
sed -e '65,72s/#//g' /etc/nginx/nginx.conf.bak
sed -i '65,72s/#//g' /etc/nginx/nginx.conf.bak
sed -n '65,72p' /etc/nginx/nginx.conf.bak
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
vim etc/nginx/nginx.conf修改后的范例如下:
server {
listen 80;
server_name localhost;
#root /var/www/html;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#root /var/www/html;
charset utf-8;
#access_log logs/host.access.log main;
access_log syslog:server=10.1.41.53:514,facility=local7,tag=nginx,severity=info;
#location / {
# root /var/www/html;
# index index.html index.htm;
#}
root html;
index index.php index.html index.htm;
#location / {
# root html;
#autoindex on;
#autoindex_exact_size off;
#autoindex_localtime on;
# index index.php index.html index.htm;
#}
location ~ .*.(php|php5)?$
{
proxy_pass http://127.0.0.1:1081;
break;
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
配置网站默认页
vim /etc/nginx/html/index.php
<?php
phpinfo();
?>
检查nginx配置
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
重载nginx
nginx -s reload
- 编辑Apache的网页测试php是否可以连接MySQL、
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
打开浏览器进行web测试访问
# curl 10.1.41.65
Success...
错误说明
今天在centos 7.2 64位版本上安装PHP5.5时在./configure 步骤的时候出现了下面错误
configure: error: Cannot find libmysqlclient under /usr.
Note that the MySQL client library is not bundled anymore!
原因分析与解决
通过查找libmysqlclient,发现是在/usr/lib64/mysql/目录内的libmysqlclient.so.15.0.0做的软连接,PHP默认是去的/usr/lib/搜索,所以没有找到.
解决办法就是:
cp /usr/lib64/mysql/* /usr/lib/mysql/
然后进行./configure即可,如果服务器没有/usr/lib/mysql/ 目录,则在/usr/lib/目录下创建mysql目录即可