Skip to content

Instantly share code, notes, and snippets.

@nadyshalaby
Last active August 8, 2024 21:38
Show Gist options
  • Save nadyshalaby/15ecaf02e1d90cc871554eb6b9d91e0e to your computer and use it in GitHub Desktop.
Save nadyshalaby/15ecaf02e1d90cc871554eb6b9d91e0e to your computer and use it in GitHub Desktop.
How to setup apache2 virtual host for laravel project
# -----------------( Terminal ) -------------------
cd /path/to/project/directory
sudo usermod -aG www-data $(whoami) # use 'webapp' instead of 'www-data' if you are using AWS
sudo chown -R $(whoami):www-data .
sudo find . -type f -exec chmod 0664 {} \;
sudo find . -type d -exec chmod 0775 {} \;
sudo chmod -R g+s .
sudo vi /etc/apache2/sites-available/example.local.conf
sudo a2ensite example.local.conf
# --------------( example.local.conf ) ----------------
<VirtualHost *:80>
ServerName example.local
ServerAdmin webmaster@localhost
ServerAlias example.local
DocumentRoot /path/to/project/directory/public
DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /path/to/project/directory/public>
Options -Indexes +MultiViews +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
# -----------------( Different Ports ) -------------------
Listen 8082
<VirtualHost *:8082>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/mismar/app
DirectoryIndex index.php
ErrorLog /var/log/mismar/app/error.log
CustomLog /var/log/mismar/app/access.log combined
<Directory /var/www/html/mismar/app>
Options -Indexes +MultiViews +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
<FilesMatch \.php$>
# For Apache version 2.4.10 and above, use SetHandler to run PHP as a fastCGI process server
SetHandler "proxy:unix:/run/php/phpr8.0-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
# -----------------( Terminal ) -------------------
sudo a2enmod rewrite
sudo service apache2 restart
sudo vi /etc/hosts
# --------------( /etc/hosts ) ----------------
127.0.0.1 example.local
# Default server configuration
#
server {
root /var/www/html/staging.suplift.com/app;
index index.php;
server_name staging.suplift.com;
access_log /var/log/nginx/staging.suplift.com-access.log;
error_log /var/log/nginx/staging.suplift.com-error.log error;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /.well-known/acme-challenge/ {
root /var/www/html/staging.suplift.com/app;
allow all;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/staging.suplift.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/staging.suplift.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
server {
if ($host = staging.suplift.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name staging.suplift.com;
return 404; # managed by Certbot
}
sudo sed -i 's/upload_max_filesize = .*/upload_max_filesize = 32M/' /etc/php/7.4/fpm/php.ini
sudo sed -i 's/post_max_size = .*/post_max_size = 256M/' /etc/php/7.4/fpm/php.ini
sudo sed -i 's/memory_limit = .*/memory_limit = -1/' /etc/php/7.4/fpm/php.ini
sudo sed -i 's/max_execution_time = .*/max_execution_time = 300/' /etc/php/7.4/fpm/php.ini
sudo sed -i 's/max_input_time = .*/max_input_time = 300/' /etc/php/7.4/fpm/php.ini
sudo sed -i 's/max_input_vars = .*/max_input_vars = 300/' /etc/php/7.4/fpm/php.ini
sudo systemctl reload php7.4-fpm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment