我试图建立一个PHP网站,我想测试我的PHP文件,而不是上传到我的主机。基本上是在上传之前先在我自己的机器上测试。我怎么做呢?
当前回答
我用WAMP。一个简单的安装向导,为Apache和PHP预配置的大量模块,易于打开和关闭,以匹配您的远程配置。
其他回答
如果你有一台本地机器,有正确的软件:支持PHP的web服务器,没有理由你不能像你描述的那样做。
目前我正在一台Windows XP机器上使用XAMPP,(在家里)使用Kubuntu和LAMP堆栈。
另一种选择是Zend服务器社区版。
如果您正在使用Windows,那么WPN-XM服务器堆栈可能是一个合适的替代方案。
即使您的机器上有现有的服务器,也可以使用Docker。通过docker Run从任何终端运行一行代码:
docker run --name=php -d -it -p 80:80 --mount type=bind,source='/absolute/path/to/your/php/web/root/folder/',target=/app webdevops/php-nginx-dev
现在,您将有一个名为php的运行容器在本地主机端口80上为请求提供服务。您应该能够在使用url http://127.0.0.1的任何浏览器中看到您的php脚本
注:
If you don't have Docker installed, instructions for Debian/Ubuntu and Windows 10+ are at the end. It can be installed on Windows 7 but it's quite annoying and not worth it. For windows 7, if you must, I'd just install Uniserver or XAMPP or something like that. You can confirm that the container is live by running docker ps in a terminal on the host machine. In order to keep your app/code modifications after the container is terminated/removed, the web root is bound to the folder where you ran the docker run command. To change it, specify the path to your local folder in the --mount source='[/local/path]' parameter. Note: Because the folder is bound to the container, changes you make in the container will also be made in the host folder. Logs can be viewed using the following command (--follow is optional, ctrl+c to exit): docker logs php --follow The web root folder in the container is /app. This may be helpful if you don't need to save anything and don't feel like specifying a bind mount in the docker run command. The port is specified using the -p [host port]:80 parameters. You may have to explicitly specify -p 80:80 in order to be able to connect to the container from a web browser (at least on Windows 10). To access the container's bash terminal run this from the host machine (type exit to return to host): docker exec -it php /bin/bash You can install packages in the container's bash terminal the same way that you would on a native Debian/Ubuntu box (e.g. apt install -y nano). Composer is already installed (run composer -v from container's terminal to inspect) To launch an additional container, specify a different host port and container name using the --name=[new_name] and -p [host port]:80 parameters. If you need a database or other server, do the same thing with a docker image for MySQL or MariaDB or whatever you need. Just remember to bind the data folder to a host folder so you don't lose it if you accidentally delete your docker image(s). How to install Docker: Debian/Ubuntu as root (or add sudo before each of these commands): apt-get update apt install -y ca-certificates curl gnupg lsb-release mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null chmod a+r /etc/apt/keyrings/docker.gpg apt-get update apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin service docker start systemctl enable docker Windows 10+ (tested on 10, should work on >10): Use Chocolatey, a command-line package manager for Windows. Chocolatey also has a gui if you insist. Once installed, run: choco install -y docker-desktop Mac, Chromebook, etc: You are alone. But we believe in you.
如果你在MAC MAMP上