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.
Related
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
I'm running ubuntu 16.04 and installed LAMP this way:
Install Apache
sudo apt-get install apache2
Install MySQL
sudo apt-get install mysql-server
Install PHP
sudo apt-get install php7.0 libapache2-mod-php7.0
Restart Server
sudo /etc/init.d/apache2 restart
Check Apache
Working
Check PHP
php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'
Working
Files structure:
/var/www/html/index.html > redirects to index.php
/var/www/html/pages/index.php < this file is not working and all php files
The owner group is set to:
chown -R www-data:www-data /var/www
The folders permissions are 755. The index.php permssions is 644 This is my apache2.conf file: https://ghostbin.com/paste/wwhog
But when i go to: http://localhost/pages/index.php I get this 403 Forbidden error. It seems like i can't see php files.
Here is some ways how to fix it.
chmod files 644 and folders 755 (you have opposite side)
check owner of folders and files and chown them correctly.
Disable SELinux.
Checking error log file of Apache will give you more information about error.
Try chown -R www-data:www-data /var/www, if you still get a 403, that means the problem is in apache2 conf, but i do not think.
I'll complete this response when i'll can see your apache's conf :) (apache2.conf & sites-enabled/000-default.conf -it should be the one you'are using in /var/www/html/-)
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.
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
I am newbie in PHP. I have successfully installed PHP on Ubuntu, now I want start my first program. I am using gPHPEdit as IDE.
Where should I save .php files that I create? And how to run/test them?
Make sure you have LAMP installed. Do a sudo tasksel and select lamp then hit enter, its gotta be the most simple *amp install ever made. Its a good idea to install phpmyadmin: sudo apt-get install phpmyadmin. After that just copy the files to /var/www/ and then they will show up on http://localhost. I recommended using Eclipse PDT or the Netbeans build for PHP.
You should pick up a book or start following some good tutorials on the web.
If you are just scripting using php, you can save them anywhere and run the php on the terminal using the php command line interpreter.
If you are trying write web scripts (and I think you are), you need to install and configure a web server (typically apache) and save your scripts in the server's document root (typically /var/www). Also, I highly recommend you to read up a little about servers and HTTP and figure out how all this works on the inside before learning to building websites in php.
If you cannot save or copy to var/www/html, to run your php scripts on your browser. If you are using Ubuntu 14.04.
I followed these steps and it worked for me.
Execute sudo su on the terminal.
Enter your password
Execute sudo subl /etc/apache2/sites-available/000-default.conf on your terminal to open this file. Note you can change the subl to any text editor to open the file e.g sudo nano /etc/apache2/sites-available/000-default.conf.
Change DocumentRoot /var/www/html to /home/user/yoursubdir
Save the file and close it.
Execute sudo subl /etc/apache2/apache2.conf on your terminal to open this file.
Add the following to end of the file
<Directory /home/user/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Save and Close the file.
Execute sudo service apache2 restart
Go to your browser, type the URL of your script e.g 127.0.1.1/directory/document.php.
I hope this helps.
remove the index.html file from /var/www/
$ sudo rm index.html
create a new php file there:
$ sudo gedit /var/www/index.php
write in it:
<?php
print_r(phpinfo());
?>
Restart your Apache2 Server :
$ sudo service apache2 restart
OR
$ sudo /etc/init.d/apace2 restart
and point to yout localhost and /index.php
if err arises visit : http://www.allaboutlinux.eu/how-to-run-php-on-ubuntu/
https://www.php.net/manual/en/features.commandline.webserver.php
this is an easy way to test your files in php.
$ cd ~/public_html
$ php -S localhost:8000
then you can go to your browser and enter localhost:8000/myfile.php.