Setup laravel app on digitalocen - php

I an trying to get my Laravel site running on Digital Ocean. My laravel app is static so no SQL is used and I developed it locally with Homestead.
I can get the site showing the home page on IPaddress /public. It won't link to any pages though. I am guessing it is some rewrite problem I am having. I want to get rid of the /public and get it linking to other pages. Then worry about making it work on a domain
I followed PHPAcademys Cloud Server Set-up tutorial https://www.youtube.com/watch?v=1-ok9d_6xrc
The only difference is I used UBUNTU 14.04 x64. While following the tutorial I found I had a html folder inside /var/www. I needed to put my app within the html folder.
Code setup
sudo apt-get update
sudo apt-get install apache 2
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
I didnt use mysql because i dont need it for this app. Its a static site with laravel.
It said mcrypt was needed so I used
sudo php5enmod mcrypt
sudo service apache2 restart
Then I was getting an exception handler error, so i fixed that with
chgrp -R www-data /var/www/html
chmod -R 775 /var/www/html/app/storage

You need to setup an apache2 virtual host
cd /etc/apache2/sites-available
sudo nano myapp.conf
<VirtualHost *:80>
ServerName myapp.com
ServerAlias www.myapp.com
DocumentRoot "/var/www/html/myapp/public"
<Directory "/var/www/html/myapp/public/">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
exit nano
sudo a2ensite myapp.conf
sudo service apache2 restart

First go to your virtual host file which can be found on
/etc/apache2/sites-available/default.conf
I am not very sure about the path because I have been using nginx for so long. Anyways locate the conf file and change your root directory to something like
/var/www/html/public
rest all looks fine to me if that doesn't work chmod 777 app/storage

Related

Apache + PHP (multi version) + multi sites (with different PHP versions) + user access setup

I was searching the internet looking for solution, unfortunately none of those was helpful.
I am trying to achive the following:
On Linux Ubuntu 20.04 setup several sites. Each site may have different PHP version. Also users of each site must not be able to read/write files on other sites. Each site should have own group/user.
I see the solution this way (and was trying this way):
to create different folders with different group/users (site1/site1, site2/site2)
install Apache, PHP as FCGI
enable MPM module to be able to run script on behalf of different user on each site
What I could do so far. I could install Apache + PHP (+FCGI) with different versions. So far it was ok, no problem.
Then I need to separate users I enabled MPM modules of Apache. The best result I could get is to run PHP script as if on behalf of different users. But when PHP script is trying to create a file in the same folder I can see the owner/group as www-data. So security issues are not resolved.
I not not sure that enabling MPM is working as it should.
Since there is a lot of work done, I didn't want to show all long list of commands here. I hope someone could advise the correct guide I could look at.
If not helpful I'll show all here
UPD 1: (I coudn't find a proper way to show code in reply comment, so I do this way)
sudo apt-get install apache2
sudo apt-get install php7.4
sudo apt-get install libapache2-mpm-itk
sudo useradd -m --shell /bin/bash --home /home/u-site1 u-site1
sudo passwd u-site1
sudo vi /etc/apache2/sites-available/site1.local.conf
-- start of content
<VirtualHost *:80>
ServerName site1.local
ServerAdmin info#site1.local
DocumentRoot /home/u-site1/site1.local/html
CustomLog ${APACHE_LOG_DIR}/site1.local.log combined
ErrorLog ${APACHE_LOG_DIR}/site1.local-error.log
<IfModule itk.c>
AssignUserID u-site1 u-site1
</IfModule>
<Directory "/home/u-site1/site1.local/html">
Options All -Indexes
AllowOverride All
Require all granted
Order allow,deny
allow from all
</Directory>
</VirtualHost>
-- end of content
sudo mkdir -p /home/u-site1/site1.local/html
sudo a2ensite site1.local.conf
sudo vi /home/u-site1/site1.local/html/index.php
-- start of content
site1.local
<?php
$sFilePath = __DIR__ . "/new.file";
$bRes = file_put_contents($sFilePath, "TEST");
if($bRes === false)
echo "<pre>", var_export(error_get_last(), 1), "</pre>";
phpinfo();
-- end of content
sudo chown -R u-site1:u-site1 /home/u-site1/site1.local
sudo chmod 755 /home/u-site1/site1.local
sudo systemctl restart apache2

Can't route to CakePHP Controllers with Apache

I have my own digitalocean droplet setup and followed this tutorial to a T to get Cakephp working
Setup CakePHP with LAMP Stack
Everything works exactly as written in that tutorial besides for 'Step 6' - Creating the Article user interface. (Books in my case)
After using the bake all command and navigating to `/books' I get a 404 not found
As you can see CakePHP is setup and working at the top level URL, however when trying to move past that to a Controller that definitely exists it can't find it.
After some more digging, I found the issue. Apparently mod_rewrite is turned off by default on Ubuntu
`sudo a2enmod rewrite
systemctl reload apache`
is the solution here
Make sure your rewrite mod is On
If you are using Linux goto /etc/apache2/sites-enabled -> open 000-default.conf file
<VirtualHost *:80>
....
// add these lines
<Directory /var/www/html>
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
....
<</VirtualHost>
Save it.
restart your server: sudo service apache2 restart
give your project permissions by giving this command:
sudo chown -R user_name:www-data project_name/
sudo chmod -R 755 project_name/
cd project_name
chown -R www-data tmp
chown -R www-data logs
chmod -R 777 tmp
chmod -R 777 logs

404 Page Not Found when run Codeigniter project inside var/www/html/ on Ubuntu 16.04 LTS?

I have installed LAMP (Linux, Apache2, MySQL, and PHP) stack.
I have a project directory named 'mahasiswa'. When i ran it on Windows 8 was working well (using XAMPP). Then, when i run it on my Ubuntu 16.04 LTS inside var/www/html/ is not working anymore.
The screen shot of the result :
Is there special configuration to run CodeIgniter project on Ubuntu 16.04 LTS ?
:: Any help would be much appreciate. Thank you.
EDIT
My configuration files :
etc/apache2/sites-available/000-default.conf
etc/apache2/sites-available/mahasiswa.conf
etc/hosts
mahasiswa/.htaccess
The current result on browser:
I don't know exactly what i've missing at this configuration. I've followed #eeya instruction / answer below. Any body can help me, please :D
For your question in setting up the apache virtual host configuration: Here's how it goes. If you have [root] privilege, Open your [Terminal] and go to this directory: /etc/apache2/sites-available
Then create a new virtual host configuration, For now, we will name this configuration the name of your project.
sudo vim mahasiswa.conf or sudo nano mahasiswa.conf
<VirtualHost *:80>
ServerName local.mahasiswa.com
DocumentRoot /var/www/html/mahasiswa
<Directory /var/www/html/mahasiswa/>
AllowOverride All
Require all granted
Allow from all
</Directory>
</VirtualHost>
1) ServerName: serves as the the DNS (Think of it as another server name aside from http://localhost or http://127.0.0.1)
2) DocumentRoot: from the word itself, is your [project]'s directory (e.g /var/www/html/mahasiswa)
3) Directory: are used to enclose a group of directives that will apply only to the named directory, sub-directories of that directory, and the files within the respective directories. In this case, we wanted to place control access rights to a directory:
AllowOverride All (This can be either All or None)
Require all granted
Allow from all
You can learn more of this here: http://httpd.apache.org/docs/current/mod/core.html#directory
Going back, Once you've saved this new configuration, Go to your /etc/hosts (hosts file) (e.g sudo vim /etc/hosts) and add the ff:
127.0.0.1 localhost local.mahasiswa.com
Once you've saved these changes on your [hosts] file, Execute this command:
sudo a2ensite mahasiswa.conf
sudo a2enmod rewrite
This will now [enable] your new site configuration and enable the [url rewrite] module as well. Then execute this afterwards:
sudo service apache2 reload
From the command itself, it means you need to reload [apache2] thus the configuration takes affect afterwards.
Then try to access your new domain name: local.mahasiswa.com.
You should be able to see your CI pages you've needed.
For further reference, check [Digital Ocean] guide here: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04
Hope this helps for your case.
Edit:
In naming the [controller] file(s) (e.g mahasiswa), You might need to set [UpperCase] instead of [lowercase] format to (e.g Mahasiswa)
Enable mod_rewrite
sudo a2enmod rewrite
sudo systemctl restart apache2

Configure remote Laravel app to be accessible from browser

All the laravel projects I worked on were installed/configured started by other people. A long time ago I managed to install a Laravel project on a Windows machine using WAMP and it was easier as far as I remember.
I recently received access to a clean droplet from digitalocean.com with Centos 7 installed. I think a droplet is something like a VPS. You have an IP, and SSH access
After some headache I managed to successfully install laravel using composer. I have also installed mysql and apache(httpd)
Now I have
/var/www/laravel
folder, with the installation of the latest Laravel (5.3)
I went inside /var/www/ and called
composer create-project laravel/laravel mypro
Now, I have a laravel app scheleton of a new application at
/var/www/mypro
I would like to access it from a browser so I can start working on it, but I do not know what I need to do. There are many tutorials on how to do that but they are very confusing for me.
What must I do next in order to be able to see the results of what I am working on?
If , in the browser, I access now the droplet by IP, like
http://xxx.xxx.xxx.xxx
I get
Not Found The requested URL / was not found on this server.
Same if I add to the URL the name of my app like
http://xxx.xxx.xxx.xxx/mypro
I believe I must configure the httpd ? Or maybe move the project's folder somewhere else?
I tried moving my project folder inside /var/www/html folder, so
/var/www/html/mypro
and now when I try to access the url I receive an empty page (view-source of the browser page returns also an empty page)
I even tried
http://xxx.xxx.xxx.xxx/mypro/server.php
since there is a server.php file in the root of my project folder... same result
I even added a conf to the /etc/httpd/conf.d/ folder called mypro.conf where I added these lines:
<VirtualHost *:80>
ServerName mypro
DocumentRoot "/var/www/html/mypro/public"
<Directory /var/www/html/mypro/public>
AllowOverride all
</Directory>
</VirtualHost>
Nothing new happens
I did "service httpd restart" everytime a changed something.
I even tried
php artisan serve --host xxx.xxx.xxx.xxx --port 8000
and tried the url http://xxx.xxx.xxx.xxx:8000
Now I get "Unable to connect" page from the browser so I stopped the "serve"
What is it that I have to do in order to be able to finally start working?
Following is way how i do it on Ubutnu 16.04 (It can be done with some changes on Centos).
Update your package repo.
sudo apt update
Update packeges.
sudo apt dist-upgrade
Install PHP
apt install php
Install apache2
apt install apache2
Install PHP Plugins
apt install php-mbstring php-pdo php-tokenizer php-xml php-mcrypt php-gd libapache2-mod-php php-curl php-mysql
Enable mcrypt
phpenmod mcrypt
a2enmod rewrite
Restart Apache Server
service apache2 restart
Install Composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
Install Git
apt install git
Install mysql-server
apt install mysql-server
Install Phpmyadmin (Optional)
apt install phpmyadmin
Install zip & unzip
apt install zip unzip
Now create apache virtual host configuration for your website.
cd /etc/apache2/sites-available
touch pqr.xyz.com.conf
The basic content of is pqr.xyz.com.conf
#content of pqr.xyz.com.conf
<VirtualHost *:80>
ServerName pqr.xyz.com
ServerAdmin webmaster#xyz.com
DocumentRoot /var/www/html/pqr.xyz.com/public
<Directory /var/www/html/pqr.xyz.com>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now goto /var/www/html
cd /var/www/html/
Create a directory with your website name
mkdir pqr.xyz.com
Now add a user because it is not good idea to work with composer as root while creating laravel project.
adduser admin --ingroup admin
Now make admin as owner of this directory
chown -R admin pqr.xyz.com
Now login as admin
go to /var/www/html
cd /var/www/html
Install Laravel using composer
composer create-project laravel/laravel pqr.xyz.com
cd /var/www/html/pqr.xyz.com
Now your storage and bootstrap directory should have write permission for apache 2 server so make apache owner of these two directories.
chown -R www-data storage
chown -R www-data bootstrap
Now login as root
Activate pqr.xyz.com.conf
a2dissite 000-default.conf
service apache2 reload
a2ensite shopperstock.eveningx.com.conf
service apache2 reload
service apache2 restart
It may not be the best way to work with any larave project , So feel free to comment or suggest an edit.

How can I enable moodle?

I've installed postgres for moodle and I got the following instructions:
Apache/mod_php setup
Give full access to the project directory to the process running
apache. You might also have to set the x-flag on all .php files.
$ chmod -R a+rw * Create a 'moodle.vhost.conf' from moodle.vhost.conf.example in project directory. * Create a symlink
from /usr/local/var/moodle to the project directory.
$ cd /usr/local/var; ln -s moodle * Also symlink the new virtual host into apache config dir.
$ cd /private/etc/apache2/other
$ sudo ln -s /moodle.vhost.conf moodle.conf
$ sudo apachectl restart * Create your own custom /etc/vcmoodle/config_local.php file for things local to your
environment by copying, and modifying if required, the example file.
$ sudo mkdir -p /etc/vcmoodle
$ sudo cp /config_local.php.example /etc/vcmoodle/config_local.php
Still it won't work. When I look at my apache root then it comes just the standard apache page and no moodle. I've this sites-available
:/etc/apache2/sites-available$ ls
000-default.conf default-ssl.conf moodle.conf
and the file moodle.conf contents
<VirtualHost *:80>
DocumentRoot "/usr/local/var/moodle"
ServerName moodle.localdev.kth.se
ErrorLog /usr/local/var/moodle/error_log
LogLevel debug
<Directory "/usr/local/var/moodle">
AllowOverride all
Order allow,deny
Allow from 127.0.0.1
</Directory>
</VirtualHost>
But I don't get a moodle page at my web server. What am I doing wrong?
if youre running Ubuntu (judging by the tag), you need to put your project directory inside /var/www. Apache cant access project folders inside your specified directory unless you change the users/groups etc.
what youve tried is the normal apache default location for web folders, but Ubuntu like to change things.

Categories