三、部署php
1.依赖环境
yum install gcc gcc-c++ make zlib-devel libxm12-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-develgd-devel libcurl-devel libxslt-devel libxslt-devel -y
2.下载php源码
wget http://mirrors.sohu.com/php/php-7.3.5.tar.gz
解压源码安装
tar -zxvf php-7.3.5.tar.gz cd php-7.3.5 ./configure --prefix=/usr/local/php7.3.5 --with-mysql-sock=/tmp/mysql.sock --with-mysqli --with-iconv-dir=/usr/local/libiconv --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-mbregex --enable-fpm --enable-mbstring --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp --enable-opcache=no make && make install
3.配置文件
vimdiff php.ini-development php.ini-production
看下两个配置文件的区别(一个用于生产,一个用于开发)
我们用开发版本的
cp php.ini-development /usr/local/php7.3.5/lib/php.ini
4.cp模板配置文件
生成新的php配置文件
有关FASTCGI配置文件
cd /usr/local/php7.3.5/etc/ cp php-fpm.conf.default php-fpm.conf ls
cd php-fpm.d cp www.conf.default www.conf
5.启动php服务指定fastcgi形式
cd /usr/local/php7.3.5/sbin ./php-fpm netstat -tunlp | grep php
6.修改nginx支持php代码
vim /opt/nginx-1.16.0/conf/nginx.conf
写入
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; include extra/my_php.conf; }
配置虚拟主机的部分
cd /opt/nginx-1.16.0/conf/ mkdir extra cd extra/ vim /opt/nginx-1.16.0/conf/extra/my_php.conf
server { listen 80; server_name _; location / { root html; index index.html; } #添加有关php程序的解析 location ~ .*\.(php|php5)?$ { root html/myphp; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } }
7.创建php的首页脚本文件
mkdir -p /opt/nginx-1.16.0/html/myphp echo "<?php phpinfo(); ?>" >/opt/nginx-1.16.0/html/myphp/index.php
8.测试验证
nginx -t nginx -s reload
访问一下
成功
四、测试php和MySQL链接
1.编写php脚本
vim /opt/nginx-1.16.0/html/myphp/test_mysql.php
<?php $link_id=mysqli_connect('localhost','root','123456') or mysql_error(); if($link_id){ echo "mysql-server was connected by mysqli_connect"; }else{ echo "something wrong this php or mysql"; } ?>
五、lnmp环境搭建wordpress
1.创建用于wordpress博客的数据库
mysql -u root -p
进入数据库创建wordpress数据库;创建wordpress专用数据库用户;给用户本地登录授权和密码
create database wordpress; create user wordpress; grant all on wordpress.* to wordpress@'localhost' identified by '123456'; FLUSH PRIVILEGES; quit
2.下载和安装源码
wget https://wordpress.org/wordpress-5.3.2.tar.gz tar -zxvf wordpress-5.3.2.tar.gz
3.移动博客代码到首页
mv -rf wordpress/* /opt/nginx-1.16.0/html/myphp/ cd /opt/nginx-1.16.0/html/myphp/ ls
mv -rf wordpress/* /opt/nginx-1.16.0/html/myphp/ cd /opt/nginx-1.16.0/html/myphp/ ls
改下权限
cd /opt/nginx-1.16.0/html/myphp/ chown -R nginx.nginx ./
4.查看下
nginx -s reload
成功
5.初始化配置
和刚刚数据库创建的库和用户名密码一样
填写博客标题和一些默认信息
完成!