Let's say I have a local apache2 and I need a script that runs the apache2 with a special injected VirtualHost.
More presice:
I have a xampp Installation (PHP 7.3.10, MariaDB 10.4.8, mysqlnd 5.0.12-dev, Apache 2.4.41) on Windows 10.
Several PHP projects are located all over the hard drive. Until now I modify the ./apache/conf/extra/httpd-vhosts.conf file before starting the apache2 service on every project switch. With that I can leave the project folders where there are without copying them in the xampp installation folder.
Now I am curious if I can write a script for each project (bat or sh, GitShell is installed) that will run mariadb normally and apache2 with a temporarily VirtualHost for that specific project folder as DocumentRoot.
What I currently can do:
Lay down a httpd-vhosts.conf file and a startProject.sh script in a project folder. Running the script will copy the configuration file in the xampp installation and then start the apache2 service.
That is working, but only one apache2 process can start and not multiple projects at once.
What I want:
I want to use a parameter that specifies a VirtualHost by parameter when starting apache2.
Maybe by saying apache2 to use a special config file rather then the file in the own project structure.
Or I want to use a parameter by starting the apache2 process that specifies a alternatie DocumentRoot Folder for a already specified VirtualHost.
Currently this is my approach:
#!\bin\bash
BASEDIR=$(dirname "$0")
xamppPath="C:\xampp\v7.3.10"
cd $xamppPath
"apache\bin\httpd.exe" -S "$BASEDIR\httpd-vhosts.conf" &
But -S only prints out the VirtualHosts, not setting the configuration file.
How can I achieve running a project with a script somewhere on my harddrive without overriding the existing configuration file in the xampp installation folder?
Easier: build a couple of congratulation files, use option -f to specify an effective configuration file, not -S.
Can be more complicated: user -D name and use <IfDefine name> in the configuration file to "select" sections of it to apply to a particular start.
Note: I use apachectl, not directly httpd to start/stop Apache.
In the xampp package there is no direct apachectl file, so a use of -D <name> is not possible for me. It would be the perfect solution, but unfortunately not possible.
Now I have to override the httpd-vhosts.conf file from every project I want to start it. Therefore, I am using a modified script solution:
#!\bin\bash
BASEDIR=$(dirname "$0")
xamppPath="C:\xampp\v7.3.10"
cp -f "$BASEDIR\httpd-vhosts.conf" "$xamppPath\apache\conf\extra\httpd-vhosts.conf"
sleep 1
cd $xamppPath
"apache\bin\httpd.exe" &
It is not the perfect solution, but it works.
Two apache services at the same time with two different projects is not possible, but until now not necessary.
Related
I've cloned a PHP repository from git that actually is served in a server with Apache and I want to reproduce it locally. This repository is cloned in:
/home/me/test/repository
I've also installed Apache in my Ubuntu and it starts fine. Now, I need to do two things:
1. Load userdir, cgi and rewrite modules
For this, I loaded the modules by doing:
sudo a2enmod userdir
sudo a2enmod cgi
sudo a2enmod rewrite
But I don't know if have to do any extra thing :/
2. Serve the content of the repo
I have no idea of how to do this, because my logic tells me to keep the git structure to be able to push things after modifications.
I know that DocumentRoot is in /var/www/html and if I create a index.php with a simple instruction, it works fine. But how with the repo?
I'm using laravel valet to serve sites in my local dev env, which is great. However, there's only one file in the expected location of ~/.valet/Log:
➜ ls ~/.valet/Log
nginx-error.log
I've tinkered with php-fpm log settings and the nginx log settings, but I'm not sure that I'm even using the right config files, since I suspect that valet installs its own version of PHP and nginx.
Can any one tell me where the php / nginx config files for valet would be found, and what specific settings to change to drop the PHP error / log files where they're supposed to be written?
Hopefully this helps with your question about the nginx config files. You can find the nginx configuration for your sites by running cd ~/.config/valet/Nginx in your terminal. To get to the base nginx config for valet use cd /usr/local/etc/nginx/valet. You should then see valet.conf, inside you can update the following lines to put the log files where you want them.
access_log "/Users/[user_id]/.config/valet/Log/access.log";
error_log "/Users/[user_id]/.config/valet/Log/nginx-error.log";
Make sure to run valet restart after you make changes to the valet.conf file.
The NGINX configuration file should be available at /usr/local/etc/nginx/nginx.conf
I have got a project to work on that is based on laravel. I have unzipped the folder in my
/home/testsite/public folder and replaced the httpd.conf file which I have received.
Ran these two commands
chown -R username:group /home/testsite/public
chmod -R 777 /home/testsite/public/app/storage
But when I try to access localhost it shows default apache page, for other route url it shows 404 and it shows Forbidden when I try to access localhost/server.php
I have pasted my httpd.conf file here: http://pastebin.com/WLpFN7Sr
From your httpd.conf I see that your apache user is apache and its group is also apache. You can see that from these entries in the httpd.conf:
User apache
Group apache
Try this from within your project directory:
chown -R :apache .
I would also suggest that you not put virtual host or directory definitions inside of your httpd.conf. Most distributions have a good place already for you to put them, where you can store a single vhost inside of a single file. This makes it much easier when you want to enable one, disable another and general management becomes easier.
For instance, on ubuntu, I store all of my vhosts as separate files inside of:
/etc/apache2/sites-available/
I have installed macports and updated my path:
via docs:
http://guide.macports.org/#installing.shell.postflight
but now if I test any of the sites in my Sites folder, I get a 404.
so for instance if I go to localhost/~carey/test.php which is just a php_info, I get a 404
If I go to:
localhost/
I get the It Works! page
Am I missing a step to configure Macports to run apache from my Sites directory?
If I run $env from the command line I get:
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/rs/943jh19j31j3ld55yxqgf2mm0000gn/T/
Apple_PubSub_Socket_Render=/tmp/launch-NehzDd/Render
TERM_PROGRAM_VERSION=326
TERM_SESSION_ID=A329EAC2-AE9F-4460-BB1B-B35981BAE0ED
USER=carey
SSH_AUTH_SOCK=/tmp/launch-CgUaVv/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0:0
PATH=/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
__CHECKFIX1436934=1
PWD=/Users/carey
LANG=en_US.UTF-8
SHLVL=1
HOME=/Users/carey
LOGNAME=carey
SECURITYSESSIONID=186b0
_=/usr/bin/env
and I can run any macport install, but I cannot configure the terminal to connect to my localhost in the browser.
So I think I have macports installed correctly, but I dont know how to make it run out of the /opt directory.
I also think this is relative to establishing the env variables, so apache knows to look to the /opt dir, but I don't know how to change it.
I am running Mavericks.
UPDATE
Following the docs recommended by eborisch here:
https://trac.macports.org/wiki/howto/MAMP
I have been able to setup the localhost directory, but still an issue.
Since I have multiple users on the machine, I had to comment out this line in httpd.conf:
Include conf/extra/httpd-userdir.conf
and added this to the httpd-userdir.conf file:
#
# Include user configurations
#
Include /private/etc/apache2/users/*.conf
which connects my Sites folder to the localhost.
I also needed to add this to the httpd.conf file to parse php files as php:
AddType application/x-httpd-php .php
Now, I have a file in my Sites dir called test.php, which has <?php phpinfo() ?>
and if I run localhost/~carey/test.php in the browser it works. phpinfo() returns that I am running php5.5.10 out of the /opt/ dir. So, all seems well. The problem is if I try to run any sites from folders in this directory. It just displays the directory tree, rather than treating it like a site.
For instance if I run,
localhost/~carey/mysite
it just returns:
Index of /~carey/mysite
Parent Directory
2005/
2006/
index.php
../
If I run
localhost/~carey/mysite/index.php
it runs that file correctly (ie looks correct in the browser)
Seems like an .htaccess issue, but not sure how I would resolve that globally for each folder in the Sites directory
any suggestions?
Probably better served on https://lists.macosforge.org/mailman/listinfo/macports-users/ the macports mailing list. But some basics:
Is the osx web server running? (Web sharing under the sharing control panel?) If so, turn it off, or configure the two to use different ports.
Is the macports apache2 installed? (sudo port install apache2)
Is it running? (sudo port load apache2)
Have you edited its configuration (/opt/local/apache2/conf/httpd.conf)?
See https://trac.macports.org/wiki/howto/MAMP for instructions on getting things up and running.
I am new to Ubuntu Linux (version 13.10). I am following this tutorial to install MySQL, PHP, and Apache2.
It installed successfully, but I don't know where to write PHP files that execute when you navigate to the URL localhost/example.php.
I am looking at this link, but I am afraid that maybe it will not work and have to reinstall Ubuntu again.
In a newer version should be in a different path: /var/www/html
With a series of commands you can find:
ls /etc/apache2/sites-available/
That answers with something like
000-default.conf default-ssl.conf
In this case you need the second file default-ssl.conf; with
grep -n -e "DocumentRoot" /etc/apache2/sites-available/default-ssl.conf
you can obtain:
5: DocumentRoot /var/www/html
That means you can find (and change) DocumentRoot definition in the 5-th lines of the file /etc/apache2/sites-available/default-ssl.conf.
As a simple Google search would have showed you, it's (by default), /var/www/.
In the Ubuntu default config, that is defined in the default virtual host, the config file for that is /etc/apache2/sites-available/default
The default location of document root is /var/www. This, assuming you haven't touched the HTTPd configuration.
By the way, if you simply need a development server for PHP scripts, you can use the one emebedded in PHP > 5.4. Just cd to the project directory and launch:
php -S localhost:8008
In vscode (I'm sure in other editors as well) you can right click the file and copy path and copy relative path.
http://127.0.0.1:8000/site.php
Works for me.