I am new to server management and till now I used a free service which installs server with one click for me and also installs wordpress in it. Now I have two problems. They are retiring their free plan and even though I can still use their free plan till I disconnect my server, I want to learn How to optimize DO server for best performance. Second Issue - I want to host Laravel apps as demo for my written tutorials which I will write in my portfolio wordpress blog and also host laravel apps as portfolio projects. But I don’t know how to install laravel as Wordpress is currently installed.
After researching, I got to know that installing composer and creating laravel project in subfolder let’s say homepage.com/demo/myapp should work. But I created my project in localhost and there I had to start the server everytime using “php artisan serve” to run the project. But in live servers how these works I don’t know.
Any tutorial links or help will be appreciated.
Thanks
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
@parthp1808
When you’re running
php artisan serve
, Laravel is using PHP’s built-in web server to serve your site. It’s not a production web server and only meant for local development, which would be why you need to start it each time you close out your terminal.It’s not meant to be persistent like, for example, NGINX or Apache, and you definitely don’t want rely on that on a production server.
What I would recommend is setting up a LEMP Stack. That’d consist of Linux (Ubuntu), NGINX, PHP, and MariaDB (or MySQL). Ubuntu has existing repositories for each, though there are also multiple alternative repositories, including those maintained by the developers themselves (which is why I use when/where possible).
…
That said, I actually just released an initial release of some of the installers I use to handle setting up NGINX and PHP (PHP-FPM) which ease the process. The NGINX installer I use compiles NGINX from source and includes multiple configuration examples (including one for PHP) which can be used as a basis for your overall configuration.
You can find that here:
https://github.com/serveradminsh/installers
To use the installers, all you need to do is clone the repository to your server using
git
. Since most don’t have it installed by default, you’ll probably need to run:Then change over to a directory of your choice for the clone. I generally use
/opt
, so that’s what I’ll use for this example.Now you’ll see a few directories – for the purpose of this, we’re only going to focus on
nginx
andphp
(you don’t need NodeJS for PHP or Laravel).So let’s start with NGINX.
That’s all you need to do to install NGINX. That auto-installer will handle a source compile for you and you won’t have to configure anything until it completes (it’ll take a little while – between 15-30 minutes). Even then, the only thing you need to configure is your server blocks for your website. The configuration is already optimized and ready to rock.
Now to install PHP and PHP-FPM (used by NGINX), you can change over to the
php
directory and choose your preferred PHP version. I normally stick with 7.1, so that’s what I’ll use here.The correct repository will be added and the most common PHP packages will be installed, which should be all you need for your application unless you need very specific packages.
You can check your PHP version by running:
…
Inside of the
nginx
directory, there’s anexamples
directory and within that, aphp
directory. That’s the server block configuration file you want to work with, so let’s copy that over and rename it to your domain.Replace
yourdomain.ext
with your actual domain. Now we just need to tweak that file to be specific to your domain instead of general.Find:
Replace that with
Now find:
And set the path to the path where you want to store your public files, i.e. where
index.php
will be. For example:Close and save the file. We just need to make one more change and that’d be to this file:
We need to modify the listen directive so that it matches our NGINX configuration. By default, PHP uses sockets but our NGINX configuration uses TCP (preferred), so we need to fix that.
Find:
Change that to:
Close and save. Now we need to restart both NGINX and PHP-FPM.
From there, the only other thing you need to do is install MariaDB/MySQL if needed for your app and then start creating databases, database users, etc so that you can connect. We can do that next (and I’ll have an installer for it uploaded soon to simplify things), but let’s make sure we get the above up and running for you first :-).