Commit d79e1679 authored by Shengjie Yang's avatar Shengjie Yang
Browse files

setup laravel on ubuntu server

parent b45bbb8b
# Setup Laravel App on Server
* Laravel app was developed on local and pushed to Git. We were going to deploy it on an Ubuntu 18.04 server where PHP, Apache, MySQL are already setup.
### 1. Clone Laravel Repo
Login the server and clone a repository to ~/public_html (It's not nesessary to store into /var/www/html)
git clone datamanager
cd datamanager/
cp .env.example .env
// Create a new database in MySQL and config the mysql parameter in .env
### 2. Install Composer
Laravel gitignore the vendor directory by default and we need composert to install the packages in vendor. You can skip this step if composer is already installed.
Run `curl -sS -o composer-setup.php` to pull the composer installer. If it returns error like below,
> curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number
vi /etc/environment`
// Change https_proxy="https://xxxxx" to https_proxy="http://xxxxx" and then reboot server
sudo su
sudo reboot
Login back to server and locate at where the composer installer stored. Then run following script, (check for latest script)
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
### 3. Install packages in vendor of Laravel
Go to the directory of Laravel app and run
composer install
// if it alerts to execute composer update, just do it
composer update
In my case, it returns errors in prompt
> Problem 1
> \- Root composer.json requires php ^7.3|^8.0 but your php version (7.2.24) does not satisfy that requirement.
> Problem 2
> \- laravel/framework[v8.40.0, ..., 8.x-dev] require php ^7.3|^8.0 -> your php version (7.2.24) does not satisfy that requirement.
> \- Root composer.json requires laravel/framework ^8.40 -> satisfiable by laravel/framework[v8.40.0, ..., 8.x-dev].
**Solution:** Upgrade PHP to 7.4 (Whatever version php>=7.3)
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
# Install PHP 7.4 core
sudo apt install php7.4 php7.4-common php7.4-cli
# PHP 7.4 extensions
sudo apt install php7.4-bcmath php7.4-bz2 php7.4-curl php7.4-intl php7.4-mbstring php7.4-mysql php7.4-readline php7.4-xml php7.4-zip
# Web server integration
sudo apt install php7.4-fpm
sudo a2enconf php7.4-fpm
sudo apt install libapache2-mod-php7.4
# Restart apache to reload
sudo systemctl reload apache2
# php -v shows PHP 7.4 and phpinfo() shows PHP 7.2. To enable php 7.4 in phpinfo()
sudo a2dismod php7.2
sudo a2enmod php7.4
sudo service apache2 restart
Then rerun `composer update` / `composer install` under Laravel app directory.
### 4. Setup Virtual Host in Apache2
sudo mv /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/
// Insert following content
<VirtualHost *:8080>
DocumentRoot /home/shengjie/public_html/
Alias /datamanager /home/shengjie/public_html/datamanager/public
<Directory "/home/shengjie/public_html">
Options All
AllowOverride All
Allow from all
<Directory /home/shengjie/public_html/datamanager>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
ErrorLog ${APACHE_LOG_DIR}/shengjie_error.log
CustomLog ${APACHE_LOG_DIR}/shengjie_access.log combined
sudo a2ensite
vi /etc/apache2/ports.conf
// Add a line: Listen 8080
### 5. Initial Laravel App
vi LARAVE_PATH/public/.htaccess
// Add a line: RewriteBase /datamanager/
php artisan key:generate
php artisan cache:clear
php artisan view:clear
php artisan config:clear
php artisan route:clear
php artisan migrate:refresh --seed
chmod -R 775 storage
Access `` to visit and find only root route "/" works and other routes return NOT FOUND
sudo a2enmod rewrite
sudo service apache2 restart
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment