Deploying Laravel to a subfolder in Apache.
To deploy Laravel to a subfolder in Apache, you need to follow these steps:
-
Prepare the Laravel project: Make sure you have a clean Laravel installation in your local development environment. You can create a new Laravel project using Composer by running the following command in your terminal:
composer create --prefer-dist laravel/laravel project-name
Replace "project-name" with the name of your Laravel project.
-
Configure the Laravel project: Open the ".env" file located in the root directory of your Laravel project and set the APP_URL variable to the subfolder URL where you want to deploy Laravel. For example, if you want to deploy Laravel to a subfolder named "myapp" in the "public_html" directory, set the APP_URL variable to:
APP_URL=http://example.com/myapp
Replace "example.com" with your domain name.
-
Create a new virtual host in Apache: Create a new configuration file for your Laravel project in the Apache "sites-available" directory. You can name it anything you like, but it's common to use the name of your domain or subfolder. For example, if your subfolder is named "myapp" and your domain name is "example.com", you can name the configuration file "myapp.conf".
Open the new configuration file in a text editor and add the following content:
<VirtualHost *:80> ServerName example.com/myapp ServerAdmin [email protected] DocumentRoot /path/to/your/project/public <Directory /path/to/your/project/public> AllowOverride All Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Replace "/path/to/your/project" with the absolute path to the root directory of your Laravel project.
-
Enable the new virtual host: Run the following command in your terminal to create a symbolic link to the new configuration file in the "sites-enabled" directory:
sudo ln -s /etc/apache2/sites-available/myapp.conf /etc/apache2/sites-enabled/
Restart Apache to apply the changes:
sudo systemctl restart apache2
-
Upload the Laravel project to the subfolder: Use an FTP client or SSH to upload the contents of your Laravel project to the subfolder in the "public_html" directory. Make sure the ownership and permissions of the files and directories are correct.
-
Access the Laravel project: Open your web browser and go to the URL of your Laravel project in the subfolder. For example, if your domain name is "example.com" and your subfolder is named "myapp", go to "http://example.com/myapp". Laravel should now be deployed to the subfolder in Apache.