<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Wediah Emmanuel</title>
    <description>The latest articles on Forem by Wediah Emmanuel (@wediah).</description>
    <link>https://forem.com/wediah</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1069834%2Fd0c74fe6-120c-40ea-9ec8-ae282c140f44.jpg</url>
      <title>Forem: Wediah Emmanuel</title>
      <link>https://forem.com/wediah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/wediah"/>
    <language>en</language>
    <item>
      <title>How to host a PHP/Laravel app on Google Cloud.</title>
      <dc:creator>Wediah Emmanuel</dc:creator>
      <pubDate>Thu, 06 Nov 2025 01:17:41 +0000</pubDate>
      <link>https://forem.com/wediah/how-to-host-a-phplaravel-app-on-google-cloud-2f34</link>
      <guid>https://forem.com/wediah/how-to-host-a-phplaravel-app-on-google-cloud-2f34</guid>
      <description>&lt;p&gt;Taking a Laravel application from a local development environment to a production system is a critical step in shipping your product.&lt;/p&gt;

&lt;p&gt;Below is the step by step method, I use to deploy my Laravel apps to Google cloud;&lt;/p&gt;

&lt;p&gt;First, we starting by creating a project on the Google Cloud console (fig. 1), then we create a virtual machine by choosing the subscription model which fits our app (fig. 2, 3). &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnplrg7z97yt08be5ajil.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnplrg7z97yt08be5ajil.png" alt=" " width="800" height="424"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;fig. 1&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhif5rau3bn6xyq8vsxnq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhif5rau3bn6xyq8vsxnq.png" alt=" " width="800" height="455"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;fig. 2&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxv6grvevek8nwb4v00l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxv6grvevek8nwb4v00l.png" alt=" " width="800" height="568"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;fig. 3&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Secondly, after creating the virtual machine, we SSH into the server. For simplicity, we go with the SSH-in-browser (fig. 4).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2jn023bte4n6nd0s1l6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2jn023bte4n6nd0s1l6.png" alt=" " width="800" height="607"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;fig. 4&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After SSHing into the virtual machine, we perform an update,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt update &amp;amp;&amp;amp; sudo apt upgrade -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then install Nginx (our web server), &lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt install -y nginx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;followed by checking the PHP version that comes with our virtual machine,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then we install these essential components for PHP (NB: the version of the component should match up with the version of PHP installed on the virtual machine. In the command below, we are using PHP version 8.3),&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt install -y php8.3-fpm php8.3-mysql php8.3-mbst&lt;br&gt;
ring php8.3-xml php8.3-zip php8.3-gd php8.3-bcmath php8.3-cli php8.3-common&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;after installing the components, we move to installing &lt;strong&gt;mysql&lt;/strong&gt; and &lt;strong&gt;composer&lt;/strong&gt; on the server,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt install -y mysql-server&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;curl -sS https://getcomposer.org/installer | php&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After installing composer, we move to the bin of our virtual machine,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo mv composer.phar /usr/local/bin/composer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The next step is to run a secure installation of MySQL,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo mysql_secure_installation&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After running the secure MySQL installation, we validate a password component for our SQL server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: Y
There are three levels of password validation policy:

LOW    Length &amp;gt;= 8
MEDIUM Length &amp;gt;= 8, numeric, mixed case, and special characters
STRONG Length &amp;gt;= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we setup a root user for our sql server. (NB: in the password section, we enter a new password),&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo mysql -u root -p&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The next step comes with cloning our code hosted on GitHub and create a folder on our virtual machine where it will cloned into,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo git clone https://github.com/yourcode.git yourfoldername&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then we set permissions and navigate to the location of the folder where our code has been cloned into and install composer, &lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo chown -R $USER:$USER /var/www/yourfoldername&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd /var/www/yourfoldername&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer install --optimize-autoloader --no-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Followed by setting up the following permissions;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo chown -R username:username .&lt;/code&gt;&lt;br&gt;
&lt;code&gt;sudo chown -R www-data:www-data /var/www/yourfoldername&lt;/code&gt;&lt;br&gt;
&lt;code&gt;sudo chmod -R 775 /var/www/yourfoldername/storage&lt;/code&gt;&lt;br&gt;
&lt;code&gt;sudo chmod -R 775 /var/www/yourfoldername/bootstrap/cache&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After these, we copy the example environment file to the environment file and add our variables using the nano editor , generate our app's key and run our migrations,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cp .env.example .env&lt;/code&gt;&lt;br&gt;
&lt;code&gt;nano .env&lt;/code&gt;&lt;br&gt;
&lt;code&gt;php artisan key:generate&lt;/code&gt;&lt;br&gt;
&lt;code&gt;php artisan migrate --force&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The last step is to configure the web server; the first step at this to to edit the site config to point to our root file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo nano /etc/nginx/sites-available/yourfoldername&lt;/code&gt; after this we make it look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 80;
    server_name _;
    root /var/www/yourfoldername/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step is to enable our site;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo ln -s /etc/nginx/sites-available/mefiedirectory /etc/nginx/sites-enabled/&lt;/code&gt;&lt;br&gt;
&lt;code&gt;sudo nginx -t&lt;/code&gt;&lt;br&gt;
&lt;code&gt;sudo systemctl reload nginx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Finally can can visit our app on the web at &lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://[YOUR_EXTERNAL_IP]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Thanks to some invaluable feedback from a few incredible developers, I’ve realized there’s a far more efficient and scalable way to manage infrastructure—through Infrastructure-as-Code (IaC). One tool that’s caught my attention—and that I’m diving into right now—is &lt;strong&gt;Terraform&lt;/strong&gt;. It promises not only greater consistency and repeatability but also a cleaner, more maintainable approach to provisioning and managing cloud resources.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>backenddevelopment</category>
      <category>api</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
