How to setup Laravel on Ubuntu using Apache2 engine with a MYSQL database.
Ubuntu, Apache, Apache2, Laravel, 2019, 2020, OVH, MYSQL
sudo apt install apache2
sudo apt-get update
sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service
sudo apt install php7.2 libapache2-mod-php7.2 php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-cli php7.2-zip php7.2-mysql php7.2-curl
or
sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-xml php-cli php-zip php-mysql php-curl
Ensure you do "php -v" and replace "7.2" with whatever version you recieve.
sudo nano /etc/php/7.2/apache2/php.ini
memory_limit = 256M
upload_max_filesize = 64M
cgi.fix_pathinfo=0
sudo apt install curl
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
cd /var/www/html
git clone https://github.com/username/project.git
sudo chown -R www-data:www-data /var/www/html/project/
sudo chmod -R 755 /var/www/html/project/
sudo nano /etc/apache2/sites-available/laravel.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/project/public
ServerName project.io
<Directory /var/www/html/project/public>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2dissite 000-default.conf
sudo a2ensite laravel.conf
sudo a2enmod rewrite
sudo service apache2 restart
sudo systemctl restart apache2.service
sudo ufw allow ssh
sudo ufw allow "Apache Full"
sudo ufw allow https
sudo ufw allow http
sudo apt install mysql-server
sudo mysql_secure_installation
sudo ufw status numbered
Password Plugin: Y
Password Validation Policy: 1 (can be 2 if you want)
(Enter Password and save somewhere)
Continue with Password: Y
Remove Anonymous Users: Y
Disallow Root Login Remotely: N
Remote Test DB: Y
Reload Privileges: Y
sudo mysql -u root -p
CREATE DATABASE db_name;
GRANT ALL ON db_name.* to 'db_user'@'localhost' IDENTIFIED BY 'db_password';
FLUSH PRIVILEGES;
quit
cd /var/www/html/project
sudo composer install
sudo composer update
mv .env.example .env
(Enter Database Credentials)
php artisan config:cache
php artisan key:generate
php artisan migrate:fresh --seed