When you use php artisan serve, Laravel starts a development server on a specific port, typically 8000. However, when you want to deploy your Laravel application on Apache, you’ll need to follow these steps:
- Install Apache:
If you haven’t installed Apache yet, you can do so using your system’s package manager. For example, on Ubuntu, you can run:
sudo apt-get update
sudo apt-get install apache2
- Enable Apache Modules:
Make sure that the required Apache modules are enabled. You’ll needrewrite
for Laravel’s pretty URLs:
sudo a2enmod rewrite
- Configure Apache:
Create a new virtual host configuration file for your Laravel application. For example, you can create a file namedlaravel.conf
in the Apache sites-available directory:
sudo nano /etc/apache2/sites-available/laravel.conf
Add the following configuration:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /path/to/your/laravel/public
ServerName yourdomain.com
<Directory /path/to/your/laravel/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Replace /path/to/your/laravel
with the actual path to your Laravel project and update ServerName
with your domain or IP address.
- Enable the Virtual Host:
Enable the virtual host configuration:
sudo a2ensite laravel.conf
- Restart Apache:
After making changes, restart Apache to apply the configurations:
sudo service apache2 restart
- Update hosts file (if needed):
If you’re using a local development environment and not a domain, you might need to update your system’s hosts file. Open the hosts file:
- On Linux:
sudo nano /etc/hosts
- On Windows:
C:\Windows\System32\drivers\etc\hosts
Add an entry like:
127.0.0.1 yourdomain.com
Replace yourdomain.com
with the ServerName you specified in your Apache configuration.
- Access your Laravel Application:
Open your web browser and navigate to the URL or IP address you’ve configured in your Apache virtual host. If everything is set up correctly, you should see your Laravel application.
That’s it! You’ve now deployed your Laravel application on Apache. Keep in mind that these instructions might need adjustments based on your specific server environment and Laravel version.