Skip to content

Instantly share code, notes, and snippets.

@Nav33d
Last active June 11, 2020 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nav33d/6982568607686da5aaf2092f5266aea4 to your computer and use it in GitHub Desktop.
Save Nav33d/6982568607686da5aaf2092f5266aea4 to your computer and use it in GitHub Desktop.
Setup apache on Laravel Homestead
####################################################################################################
# Apache Setup [copy and paste below code to the after.sh file in your project's folder]
# Set path to /var/www/html/project_name in Homestead.yml file
####################################################################################################
folder="tester" # Name of the project folder
phpVersion=5 # Enter 5 or 7
sudo service nginx stop
sudo apt update
sudo apt install apache2 -y
if [ "$phpVersion" -eq "5" ]; then
echo "Installing PHP5 mod"
sudo DEBIAN_FRONTEND=noninteractive apt install php5.6 php5.6-mysql php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-imagick libapache2-mod-php5.6 -y
else
echo "Installing PHP7 mod"
sudo DEBIAN_FRONTEND=noninteractive apt install libapache2-mod-php -y
fi
sudo a2enmod rewrite
sudo rm -f /etc/apache2/sites-enabled/*
sudo rm -f /etc/apache2/sites-available/*
block="<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
ServerName localhost
DocumentRoot /var/www/html/$folder/public
<Directory "/var/www/html/$folder/public">
Require all granted
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
"
echo "$block" > "/etc/apache2/sites-available/$folder.conf"
ln -fs "/etc/apache2/sites-available/$folder.conf" "/etc/apache2/sites-enabled/$folder.conf"
sed -i '/export APACHE_RUN_USER=www-data/c\export APACHE_RUN_USER=vagrant' /etc/apache2/envvars
sed -i '/export APACHE_RUN_GROUP=www-data/c\export APACHE_RUN_GROUP=vagrant' /etc/apache2/envvars
sudo a2enmod headers
sudo service apache2 restart
@joshangell
Copy link

joshangell commented Nov 1, 2016

Line 15 didn’t work for me, I had to do this:

sudo DEBIAN_FRONTEND=noninteractive apt install php5.6 php5.6-mysql php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-imagick libapache2-mod-php5.6 -y

@Nav33d
Copy link
Author

Nav33d commented Nov 5, 2016

Thanks Josh! I have updated the gist.

@joshangell
Copy link

Ignore that ... me being a plonker :|

@WhiskyWonka
Copy link

Thanks!
y paste this code to after.sh and apache is running but nothing y /etc/apache2/sites-enable or sites-available
just empty directories

any sugestion?
Thanks again

@WhiskyWonka
Copy link

homestead: /tmp/vagrant-shell: 90: /tmp/vagrant-shell: cannot create /etc/apache2/sites-available/homestead.text.conf: Permission denied

i tryed adding sudo to the line:
sudo echo "$block" > "/etc/apache2/sites-available/$servername.conf"

but doen't work

Thanks

@phpfui
Copy link

phpfui commented Jun 11, 2020

Since I had already run vagrant provision, it already created the appropriate conf files. I just needed to update the conf files. I was getting an permission denied error on the ln -fs line, but since the link was already created, I could simply comment it out, as it was no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment