【php配置文件】
配置文件路徑在源碼解壓縮包里
[root@web01 php-7.3.5]# pwd
/mytools/php-7.3.5
[root@web01 php-7.3.5]# ll php.ini*
-rw-r--r-- 1 1000 1000 71648 Apr 30 2019 php.ini-development
-rw-r--r-- 1 1000 1000 71920 Apr 30 2019 php.ini-production
以上兩個配置文件分別用於開發環境已經生產環境,配置參數有所不同
# 可以用如下命令對比文件區別
[root@web01 php-7.3.5]# vimdiff php.ini-development php.ini-production
開發環境下開起了更多的日志、調試信息,生產環境該參數都關閉了
拷貝PHP配置文件到PHP默認目錄,並且改名
[root@web01 php-7.3.5]# cp php.ini-development /opt/php/lib/php.ini
【fastcgi的配置文件】
1.默認FastCGI的配置文件路徑
[root@web01 etc]# pwd
/opt/php/etc
[root@web01 etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
2.生成2個php-frpm的配置文件,先用默認配置,后續可以再后話
[root@web01 etc]# cp php-fpm.conf.default php-fpm.conf
[root@web01 etc]# cp php-fpm.d/www.conf.default php-fpm.d/www.conf
【啟動PHP服務】(以fastcgi形式)
# 以絕對路徑啟動服務,並且檢查狀態
[root@web01 etc]# /opt/php/sbin/php-fpm
[root@web01 etc]# netstat -tunlp|grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 109647/php-fpm: mas
【修改nginx支持php】
1.修改nginx配置文件,在最底行添加 包含文件參數,建議刪除nginx.conf原有的server配置
[root@web01 conf]# vim /opt/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
include extra/*.conf;
}
【配置php的解析配置文件】
[root@web01 conf]# mkdir extra
[root@web01 conf]# vim extra/my_php.conf
server {
listen 80;
server_name -;
location / {
root html;
index index.html;
}
#添加有關php程序的解析
location ~ .*\.(php|php5)?$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
【檢查並且重啟nginx】
[root@web01 extra]# nginx -t
nginx: the configuration file /opt/nginx-1.16.0//conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx-1.16.0//conf/nginx.conf test is successful
[root@web01 extra]# nginx -s reload
【測試LNMP環境】
[root@web01 conf]# mkdir -p /opt/nginx/html/blog
[root@web01 conf]# echo "<?php phpinfo(); ?>" > ../html/index.php
[root@web01 conf]#
當看到如下界面,說明LNMP環境已經能夠正確解析
【測試PHP訪問mysql】
[root@web01 conf]# cat ../html/test_mysql.php
<?php
$link_id=mysqli_connect('localhost','root','chaoge666') or mysql_error();
if($link_id){
echo "mysql successful by chaoge.\n";
}else {
echo mysql_error();
}
?>