In fact, there are several ways. The first, banal - use a local Apache. The method is good, but for normal development it is very inconvenient and you described one of the examples of inconvenience. You can go ahead and make yourself a folder in your home directory and fix the Apache config, but this is also bad. Therefore, I will not even describe this method in detail.
A more advanced way is to use a real server. But he is also bad. The server is usually not free and logs with access. But I saw a man who made himself a cluster on a raspberry pi and was happy. And also purchased a dozen sdcard, which stores various distributions.
And the easiest and right way is to use docker. Consider the pros:
- it is very easy to assemble the necessary configuration (database with the correct version, apache with the correct config, the necessary axis).
- If you write a compose file, it is very easy to transfer it to your “neighbor” or admin, so that you can expand it to yourself.
- It is easy to keep several different "sites", and not to fence the city with configs.
- Docker is available not only for Linux, but also for MacOS, and recently became available for Windows, and this allows a lot.
- Many hosters now provide hosting for the docker. That is, the process of uploading your site to such a hosting comes down to copying the dockerfile or compose file and launching it.
How to set it all up and run. First of all, you need to put a docker and, preferably, docker-compose
. Here, read the mana to your axis.
Next, you need to decide how to "fill sortsy." There are several ways.
- hardcore - install vim / nano / emax in docker and develop it directly in it. But this is for lovers. But this method has its advantages. The development environment can easily migrate between computers.
- plain. Docker image can use the folder from the host machine. That is, the folder with the project is connected to the docker. There are two ways to do this - either just connect to the docker file (
ADD /host/path /path/inside/docker/container
) or when starting the container ( docker run -v /host/directory:/container/directory ...
). And you can copy files when starting the container. If everything is correctly put together, then everything will live in a container and in a working directory. And if the docker is properly configured, then even root rights are not needed. - complex but beautiful. A beautiful and correct way is to build your deployment system. This method is unnecessary for small projects, but pays off for more complex ones. At the very beginning, a script is written that can upload files and perform the necessary manipulations (set permissions, restart apache, edit the database). And the script itself is launched either by hand or clings to the hook / commit.
And now, a list of useful links.
- the docker site itself.
- how to set up an environment to work with apache, pkhp and muscle .
- and one more article on this topic docker for php developers .
- article on Habré, which also describes how to configure dnsmask, which allows you to make a local dns and test their work with real addresses and without modifying the hosts file.