lnmp服务一PHP部署

「爱情、让人受尽委屈。」 2022-05-17 04:16 307阅读 0赞

文章目录

  • 1.安装依赖于函数库
  • 2.安装PHP
    • 2.1解压php安装包
    • 2.2编译PHP
  • 3.配置PHP
    • 3.1修改配置文件
    • 3.2创建日志目录
    • 3.3设置环境变量
    • 3.4检查语法,启动php
  • 4.整合nginx与PHP
    • 4.1修改nginx配置文件
    • 4.2检查语法,启动nginx
    • 4.3编写php网页测试
    • 4.4网页查看
    • 4.5测试mysql连接

1.安装依赖于函数库

  1. [root@lnmp ~]# ll libiconv-1.14.tar.gz php-5.3.27.tar.gz
  2. -rw-r--r--. 1 root root 4984397 Aug 4 03:16 libiconv-1.14.tar.gz
  3. -rw-r--r--. 1 root root 15008639 Aug 4 00:29 php-5.3.27.tar.gz
  4. [root@lnmp ~]# yum install zlib gcc-c++ libjpeg freetype \
  5. libpng gd zlib-devel libxml2-devel libjpeg-devel freetype-devel \
  6. libpng-devel gd-devel curl-devel libxslt-devel openssl-devel -y
  7. [root@lnmp ~]# tar xf libiconv-1.14.tar.gz
  8. [root@lnmp ~]# cd libiconv-1.14
  9. [root@lnmp libiconv-1.14]# ./configure --prefix=/usr/local/libiconv-1.14
  10. [root@lnmp libiconv-1.14]# make && make install

2.安装PHP

2.1解压php安装包

  1. [root@lnmp ~]# tar xf php-5.3.27.tar.gz
  2. [root@lnmp ~]# cd php-5.3.27

2.2编译PHP

  1. [root@lnmp php-5.3.27]# ./configure --prefix=/usr/local/php \
  2. --with-mysql=mysqlnd --with-iconv-dir=/usr/local/libiconv \
  3. --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \
  4. --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode \
  5. --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization \
  6. --with-curl --with-curlwrappers --enable-mbregex --enable-fpm \
  7. --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl \
  8. --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap \
  9. --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl \
  10. --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp
  11. [root@lnmp php-5.3.27]# make && make install
  12. [root@lnmp php-5.3.27]# ln -s /usr/local/php/ /application/php

3.配置PHP

3.1修改配置文件

  1. [root@nginx php-5.3.27]# \cp php.ini-production /application/php/lib/php.ini
  2. [root@nginx php-5.3.27]# cd /application/php/
  3. [root@nginx ~]# egrep -v "^$|^;" /application/php/etc/php-fpm.conf|cat -n
  4. 1 [global]
  5. 2 pid = /app/logs/php-fpm.pid
  6. 3 error_log = /app/logs/php-fpm.log
  7. 4 log_level = error
  8. 5
  9. 6 rlimit_files = 32768
  10. 7
  11. 8 events.mechanism = epoll
  12. 9 [www]
  13. 10 user = nginx
  14. 11 group = nginx
  15. 12 listen = 127.0.0.1:9000
  16. 13 listen.owner = nginx
  17. 14 listen.group = nginx
  18. 15 pm = dynamic
  19. 16 pm.max_children = 1024
  20. 17 pm.start_servers = 16
  21. 18 pm.min_spare_servers = 5
  22. 19 pm.max_spare_servers = 20
  23. 20 pm.process_idle_timeout = 15s;
  24. 21 pm.max_requests = 2048
  25. 22 slowlog = /app/logs/$pool.log.slow
  26. 23 request_slowlog_timeout = 10
  27. 24 php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f 1093626742@qq.com

3.2创建日志目录

  1. [root@lnmp php]# mkdir /app/logs/ -p

3.3设置环境变量

  1. [root@lnmp php]# cp sbin/php-fpm /usr/local/sbin/

3.4检查语法,启动php

  1. [root@lnmp php]# php-fpm -t
  2. [06-Aug-2018 11:22:37] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
  3. [root@lnmp php]# php-fpm
  4. [root@lnmp php]# netstat -lntup|grep php
  5. tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 6625/php-fpm

4.整合nginx与PHP

4.1修改nginx配置文件

  1. [root@lnmp php]# vim /application/nginx/conf/nginx.conf
  2. 10 server {
  3. 11 listen 80;
  4. 12 server_name www.liang.com;
  5. 13 root html/www;
  6. 14 index index.php index.html index.htm;
  7. 15 location ~ \.php$ {
  8. 16 root html/www;
  9. 17 fastcgi_pass 127.0.0.1:9000;
  10. 18 fastcgi_index index.php;
  11. 19 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  12. 20 include fastcgi.conf;
  13. 21 }
  14. 22 }

4.2检查语法,启动nginx

  1. [root@lnmp php]# nginx -t
  2. nginx: the configuration file /usr/local/nginx-1.6.2/conf/nginx.conf syntax is ok
  3. nginx: configuration file /usr/local/nginx-1.6.2/conf/nginx.conf test is successful
  4. [root@lnmp php]# nginx -s reload

4.3编写php网页测试

  1. [root@lnmp php]# cat /application/nginx/html/www/index.php
  2. <?php
  3. phpinfo();
  4. ?>

4.4网页查看

这里写图片描述

4.5测试mysql连接

  1. [root@lnmp php]# cat /application/nginx/html/www/index.php
  2. <?php
  3. //$link_id=mysql_connect('主机名','用户','密码');
  4. $link_id=mysql_connect('localhost','root','000000') or mysql_error();
  5. if($link_id){
  6. echo "mysql successful by https://blog.csdn.net/liang_operations!";
  7. }else{
  8. echo mysql_error();
  9. }
  10. ?>

这里写图片描述

发表评论

表情:
评论列表 (有 0 条评论,307人围观)

还没有评论,来说两句吧...

相关阅读