{"id":564,"date":"2024-05-16T12:20:35","date_gmt":"2024-05-16T12:20:35","guid":{"rendered":"https:\/\/zahiralam.com\/blog\/?p=564"},"modified":"2024-09-12T10:51:21","modified_gmt":"2024-09-12T10:51:21","slug":"how-to-set-up-a-laravel-code-base-on-an-ubuntu-server","status":"publish","type":"post","link":"https:\/\/zahiralam.com\/blog\/how-to-set-up-a-laravel-code-base-on-an-ubuntu-server\/","title":{"rendered":"How to Set Up a Laravel Code Base on an Ubuntu Server"},"content":{"rendered":"\n<p>Setting up a Laravel code base on an Ubuntu server can be straightforward if you follow the steps carefully. This guide will walk you through the entire process, from cloning your repository to securing your site with SSL. Let&#8217;s get started!\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before you begin, ensure you have the following:\n\n\n\n<ul class=\"wp-block-list\">\n<li>An Ubuntu server<\/li>\n\n\n\n<li>SSH access to your server<\/li>\n\n\n\n<li>A registered domain name pointed to your server<\/li>\n<\/ul>\n\n\n\n<p>\n\n\n\n<h2 class=\"wp-block-heading\">Step-by-Step Guide<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. Clone Your Repository<\/h3>\n\n\n\n<p>First, SSH into your server and navigate to your web root directory.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-1\">ssh your_username@your_server_ip\ncd \/var\/www\/html\/<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#ssh%20your_username%40your_server_ip%0Acd%20%2Fvar%2Fwww%2Fhtml%2F\">\n                            <button class=\"copy-button\" data-label=\"ssh your_username@your_server_ip\ncd \/var\/www\/html\/\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Clone your Laravel project from your Git repository.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-2\">git clone YOUR_GIT_REPO<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#git%20clone%20YOUR_GIT_REPO\">\n                            <button class=\"copy-button\" data-label=\"git clone YOUR_GIT_REPO\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Navigate to your project directory.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-3\">cd \/var\/www\/html\/ai-arena<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#cd%20%2Fvar%2Fwww%2Fhtml%2Fai-arena\">\n                            <button class=\"copy-button\" data-label=\"cd \/var\/www\/html\/ai-arena\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<h3 class=\"wp-block-heading\">2. Set Up Environment Variables<\/h3>\n\n\n\n<p>Copy your <code>.env<\/code> file to the root of your project.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-4\">cp \/path\/to\/your\/.env \/var\/www\/html\/ai-arena\/.env<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#cp%20%2Fpath%2Fto%2Fyour%2F.env%20%2Fvar%2Fwww%2Fhtml%2Fai-arena%2F.env\">\n                            <button class=\"copy-button\" data-label=\"cp \/path\/to\/your\/.env \/var\/www\/html\/ai-arena\/.env\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3. Install Composer<\/h3>\n\n\n\n<p>Install Composer, a dependency manager for PHP. Follow the instructions at <a href=\"https:\/\/getcomposer.org\/download\/\">Composer&#8217;s official website<\/a>.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-5\">php -r &quot;copy(&#039;https:\/\/getcomposer.org\/installer&#039;, &#039;composer-setup.php&#039;);&quot;\nphp -r &quot;if (hash_file(&#039;sha384&#039;, &#039;composer-setup.php&#039;) === &#039;e4d9b25c6359b25925fa897ad96fa212f63b4e1a4e44b0a1b7d735eb4f6a2e4b&#039;) { echo &#039;Installer verified&#039;; } else { echo &#039;Installer corrupt&#039;; unlink(&#039;composer-setup.php&#039;); } echo PHP_EOL;&quot;\nphp composer-setup.php\nphp -r &quot;unlink(&#039;composer-setup.php&#039;);&quot;<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#php%20-r%20%22copy%28%27https%3A%2F%2Fgetcomposer.org%2Finstaller%27%2C%20%27composer-setup.php%27%29%3B%22%0Aphp%20-r%20%22if%20%28hash_file%28%27sha384%27%2C%20%27composer-setup.php%27%29%20%3D%3D%3D%20%27e4d9b25c6359b25925fa897ad96fa212f63b4e1a4e44b0a1b7d735eb4f6a2e4b%27%29%20%7B%20echo%20%27Installer%20verified%27%3B%20%7D%20else%20%7B%20echo%20%27Installer%20corrupt%27%3B%20unlink%28%27composer-setup.php%27%29%3B%20%7D%20echo%20PHP_EOL%3B%22%0Aphp%20composer-setup.php%0Aphp%20-r%20%22unlink%28%27composer-setup.php%27%29%3B%22\">\n                            <button class=\"copy-button\" data-label=\"php -r &quot;copy(&#039;https:\/\/getcomposer.org\/installer&#039;, &#039;composer-setup.php&#039;);&quot;\nphp -r &quot;if (hash_file(&#039;sha384&#039;, &#039;composer-setup.php&#039;) === &#039;e4d9b25c6359b25925fa897ad96fa212f63b4e1a4e44b0a1b7d735eb4f6a2e4b&#039;) { echo &#039;Installer verified&#039;; } else { echo &#039;Installer corrupt&#039;; unlink(&#039;composer-setup.php&#039;); } echo PHP_EOL;&quot;\nphp composer-setup.php\nphp -r &quot;unlink(&#039;composer-setup.php&#039;);&quot;\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Move Composer to a globally accessible location.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-6\">sudo mv composer.phar \/usr\/local\/bin\/composer<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20mv%20composer.phar%20%2Fusr%2Flocal%2Fbin%2Fcomposer\">\n                            <button class=\"copy-button\" data-label=\"sudo mv composer.phar \/usr\/local\/bin\/composer\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<h3 class=\"wp-block-heading\">4. Install Laravel Dependencies<\/h3>\n\n\n\n<p>Navigate to your project directory and install the necessary dependencies.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-7\">cd \/var\/www\/html\/ai-arena\ncomposer install<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#cd%20%2Fvar%2Fwww%2Fhtml%2Fai-arena%0Acomposer%20install\">\n                            <button class=\"copy-button\" data-label=\"cd \/var\/www\/html\/ai-arena\ncomposer install\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<h3 class=\"wp-block-heading\">5. Set Up Laravel<\/h3>\n\n\n\n<p>Generate the application key.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-8\">php artisan key:generate<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#php%20artisan%20key%3Agenerate\">\n                            <button class=\"copy-button\" data-label=\"php artisan key:generate\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Run the migrations to set up your database.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-9\">php artisan migrate<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#php%20artisan%20migrate\">\n                            <button class=\"copy-button\" data-label=\"php artisan migrate\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<h3 class=\"wp-block-heading\">6. Set Permissions<\/h3>\n\n\n\n<p>Ensure the <code>storage<\/code> and <code>bootstrap\/cache<\/code> directories are writable by the web server.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-10\">sudo chmod -R 777 \/var\/www\/html\/ai-arena\/storage\/logs\nsudo chown -R www-data:www-data \/var\/www\/html\/ai-arena\/storage\nsudo chown -R www-data:www-data \/var\/www\/html\/ai-arena\/bootstrap\/cache<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20chmod%20-R%20777%20%2Fvar%2Fwww%2Fhtml%2Fai-arena%2Fstorage%2Flogs%0Asudo%20chown%20-R%20www-data%3Awww-data%20%2Fvar%2Fwww%2Fhtml%2Fai-arena%2Fstorage%0Asudo%20chown%20-R%20www-data%3Awww-data%20%2Fvar%2Fwww%2Fhtml%2Fai-arena%2Fbootstrap%2Fcache\">\n                            <button class=\"copy-button\" data-label=\"sudo chmod -R 777 \/var\/www\/html\/ai-arena\/storage\/logs\nsudo chown -R www-data:www-data \/var\/www\/html\/ai-arena\/storage\nsudo chown -R www-data:www-data \/var\/www\/html\/ai-arena\/bootstrap\/cache\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Create a symbolic link for storage.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-11\">php artisan storage:link<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#php%20artisan%20storage%3Alink\">\n                            <button class=\"copy-button\" data-label=\"php artisan storage:link\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<h3 class=\"wp-block-heading\">7. Configure Apache<\/h3>\n\n\n\n<p>Create a new Apache configuration file for your Laravel project.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-12\">sudo vim \/etc\/apache2\/sites-available\/aiarena.zahiralam.com.conf<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20vim%20%2Fetc%2Fapache2%2Fsites-available%2Faiarena.zahiralam.com.conf\">\n                            <button class=\"copy-button\" data-label=\"sudo vim \/etc\/apache2\/sites-available\/aiarena.zahiralam.com.conf\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Add the following configuration to the file:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-13\">&lt;VirtualHost *:80&gt;\n    ServerName aiarena.zahiralam.com\n    ServerAdmin webmaster@localhost\n    DocumentRoot \/var\/www\/html\/ai-arena\/public\n\n    &lt;Directory \/var\/www\/html\/ai-arena\/public&gt;\n        Options Indexes FollowSymLinks MultiViews\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory&gt;\n\n    ErrorLog ${APACHE_LOG_DIR}\/aiarena-error.log\n    CustomLog ${APACHE_LOG_DIR}\/aiarena-access.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#%3CVirtualHost%20%2A%3A80%3E%0A%20%20%20%20ServerName%20aiarena.zahiralam.com%0A%20%20%20%20ServerAdmin%20webmaster%40localhost%0A%20%20%20%20DocumentRoot%20%2Fvar%2Fwww%2Fhtml%2Fai-arena%2Fpublic%0A%0A%20%20%20%20%3CDirectory%20%2Fvar%2Fwww%2Fhtml%2Fai-arena%2Fpublic%3E%0A%20%20%20%20%20%20%20%20Options%20Indexes%20FollowSymLinks%20MultiViews%0A%20%20%20%20%20%20%20%20AllowOverride%20All%0A%20%20%20%20%20%20%20%20Require%20all%20granted%0A%20%20%20%20%3C%2FDirectory%3E%0A%0A%20%20%20%20ErrorLog%20%24%7BAPACHE_LOG_DIR%7D%2Faiarena-error.log%0A%20%20%20%20CustomLog%20%24%7BAPACHE_LOG_DIR%7D%2Faiarena-access.log%20combined%0A%3C%2FVirtualHost%3E\">\n                            <button class=\"copy-button\" data-label=\"&lt;VirtualHost *:80&gt;\n    ServerName aiarena.zahiralam.com\n    ServerAdmin webmaster@localhost\n    DocumentRoot \/var\/www\/html\/ai-arena\/public\n\n    &lt;Directory \/var\/www\/html\/ai-arena\/public&gt;\n        Options Indexes FollowSymLinks MultiViews\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory&gt;\n\n    ErrorLog ${APACHE_LOG_DIR}\/aiarena-error.log\n    CustomLog ${APACHE_LOG_DIR}\/aiarena-access.log combined\n&lt;\/VirtualHost&gt;\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Enable the site and restart Apache.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-14\">sudo a2ensite aiarena.zahiralam.com.conf\nsudo service apache2 restart<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20a2ensite%20aiarena.zahiralam.com.conf%0Asudo%20service%20apache2%20restart\">\n                            <button class=\"copy-button\" data-label=\"sudo a2ensite aiarena.zahiralam.com.conf\nsudo service apache2 restart\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<h3 class=\"wp-block-heading\">8. Secure Your Site with SSL<\/h3>\n\n\n\n<p>Install Certbot, a tool to obtain SSL certificates from Let&#8217;s Encrypt.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-15\">sudo apt install certbot python3-certbot-apache<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20apt%20install%20certbot%20python3-certbot-apache\">\n                            <button class=\"copy-button\" data-label=\"sudo apt install certbot python3-certbot-apache\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Run Certbot to obtain and install your SSL certificate.\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-16\">sudo certbot --apache -d aiarena.zahiralam.com<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20certbot%20--apache%20-d%20aiarena.zahiralam.com\">\n                            <button class=\"copy-button\" data-label=\"sudo certbot --apache -d aiarena.zahiralam.com\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Follow the prompts to complete the SSL installation.\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>By following these steps, you will have successfully set up your Laravel code base on an Ubuntu server. Your site will be running securely with SSL, ensuring that your users&#8217; data is protected. If you encounter any issues, refer to the Laravel and Apache documentation for additional troubleshooting tips.\n","protected":false},"excerpt":{"rendered":"<p>Setting up a Laravel code base on an Ubuntu server can be straightforward if you follow the steps carefully. This guide will walk you through [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":1132,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[13,83,81,84,82],"class_list":["post-564","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development","tag-apache","tag-certbot","tag-laravel","tag-ssl","tag-ubuntu-server"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/posts\/564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/comments?post=564"}],"version-history":[{"count":2,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/posts\/564\/revisions"}],"predecessor-version":[{"id":1133,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/posts\/564\/revisions\/1133"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/media\/1132"}],"wp:attachment":[{"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/media?parent=564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/categories?post=564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/tags?post=564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}