php开发入门


一、介绍

最近接了一单PHP开发的,以前总是听说PHP是最好的开发语言,上手很快。
这次终于有机会用起来了。它是一个服务端的脚本语言。语法比较简单。

二、环境搭建

我本地的开发用的系统是ubuntu 18.04。以下环境搭建,基于linux系统。

  1. Web Server
    可以安装Apache2: sudo apt install apache2
    也可以用nginx: sudo apt install nginx

  2. php运行环境
    sudo apt install php php-fpm

  3. 配置Web Server,使用php处理器
    我在第一步选用的是nginx,修改nginx的配置: sudo vim /etc/nginx/nginx.conf

server {
listen 80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com;

location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}

location ~ /\.ht {
deny all;
}
}

修改完配置,需要重启nginx服务或者重新加载配置: sudo service nginx restart

参考: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04

三、第一个程序

在/var/www/html下新建一个文件hello.php, 粘贴以下内容:

<!DOCTYPE html>
<html>
<body>

<?php
echo "Hello world!";
?>

</body>
</html>

打开浏览器,输入 “http://example.com/hello.php“ 即可访问Hello World页面。

四、学习资料

w3school上提供了很多语法参考资料,还有测试,非常方便学习和参考。
https://www.w3schools.com/php/


文章作者: IT神助攻
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 IT神助攻 !
  目录