{"id":7461,"date":"2021-01-06T22:23:48","date_gmt":"2021-01-06T19:23:48","guid":{"rendered":"https:\/\/kifarunix.com\/?p=7461"},"modified":"2024-03-19T21:07:57","modified_gmt":"2024-03-19T18:07:57","slug":"install-laravel-php-framework-on-ubuntu","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-laravel-php-framework-on-ubuntu\/","title":{"rendered":"Install Laravel PHP Framework On Ubuntu 20.04"},"content":{"rendered":"\n
Welcome to our tutorial on how to install Laravel PHP framework on Ubuntu 20.04. Laravel<\/a> is a free, open-source PHP web framework which provides expressive, elegant syntax to web artisans. Laravel is one of the best choices for building modern, full-stack web applications.<\/p>\n\n\n\n Laravel is accessible, powerful, and provides tools required for large, robust applications. Some of its features include;<\/p>\n\n\n\n In order to install Laravel PHP framework, there are a few system requirements that have to be installed and setup.<\/p>\n\n\n\n Basically, you need either a LEMP or LAMP stack to run Laravel. You can follow the links below to install LEMP\/LAMP stack on Ubuntu 20.04.<\/p>\n\n\n\n Install LAMP Stack on Ubuntu 20.04<\/a><\/p>\n\n\n\n Install and Setup LEMP Stack on Ubuntu 20.04<\/a><\/p>\n\n\n\n In this setup, however, we will install Laravel with LAMP stack.<\/p>\n\n\n\n Apart from the default PHP extensions that gets installed alongside PHP package, there are other extensions that you need to install. Run the command below to install them;<\/p>\n\n\n\n Just to confirm, we are using PHP 7.4;<\/p>\n\n\n\n Login to your database backend and create a database and database user for your application. Be sure to replace the database name and user appropriately.<\/p>\n\n\n\n Reload database privilege tables;<\/p>\n\n\n\n Assuming you already have the Apache HTTP server, PHP and extensions and Database (MariaDB or MySQL), proceed to install PHP Composer.<\/p>\n\n\n\n Run the script below to install Composer programmatically on Ubuntu;<\/p>\n\n\n\n Save and exit the script.<\/p>\n\n\n\n Execute it;<\/p>\n\n\n\n Check the exit status of the script. It will exit with 1 in case of failure, or 0 on success, and is quiet if no error occurs.<\/p>\n\n\n\n Verify composer is installed;<\/p>\n\n\n\n You can as well check version of installed composer;<\/p>\n\n\n\n There are two ways in which you can install Laravel PHP framework;<\/p>\n\n\n\n Create Non root user to run composer as (it is strongly advised to avoid running Composer as super-user\/root<\/strong><\/em>).<\/p>\n\n\n\n In the command above, we created a non root user called laravel whose home directory is set to Switch to the user and run the Laravel live installer as follows;<\/p>\n\n\n\n All the necessary packages are installed to You ca simply run the command below to update the path.<\/p>\n\n\n\n Create demo app with the default Laravel settings;<\/p>\n\n\n\n To verify that the Laravel components are working fine, navigate to application directory and run You can similarly install Laravel PHP framework on Ubuntu using Composer, PHP package manager.<\/p>\n\n\n\n Navigate to the Laravel directory, which in our case is Install Laravel using composer;<\/p>\n\n\n\n Similarly, you can run run Once the installation is done, adjust the application environment variables ( Define the Laravel application database connection settings as created above;<\/p>\n\n\n\n Once you are done with installation and configuration of Laravel, create the specific app Apache site configuration file to enable you access it externally from browser.<\/p>\n\n\n\n The commands below are as root user<\/strong>.<\/p>\n\n\n\n For example, to create Apache site configuration for demoapp Laravel app;<\/p>\n\n\n\n Save and exit the file and run syntax check;<\/p>\n\n\n\n Disable the default Apache site;<\/p>\n\n\n\n Enable demoapp site configuration;<\/p>\n\n\n\n Set the proper ownership of the demoapp web root directory;<\/p>\n\n\n\n Restart Apache;<\/p>\n\n\n\n To allow external access to your apps, open HTTP(S) port on firewall if it is running;<\/p>\n\n\n\n Then navigate to browser and access Laravel App using the URL, And that confirms that Laravel is installed and working as expected. You can now start building your web applications using Laravel PHP framework.<\/p>\n\n\n\n Laravel 8.x Documentations<\/a><\/p>\n\n\n\n Install and Use Mendeley in Ubuntu 20.04<\/a><\/p>\n\n\n\n Install NetBeans IDE on Debian 10<\/a><\/p>\n\n\n\n Install NetBeans IDE on Ubuntu 20.04<\/a><\/p>\n\n\n\n<\/figure>\n\n\n\n
\n
Installing Laravel PHP Framework On Ubuntu 20.04<\/h2>\n\n\n\n
Prerequisites<\/h3>\n\n\n\n
\n
Install Other Required PHP Extensions<\/h4>\n\n\n\n
apt install php-bcmath php-gd php-mbstring php-xml php-zip php-tokenizer -y<\/code><\/pre>\n\n\n\n
php -v<\/code><\/pre>\n\n\n\n
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )\nCopyright (c) The PHP Group\nZend Engine v3.4.0, Copyright (c) Zend Technologies\n with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies<\/code><\/pre>\n\n\n\n
Create Laravel Database and Database User<\/h4>\n\n\n\n
create database demoapp;<\/code><\/pre>\n\n\n\n
grant all on demoapp.* to demoadmin@localhost identified by 'changeme';<\/code><\/pre>\n\n\n\n
flush privileges;\nquit<\/code><\/pre>\n\n\n\n
Install Composer PHP Package Manager on Ubuntu 20.04<\/h4>\n\n\n\n
vim install-composer.sh<\/code><\/pre>\n\n\n\n
#!\/bin\/sh\n\nEXPECTED_CHECKSUM=\"$(wget -q -O - https:\/\/composer.github.io\/installer.sig)\"\nphp -r \"copy('https:\/\/getcomposer.org\/installer', 'composer-setup.php');\"\nACTUAL_CHECKSUM=\"$(php -r \"echo hash_file('sha384', 'composer-setup.php');\")\"\n\nif [ \"$EXPECTED_CHECKSUM\" != \"$ACTUAL_CHECKSUM\" ]\nthen\n >&2 echo 'ERROR: Invalid installer checksum'\n rm composer-setup.php\n exit 1\nfi\n\nphp composer-setup.php --install-dir=\/usr\/local\/bin --filename=composer --quiet\nRESULT=$?\nrm composer-setup.php\nexit $RESULT<\/code><\/pre>\n\n\n\n
bash install-composer.sh<\/code><\/pre>\n\n\n\n
echo $?<\/code><\/pre>\n\n\n\n
which compoer<\/code><\/pre>\n\n\n\n
\/usr\/local\/bin\/composer<\/code><\/pre>\n\n\n\n
composer --version<\/code><\/pre>\n\n\n\n
Install Laravel PHP Framework<\/h4>\n\n\n\n
\n
Install Laravel PHP Framework Using Laravel Installer<\/h5>\n\n\n\n
useradd -m -d \/var\/www\/html\/laravel -s \/usr\/bin\/bash -g www-data laravel<\/code><\/pre>\n\n\n\n
\/var\/www\/html\/laravel<\/strong><\/code>. We will be using this directory as our default Laravel directory for our Apps.<\/p>\n\n\n\n
su - laravel<\/code><\/pre>\n\n\n\n
composer global require laravel\/installer<\/code><\/pre>\n\n\n\n
Changed current directory to \/var\/www\/html\/laravel\/.config\/composer\nUsing version ^4.1 for laravel\/installer\n.\/composer.json has been created\nRunning composer update laravel\/installer\nLoading composer repositories with package information\nUpdating dependencies\nLock file operations: 12 installs, 0 updates, 0 removals\n - Locking laravel\/installer (v4.1.1)\n - Locking psr\/container (1.0.0)\n - Locking symfony\/console (v5.2.1)\n - Locking symfony\/polyfill-ctype (v1.20.0)\n - Locking symfony\/polyfill-intl-grapheme (v1.20.0)\n - Locking symfony\/polyfill-intl-normalizer (v1.20.0)\n - Locking symfony\/polyfill-mbstring (v1.20.0)\n - Locking symfony\/polyfill-php73 (v1.20.0)\n - Locking symfony\/polyfill-php80 (v1.20.0)\n - Locking symfony\/process (v5.2.1)\n - Locking symfony\/service-contracts (v2.2.0)\n - Locking symfony\/string (v5.2.1)\nWriting lock file\nInstalling dependencies from lock file (including require-dev)\n...<\/code><\/pre>\n\n\n\n
\/var\/www\/html\/laravel\/.config\/composer<\/strong><\/code> directory. As a result, you need to update the PATH environment variable with Laravel binary configuration directory, \/var\/www\/html\/laravel\/.config\/composer\/vendor\/bin\/.<\/p>\n\n\n\n
echo 'export PATH=\"$HOME\/.config\/composer\/vendor\/bin:$PATH\"' >> ~\/.bashrc<\/code><\/pre>\n\n\n\n
source ~\/.bashrc<\/code><\/pre>\n\n\n\n
Create PHP demo App using Laravel<\/h5>\n\n\n\n
laravel new demoapp<\/code><\/pre>\n\n\n\n
_ _\n| | | |\n| | __ _ _ __ __ ___ _____| |\n| | \/ _` | '__\/ _` \\ \\ \/ \/ _ \\ |\n| |___| (_| | | | (_| |\\ V \/ __\/ |\n|______\\__,_|_| \\__,_| \\_\/ \\___|_|\n\nCreating a \"laravel\/laravel\" project at \".\/demoapp\"\nInstalling laravel\/laravel (v8.5.7)\n - Installing laravel\/laravel (v8.5.7): Extracting archive\nCreated project in \/var\/www\/html\/laravel\/demoapp\n> @php -r \"file_exists('.env') || copy('.env.example', '.env');\"\nLoading composer repositories with package information\nUpdating dependencies\nLock file operations: 105 installs, 0 updates, 0 removals\n - Locking asm89\/stack-cors (v2.0.2)\n - Locking brick\/math (0.9.1)\n...\nPackage manifest generated successfully.\n73 packages you are using are looking for funding.\nUse the `composer fund` command to find out more!\n> @php artisan key:generate --ansi\nApplication key set successfully.\n\nApplication ready! Build something amazing.<\/code><\/pre>\n\n\n\n
php artisan<\/strong><\/code> command.<\/p>\n\n\n\n
cd demoapp<\/code><\/pre>\n\n\n\n
php artisan<\/code><\/pre>\n\n\n\n
Laravel Framework 8.21.0\n\nUsage:\n command [options] [arguments]\n\nOptions:\n -h, --help Display help for the given command. When no command is given display help for the list command\n -q, --quiet Do not output any message\n -V, --version Display this application version\n --ansi Force ANSI output\n --no-ansi Disable ANSI output\n -n, --no-interaction Do not ask any interactive question\n --env[=ENV] The environment the command should run under\n -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug\n\nAvailable commands:\n...<\/code><\/pre>\n\n\n\n
Install Laravel PHP Framework using Composer<\/h5>\n\n\n\n
\/var\/www\/html\/laravel<\/strong><\/code>.<\/p>\n\n\n\n
su - laravel<\/code><\/pre>\n\n\n\n
pwd<\/code><\/pre>\n\n\n\n
\/var\/www\/html\/laravel<\/code><\/pre>\n\n\n\n
composer create-project --prefer-dist laravel\/laravel demoapp<\/code><\/pre>\n\n\n\n
php artisan<\/strong><\/code> command.<\/p>\n\n\n\n
Configure Laravel Application Environment Variables<\/h3>\n\n\n\n
APP_NAME, APP_ENV, APP_KEY, APP_DEBUG, APP_URL<\/strong><\/code>) appropriately;<\/p>\n\n\n\n
vim demoapp\/.env<\/code><\/pre>\n\n\n\n
APP_NAME=Laravel\nAPP_ENV=local\nAPP_KEY=base64:1nzhBMNqoyGP+DYbPM1Pq33MAPTQ+LGpTHwxuADV1v4=\nAPP_DEBUG=true\nAPP_URL=http:\/\/demoapp.kifarunix-demo.com\n...<\/code><\/pre>\n\n\n\n
...\nDB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=demoapp\nDB_USERNAME=demoadmin\nDB_PASSWORD=changeme\n...<\/code><\/pre>\n\n\n\n
Create Apache Site configuration file for Laravel Application<\/h3>\n\n\n\n
vim \/etc\/apache2\/sites-available\/demoapp.conf<\/code><\/pre>\n\n\n\n
<VirtualHost *:80>\n\n ServerName demoapp.kifarunix-demo.com\n ServerAdmin webmaster@localhost\n DocumentRoot \/var\/www\/html\/laravel\/demoapp\/public\n\n <Directory \/var\/www\/html\/laravel\/demoapp>\n Options Indexes MultiViews\n AllowOverride None\n Require all granted\n <\/Directory>\n\n ErrorLog \/var\/log\/apache2\/demoapp.error.log\n CustomLog \/var\/log\/apache2\/demoapp.access.log combined\n\n<\/VirtualHost><\/code><\/pre>\n\n\n\n
apachectl -t<\/code><\/pre>\n\n\n\n
a2dissite 000-default.conf<\/code><\/pre>\n\n\n\n
a2ensite demoapp.conf<\/code><\/pre>\n\n\n\n
chown -R :www-data \/var\/www\/html\/laravel\/demoapp\/<\/code><\/pre>\n\n\n\n
systemctl restart apache2<\/code><\/pre>\n\n\n\n
Accessing Laravel App from Browser<\/h3>\n\n\n\n
ufw allow \"Apache Full\"<\/code><\/pre>\n\n\n\n
http:\/\/APP-URL<\/strong><\/code>, for example,
http:\/\/demoapp.kifarunix-demo.com<\/strong><\/code>.<\/p>\n\n\n\n
<\/figure>\n\n\n\n
Reference and Further Reading<\/h3>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n